From: Youngjae Cho Date: Thu, 5 Dec 2024 08:33:50 +0000 (+0900) Subject: common: Change compatibility error to a real error instead of warning X-Git-Tag: accepted/tizen/9.0/unified/20250220.165931~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=057367d29b0cd56675f3d537bd313e4c1d495e0a;p=platform%2Fhal%2Fapi%2Fcommon.git common: Change compatibility error to a real error instead of warning The compatibility check needed time to be operational properly because there were hal modules that hadn't declared their hal manifest. And this is why the compatibility check failure was treated as a warning and ignored. But as of now, we make the error be treated as an effective error instead of warning. Therefore, the functions below can now fail due to compatibility check failure. - hal_common_get_backend() - hal_common_get_backend_with_library_name() - hal_common_get_backend_v2() - hal_common_get_backend_with_library_name_v2() Existing unittest needs to be reworked to be operational with proper manifest file. Therefore, added manifest files. Change-Id: I4bdb56f3e2f7a9c955884ae88f99dee243330881 Signed-off-by: Youngjae Cho (cherry picked from commit a74a9d42f45d095d318ec95693833b7ef8d6a425) --- diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 987cf7c..1de9826 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -238,15 +238,9 @@ static int __check_backend_compatibility_by_version(enum hal_module module, 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", + _E("%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 -ELIBBAD; } return 0; diff --git a/tests/unittest/hal-api-common-hook.c b/tests/unittest/hal-api-common-hook.c index e8d0ce3..3ffa60e 100644 --- a/tests/unittest/hal-api-common-hook.c +++ b/tests/unittest/hal-api-common-hook.c @@ -28,7 +28,7 @@ #include "hal-common-interface.h" #include "hal-api-common-hook.h" #include "../../src/hal-api-conf.h" -#include "../../src/hal-api-list.h" +#include "../../src/common.h" /* * All hal-backend-[module] (e.g., tbm/tdm/audio/camera/devcie/power etc) @@ -42,6 +42,7 @@ static int hal_backend_init(void **data) { return 0; } static int hal_backend_exit(void *data) { return 0; } static hal_backend hal_backend_module_data[HAL_MODULE_END]; +static char *g_orig_manifest[HAL_MODULE_END]; /* * hal-api-common uses the dlopen/dlsym/dlclose/access to load/unload @@ -59,94 +60,95 @@ static enum hal_module get_module_by_library_name(const char *library_name) return HAL_MODULE_UNKNOWN; for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) { - struct __hal_module_info *info = &g_hal_module_info[module]; - - if (info->library_name - && strncmp(info->library_name, - library_name, strlen(info->library_name) + 1) == 0) - return module; - - if (info->library_name_64bit - && strncmp(info->library_name_64bit, - library_name, strlen(info->library_name_64bit) + 1) == 0) + if (_hal_api_conf_get_module_info(module, basename((char *) library_name))) return module; } return HAL_MODULE_UNKNOWN; } -int set_module_info_manifest(const char *our_directory) +int set_module_info_manifest(enum hal_module our_module, const char *our_directory) { int ret; + struct __hal_module_info *info = NULL; + char *orig_manifest = NULL; if (!our_directory) return -1; _hal_api_conf_init(); - for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) { - struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL); - char *orig_manifest = NULL; - - if (!info) { - _hal_api_conf_exit(); - return -1; - } - - orig_manifest = info->manifest; - if (!orig_manifest) - continue; - - /* We sneak into the data structure and modify it to what we want */ - ret = asprintf(&info->manifest, - "%s%s", our_directory, strrchr(orig_manifest, '/')); - if (ret == -1) { - _hal_api_conf_exit(); - return -1; - } + info = _hal_api_conf_get_module_info(our_module, NULL); + + if (!info) { + _hal_api_conf_exit(); + return -1; } + orig_manifest = info->manifest; + if (!orig_manifest) { + _hal_api_conf_exit(); + return -1; + } + + /* We sneak into the data structure and modify it to what we want */ + ret = asprintf(&info->manifest, + "%s%s", our_directory, strrchr(orig_manifest, '/')); + if (ret == -1) { + _hal_api_conf_exit(); + return -1; + } + + g_orig_manifest[our_module] = orig_manifest; + _hal_api_conf_exit(); return 0; } -int unset_module_info_manifest(void) +int set_module_info_manifest_all(const char *our_directory) { - int ret; + for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) + set_module_info_manifest(module, our_directory); + + return 0; +} + +int unset_module_info_manifest(enum hal_module our_module) +{ + struct __hal_module_info *info = NULL; + char *modified_manifest = NULL; _hal_api_conf_init(); - for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) { - struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL); - char *orig_manifest = NULL; - - if (!info) { - _hal_api_conf_exit(); - return -1; - } - - orig_manifest = info->manifest; - if (!orig_manifest) - continue; - - /* Put it back to the original */ - ret = asprintf(&info->manifest, - "/etc/hal%s", strrchr(orig_manifest, '/')); - if (ret == -1) { - _hal_api_conf_exit(); - return -1; - } - - free(orig_manifest); - orig_manifest = NULL; + info = _hal_api_conf_get_module_info(our_module, NULL); + + if (!info || !info->manifest) { + _hal_api_conf_exit(); + return -1; } + modified_manifest = info->manifest; + + /* Put it back to the original */ + info->manifest = g_orig_manifest[our_module]; + + free(modified_manifest); + modified_manifest = NULL; + _hal_api_conf_exit(); return 0; } +int unset_module_info_manifest_all(void) +{ + for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) + unset_module_info_manifest(module); + + return 0; +} + void mock_hal_backend_data_set_version(enum hal_module module, unsigned int major, unsigned int minor) { diff --git a/tests/unittest/hal-api-common-hook.h b/tests/unittest/hal-api-common-hook.h index 4f1abb5..42adde3 100644 --- a/tests/unittest/hal-api-common-hook.h +++ b/tests/unittest/hal-api-common-hook.h @@ -35,8 +35,10 @@ extern "C" { */ #define ACCESS_DO_NOT_HOOK (ACCESS_UNUSED_MODES & -ACCESS_UNUSED_MODES) -int set_module_info_manifest(const char *our_directory); -int unset_module_info_manifest(void); +int set_module_info_manifest(enum hal_module our_module, const char *our_directory); +int set_module_info_manifest_all(const char *our_directory); +int unset_module_info_manifest(enum hal_module our_module); +int unset_module_info_manifest_all(void); void mock_hal_backend_data_set_version(enum hal_module module, unsigned int major, unsigned int minor); void mock_hal_backend_data_unset_version(enum hal_module module); diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-audio-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-audio-manifest.xml new file mode 100644 index 0000000..6df2467 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-audio-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_AUDIO + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-bluetooth-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-bluetooth-manifest.xml new file mode 100644 index 0000000..88f7afc --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-bluetooth-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_BLUETOOTH + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-camera-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-camera-manifest.xml new file mode 100644 index 0000000..c2ae86f --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-camera-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_CAMERA + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-device-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-device-manifest.xml new file mode 100644 index 0000000..793a688 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-device-manifest.xml @@ -0,0 +1,56 @@ + + + + HAL_MODULE_DEVICE_BATTERY + 1.0 + + + HAL_MODULE_DEVICE_BEZEL + 1.0 + + + HAL_MODULE_DEVICE_DISPLAY + 1.0 + + + HAL_MODULE_DEVICE_IR + 1.0 + + + HAL_MODULE_DEVICE_TOUCHSCREEN + 1.0 + + + HAL_MODULE_DEVICE_LED + 1.0 + + + HAL_MODULE_DEVICE_BOARD + 1.0 + + + HAL_MODULE_DEVICE_EXTERNAL_CONNECTION + 1.0 + + + HAL_MODULE_DEVICE_THERMAL + 1.0 + + + HAL_MODULE_DEVICE_HAPTIC + 1.0 + + + HAL_MODULE_DEVICE_MEMORY + 1.0 + + + HAL_MODULE_DEVICE_INPUT + 1.0 + + + HAL_MODULE_DEVICE_POWER + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-location-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-location-manifest.xml new file mode 100644 index 0000000..75bdace --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-location-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_LOCATION + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-nfc-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-nfc-manifest.xml new file mode 100644 index 0000000..cd27a82 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-nfc-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_NFC + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-power-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-power-manifest.xml new file mode 100644 index 0000000..a369408 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-power-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_POWER + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-radio-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-radio-manifest.xml new file mode 100644 index 0000000..26393e5 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-radio-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_RADIO + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-sensor-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-sensor-manifest.xml new file mode 100644 index 0000000..11503a2 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-sensor-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_SENSOR + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-tbm-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-tbm-manifest.xml new file mode 100644 index 0000000..d6acba1 --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-tbm-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_TBM + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-tdm-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-tdm-manifest.xml new file mode 100644 index 0000000..43322bb --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-tdm-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_TDM + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common-manifest/hal-api-wifi-manifest.xml b/tests/unittest/test-hal-api-common-manifest/hal-api-wifi-manifest.xml new file mode 100644 index 0000000..334d08e --- /dev/null +++ b/tests/unittest/test-hal-api-common-manifest/hal-api-wifi-manifest.xml @@ -0,0 +1,8 @@ + + + + HAL_MODULE_WIFI + 1.0 + + + diff --git a/tests/unittest/test-hal-api-common.cc b/tests/unittest/test-hal-api-common.cc index 17959b1..a5418ff 100644 --- a/tests/unittest/test-hal-api-common.cc +++ b/tests/unittest/test-hal-api-common.cc @@ -24,6 +24,7 @@ #include "hal-common.h" #include "hal-common-interface.h" +#include "hal-api-common-hook.h" #include "../../src/hal-api-conf.h" #include "../../src/common.h" @@ -84,7 +85,31 @@ class HalInfo { library_name_64bit_(library_name_64bit), symbol_name_(symbol_name) {} }; -class HalInfoMatchedTest : public ::testing::TestWithParam {}; +class HalInfoMatchedTest : public ::testing::TestWithParam { + void SetUp() override { + const auto &info = GetParam(); + int ret = 0; + char *modified_manifest_path = NULL; + + /* mock backend library version with 1.0 */ + mock_hal_backend_data_set_version(info.module_, 1, 0); + + /* set directory for hal manifest mock */ + ret = asprintf(&modified_manifest_path, + "%s/%s", getcwd(NULL, 0), "test-hal-api-common-manifest"); + if (ret < 0) + return; + + set_module_info_manifest(info.module_, modified_manifest_path); + modified_manifest_path = NULL; /* don't free. consumed by set_module_info_manifest() */ + } + + void TearDown() override { + const auto &info = GetParam(); + unset_module_info_manifest(info.module_); + mock_hal_backend_data_unset_version(info.module_); + } +}; INSTANTIATE_TEST_CASE_P(HalApiCommonTest, HalInfoMatchedTest, diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-device-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-device-manifest.xml new file mode 100644 index 0000000..7b3c9d8 --- /dev/null +++ b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-device-manifest.xml @@ -0,0 +1,22 @@ + + + + HAL_MODULE_DEVICE_DISPLAY + 1.2 + + + + + HAL_MODULE_DEVICE_DISPLAY + 2.0 + + + + + HAL_MODULE_DEVICE_DISPLAY + 2.1 + 3.0 + + + + diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tdm-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tdm-manifest.xml new file mode 100644 index 0000000..80174c7 --- /dev/null +++ b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-tdm-manifest.xml @@ -0,0 +1,21 @@ + + + + HAL_MODULE_TDM + 5.5 + + + + + HAL_MODULE_TDM + 5.5 + + + + + HAL_MODULE_TDM + 5.5 + + + + diff --git a/tests/unittest/test-hal-compatibility-checker.cc b/tests/unittest/test-hal-compatibility-checker.cc index 244a6b3..c7174a6 100644 --- a/tests/unittest/test-hal-compatibility-checker.cc +++ b/tests/unittest/test-hal-compatibility-checker.cc @@ -39,11 +39,11 @@ class HalccObjectTest : public ::testing::Test if (!g_cwd) FAIL(); - ret = asprintf(&g_manifest_directory, "%s/%s", g_cwd, "test-hal-manifest"); + ret = asprintf(&g_manifest_directory, "%s/%s", g_cwd, "test-hal-compatibility-checker-manifest"); if (ret == -1) FAIL(); - set_module_info_manifest(g_manifest_directory); + set_module_info_manifest_all(g_manifest_directory); ret = asprintf(&g_compatibility_result_path, "%s/.hal-backend-compatibility", g_cwd); if (ret == -1) @@ -66,7 +66,7 @@ class HalccObjectTest : public ::testing::Test for (int module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) mock_hal_backend_data_unset_version((enum hal_module) module); unlink(g_compatibility_result_path); - unset_module_info_manifest(); + unset_module_info_manifest_all(); hal_api_cc_unset_compatibility_loaded_path(); free(g_compatibility_loaded_path); free(g_compatibility_result_path); diff --git a/tests/unittest/test-hal-manifest/hal-api-device-manifest.xml b/tests/unittest/test-hal-manifest/hal-api-device-manifest.xml deleted file mode 100644 index 7b3c9d8..0000000 --- a/tests/unittest/test-hal-manifest/hal-api-device-manifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - HAL_MODULE_DEVICE_DISPLAY - 1.2 - - - - - HAL_MODULE_DEVICE_DISPLAY - 2.0 - - - - - HAL_MODULE_DEVICE_DISPLAY - 2.1 - 3.0 - - - - diff --git a/tests/unittest/test-hal-manifest/hal-api-tdm-manifest.xml b/tests/unittest/test-hal-manifest/hal-api-tdm-manifest.xml deleted file mode 100644 index 80174c7..0000000 --- a/tests/unittest/test-hal-manifest/hal-api-tdm-manifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - HAL_MODULE_TDM - 5.5 - - - - - HAL_MODULE_TDM - 5.5 - - - - - HAL_MODULE_TDM - 5.5 - - - -