From: Youngjae Cho Date: Wed, 23 Oct 2024 02:49:44 +0000 (+0900) Subject: halcc: Add %enable_halcc to enable/disable the feature selectively X-Git-Tag: accepted/tizen/unified/20241108.105514^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9857071d40990e13457c68fe001402d66ae45b22;p=platform%2Fhal%2Fapi%2Fcommon.git halcc: Add %enable_halcc to enable/disable the feature selectively There could be some environment that the hal-comaptibility-checker would not be necessary. For example, a platform image that always accompanies hal image when building will never worry about ABI compatibility between them. In such case, the hal-compatibility-checker is pointless and no more than a thing that degrades booting performance. For such reason, %enable_halcc has been introduced on the .spec file and can be used to exclude total halcc feature. Change-Id: I26510db0374602303874265c2e99cb97c3c71fdc Signed-off-by: Youngjae Cho --- diff --git a/CMakeLists.txt b/CMakeLists.txt index be7e733..2409362 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,12 @@ SET(LIBDIR ${CMAKE_LIBDIR_PREFIX}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) +if (${ENABLE_HALCC}) +ADD_DEFINITIONS("-DHALCC_ENABLED=1") +else() +ADD_DEFINITIONS("-DHALCC_ENABLED=0") +endif() + if (${ENABLE_DLOG}) ADD_DEFINITIONS("-DENABLE_DLOG=1") ADD_DEFINITIONS("-DLOG_TAG=\"HALAPI_COMMON\"") @@ -67,4 +73,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tools/lshal) +if (${ENABLE_HALCC}) ADD_SUBDIRECTORY(tools/hal-compatibility-checker) +endif() diff --git a/packaging/hal-api-common.spec b/packaging/hal-api-common.spec index 708cc99..898f2fb 100644 --- a/packaging/hal-api-common.spec +++ b/packaging/hal-api-common.spec @@ -1,6 +1,11 @@ %define name hal-api-common %define devel_name hal-api-common-devel %define test_name hal-api-common-haltests +%if "%{tizen_profile_name}" != "tv" +%define enable_halcc 1 +%else +%define enable_halcc 0 +%endif ### main package ######### Name: %{name} @@ -58,6 +63,7 @@ Haltests for hal-api-common cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ -DCMAKE_LIBDIR_PREFIX=%{_libdir} \ + -DENABLE_HALCC=%{enable_halcc} \ -DENABLE_DLOG=1 %build @@ -71,8 +77,10 @@ make %{?jobs:-j%jobs} rm -rf %{buildroot} %make_install +%if %{enable_halcc} mkdir -p %{buildroot}%{_unitdir} cp %{SOURCE4} %{buildroot}%{_unitdir} +%endif mkdir -p %{buildroot}/hal install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/ld.so.conf.d/libhal-api.conf @@ -102,10 +110,12 @@ rm -f %{_unitdir}/sysinit.target.wants/hal-compatibility-checker.service %dir /hal %{_libdir}/hal/*.so* %{_bindir}/lshal -%{_bindir}/hal-compatibility-checker %{_sysconfdir}/ld.so.conf.d/libhal-api.conf %{_systemdgeneratordir}/systemd-hal-firmware-generator +%if %{enable_halcc} +%{_bindir}/hal-compatibility-checker %{_unitdir}/hal-compatibility-checker.service +%endif %{_datadir}/upgrade/scripts/500.%{name}.sh %files -n %{devel_name} diff --git a/src/hal-api-common.c b/src/hal-api-common.c index e4cb731..19c5641 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -234,13 +234,39 @@ static void __close_backend(struct __hal_module_info *info) info->handle = NULL; } +static int __check_backend_compatibility_by_version(enum hal_module module, + unsigned int major, unsigned int minor) +{ + int ret; + enum hal_common_backend_compatibility compatibility = + HAL_COMMON_BACKEND_COMPATIBILITY_UNKNOWN; + + if (!HALCC_ENABLED) + return 0; + + ret = hal_api_cc_check_backend_compatibility_by_version(module, major, minor, &compatibility); + if (ret != 0 || compatibility == HAL_COMMON_BACKEND_COMPATIBILITY_INCOMPATIBLE) { + struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL); + + _W("%s: Failed to check compatibility, ret=%d, compatibility=%d\n", + info ? info->module_name : "Unknown", ret, compatibility); + /** + * FIXME: + * Do not return error but just print warning for now. Need time to + * deploy compatibility manifest to all hal modules. + * + * return -ELIBBAD; + */ + } + + return 0; +} + static int __init_backend(struct __hal_module_info *info, void **data, void *user_data, int (*init_backend)(void **data, void *user_data)) { int ret; - enum hal_common_backend_compatibility compatibility = - HAL_COMMON_BACKEND_COMPATIBILITY_UNKNOWN; if (!info->handle || !info->backend) { _I("%s: Has not yet dlopend backend\n", info->module_name); @@ -260,18 +286,10 @@ static int __init_backend(struct __hal_module_info *info, return -EINVAL; } - ret = hal_api_cc_check_backend_compatibility_by_version(info->module, - info->backend->major_version, info->backend->minor_version, - &compatibility); - if (ret != 0 || compatibility == HAL_COMMON_BACKEND_COMPATIBILITY_INCOMPATIBLE) { - /** - * FIXME: - * Not return but just print warning for now. Need time to - * deploy compatibility manifest to all hal modules. - */ - _W("%s: Failed to check compatibility, ret=%d, compatibility=%d\n", - info->module_name, ret, compatibility); - } + ret = __check_backend_compatibility_by_version(info->module, + info->backend->major_version, info->backend->minor_version); + if (ret < 0) + return -EINVAL; /* Initialize backend */ ret = info->backend->init(data); @@ -732,6 +750,15 @@ EXPORT int hal_common_check_backend_compatibility(enum hal_module module, enum hal_common_backend_compatibility *backend_compatibility) { + if (!backend_compatibility) + return -EINVAL; + + if (!HALCC_ENABLED) { + _W("Hal compatibility checker is disabled. Consider it always compatible."); + *backend_compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE; + return 0; + } + return hal_api_cc_check_backend_compatibility(module, backend_compatibility); } @@ -739,6 +766,15 @@ EXPORT int hal_common_get_supported_interface_versions(enum hal_module module, unsigned int **major_versions, unsigned int **minor_versions, int *num_versions) { + if (!major_versions || !minor_versions || !num_versions) + return -EINVAL; + + if (!HALCC_ENABLED) { + _W("Hal compatibility checker is disabled. No interface version has been provided."); + *num_versions = 0; + return 0; + } + return hal_api_cc_get_supported_interface_versions(module, major_versions, minor_versions, num_versions); } diff --git a/tests/unittest/CMakeLists.txt b/tests/unittest/CMakeLists.txt index 13a3240..c109acf 100644 --- a/tests/unittest/CMakeLists.txt +++ b/tests/unittest/CMakeLists.txt @@ -5,7 +5,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Werror -Wno-pointer-sign") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -Wall -Werror") ADD_DEFINITIONS("-DHAL_API_COMMON_UNITTEST") -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNITTEST_SRCS) +SET(UNITTEST_SRCS + hal-api-common-hook.c + test-hal-api-common.cc + test-main.cc) +if (${ENABLE_HALCC}) + SET(UNITTEST_SRCS ${UNITTEST_SRCS} test-hal-compatibility-checker.cc) +endif() AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src/ HAL_API_COMMON_SRCS) ADD_EXECUTABLE(${HAL_API_COMMON_UNITTEST} ${UNITTEST_SRCS} ${HAL_API_COMMON_SRCS})