halcc: Add %enable_halcc to enable/disable the feature selectively 39/319939/1 accepted/tizen/9.0/unified/20241108.065613
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 23 Oct 2024 02:49:44 +0000 (11:49 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 5 Nov 2024 09:29:12 +0000 (18:29 +0900)
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 <y0.cho@samsung.com>
CMakeLists.txt
packaging/hal-api-common.spec
src/hal-api-common.c
tests/unittest/CMakeLists.txt

index be7e73329bee54ab190f71a9ae18a5c62bc3f535..24093620cd72dc48fc7b9dadf4297be0d5c16b49 100644 (file)
@@ -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()
index 708cc995c21a4442f5e20ce46ecee2cfbffa9439..898f2fbe19294b0fc0d1423eb876dd1d6bcb1bb0 100644 (file)
@@ -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}
index e4cb73198f5ecc3e63087ce4b3ef6c6244203bfe..19c56416a1128f4453c4a85eafa5ae842553a459 100644 (file)
@@ -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);
 }
index 13a3240483a82ec89b2fc9e14741e384465a9528..c109acf8919c7013f191fd21d2b7026b957b786f 100644 (file)
@@ -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})