From: Youngjae Cho Date: Mon, 24 Jun 2024 08:32:09 +0000 (+0900) Subject: halcc: Add hal_common_get_supported_interface_versions() X-Git-Tag: accepted/tizen/unified/20240625.163203~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8dff4f6cb4e98689a8c83ea0793a66252d1cf5c7;p=platform%2Fhal%2Fapi%2Fcommon.git halcc: Add hal_common_get_supported_interface_versions() It gets versions specified at manifest file. Change-Id: Icdaa1e8c4615fa2aa046c1a6cd698f8061905a00 Signed-off-by: Youngjae Cho --- diff --git a/include/hal-common.h b/include/hal-common.h index d9f1c5b..fed8444 100644 --- a/include/hal-common.h +++ b/include/hal-common.h @@ -210,6 +210,20 @@ int hal_common_get_backend_library_names(enum hal_module module, int hal_common_check_backend_compatibility(enum hal_module module, enum hal_common_backend_compatibility *backend_compatibility); +/** + * @brief Get the supported interface versions from the platform hal manifest + * @param[in] module HAL id among enum hal_module + * @param[out] major_versions Array of major version. An index is paired with the same + * index in the array minor_versions. The caller takes ownership of the data + * so it is responsible for caller to free it using free() + * @param[out] minor_versions Array of minor version. An index is paired with the same + * index in the array major_versions. The caller takes ownership of the data + * so it is responsible for caller to free it using free() + * @param[out] num_versions Number of returned major and minor versions + */ +int hal_common_get_supported_interface_versions(enum hal_module module, + unsigned int **major_versions, unsigned int **minor_versions, int *num_versions); + #ifdef __cplusplus } #endif diff --git a/src/hal-api-common.c b/src/hal-api-common.c index bcfe659..3869739 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -654,3 +654,11 @@ int hal_common_check_backend_compatibility(enum hal_module module, { return hal_api_cc_check_backend_compatibility(module, backend_compatibility); } + +EXPORT +int hal_common_get_supported_interface_versions(enum hal_module module, + unsigned int **major_versions, unsigned int **minor_versions, int *num_versions) +{ + return hal_api_cc_get_supported_interface_versions(module, + major_versions, minor_versions, num_versions); +} diff --git a/src/hal-api-compatibility-checker.c b/src/hal-api-compatibility-checker.c index efe1841..26f63e3 100644 --- a/src/hal-api-compatibility-checker.c +++ b/src/hal-api-compatibility-checker.c @@ -565,3 +565,55 @@ int hal_api_cc_check_backend_compatibility_by_version(enum hal_module module, return 0; } + +int hal_api_cc_get_supported_interface_versions(enum hal_module module, + unsigned int **major_versions, + unsigned int **minor_versions, + int *num_versions) +{ + int ret; + int ret_num_versions = 0; + unsigned int *ret_major_versions = NULL; + unsigned int *ret_minor_versions = NULL; + struct compatibility_info info = { 0 , }; + + if (!major_versions || !minor_versions || !num_versions) + return -EINVAL; + + ret = load_module_compatibility_info(module, &info); + if (ret < 0) { + ret = load_module_compatibility_info_fallback(module, &info, true); + if (ret < 0) + return ret; + } + + ret_num_versions = info.num_version_list; + if (ret_num_versions == 0) + return -ENODATA; + + ret_major_versions = calloc(ret_num_versions, sizeof(unsigned int)); + if (!ret_major_versions) + return -ENOMEM; + + ret_minor_versions = calloc(ret_num_versions, sizeof(unsigned int)); + if (!ret_minor_versions) { + free(ret_major_versions); + return -ENOMEM; + } + + for (int i = 0; i < ret_num_versions; ++i) { + ret_major_versions[i] = info.version_list[i][0]; + ret_minor_versions[i] = info.version_list[i][1]; + } + + *major_versions = ret_major_versions; + ret_major_versions = NULL; + + *minor_versions = ret_minor_versions; + ret_minor_versions = NULL; + + *num_versions = ret_num_versions; + ret_num_versions = 0; + + return 0; +} diff --git a/src/hal-api-compatibility-checker.h b/src/hal-api-compatibility-checker.h index 2114116..4c897a7 100644 --- a/src/hal-api-compatibility-checker.h +++ b/src/hal-api-compatibility-checker.h @@ -28,6 +28,8 @@ int hal_api_cc_check_backend_compatibility(enum hal_module module, int hal_api_cc_check_backend_compatibility_by_version(enum hal_module module, unsigned int major, unsigned int minor, enum hal_common_backend_compatibility *backend_compatibility); +int hal_api_cc_get_supported_interface_versions(enum hal_module module, + unsigned int **major_versions, unsigned int **minor_versions, int *num_versions); /* For test use only */ void set_compatibility_manifest_directory(const char *path); diff --git a/tests/unittest/test-hal-compatibility-checker.cc b/tests/unittest/test-hal-compatibility-checker.cc index 9e88e9c..be921b9 100644 --- a/tests/unittest/test-hal-compatibility-checker.cc +++ b/tests/unittest/test-hal-compatibility-checker.cc @@ -86,7 +86,7 @@ char* HalccObjectTest::g_manifest_directory = NULL; char* HalccObjectTest::g_compatibility_result_path = NULL; char* HalccObjectTest::g_cwd = NULL; -static bool have_exact_version(halcc_hal *hal, const char *version) +static bool have_exact_version_within_halcc_hal(halcc_hal *hal, const char *version) { int version_list[HALCC_NUM_VERSION_LIST_MAX][2] = { 0 , }; int num_version_list = 0; @@ -114,18 +114,57 @@ static bool have_exact_version(halcc_hal *hal, const char *version) return false; } -MATCHER_P(HasExactVersion, version, "") +struct versions_info { + unsigned int *major_versions; + unsigned int *minor_versions; + int num_versions; +}; + +static bool have_exact_version_within_array(const struct versions_info *vi, const char *version) +{ + unsigned int major, minor; + int ret; + + if (!vi) + return false; + + if (!vi->major_versions || !vi->minor_versions) + return false; + + ret = sscanf(version, "%u.%u", &major, &minor); + if (ret != 2) + return false; + + for (int i = 0; i < vi->num_versions; ++i) { + if (vi->major_versions[i] != major) + continue; + if (vi->minor_versions[i] != minor) + continue; + return true; + } + + return false; +} + +MATCHER_P(HasExactVersionHalccHal, version, "") { halcc_hal *hal = (halcc_hal *) arg; - return have_exact_version(hal, version); + return have_exact_version_within_halcc_hal(hal, version); } -MATCHER_P(HasNoExactVersion, version, "") +MATCHER_P(HasNoExactVersionHalccHal, version, "") { halcc_hal *hal = (halcc_hal *) arg; - return !have_exact_version(hal, version); + return !have_exact_version_within_halcc_hal(hal, version); +} + +MATCHER_P(HasExactVersionArray, version, "") +{ + const struct versions_info *vi = (const struct versions_info *) arg; + + return have_exact_version_within_array(vi, version); } TEST_F(HalccObjectTest, manifest_find_hal_success) @@ -158,11 +197,11 @@ TEST_F(HalccObjectTest, hal_check_version_list) ret = halcc_manifest_find_hal(g_manifest, "HAL_MODULE_DEVICE_DISPLAY", &hal); ASSERT_EQ(ret, 0); - ASSERT_THAT(hal, HasExactVersion("1.2")); + ASSERT_THAT(hal, HasExactVersionHalccHal("1.2")); /* This 2.0 is specified but replaced with and covered by 2.1 */ - ASSERT_THAT(hal, HasNoExactVersion("2.0")); - ASSERT_THAT(hal, HasExactVersion("2.1")); - ASSERT_THAT(hal, HasExactVersion("3.0")); + ASSERT_THAT(hal, HasNoExactVersionHalccHal("2.0")); + ASSERT_THAT(hal, HasExactVersionHalccHal("2.1")); + ASSERT_THAT(hal, HasExactVersionHalccHal("3.0")); } TEST_F(HalccObjectTest, hal_is_compatible_with_version) @@ -447,3 +486,60 @@ TEST_F(HalccObjectTest, hal_get_backend_with_generator_without_result_file) unset_compatibility_result_path(); unsetenv("SYSTEMD_SCOPE"); } + +TEST_F(HalccObjectTest, hal_get_manifest_version_success_with_result_file) +{ + int ret; + enum hal_common_backend_compatibility compatibility; + struct versions_info vi = { 0 , }; + + setenv("SYSTEMD_SCOPE", "system", 1); + set_compatibility_result_path(g_compatibility_result_path); + + ret = hal_api_cc_check_backend_compatibility(HAL_MODULE_DEVICE_DISPLAY, &compatibility); + ASSERT_EQ(ret, 0); + + ret = access(g_compatibility_result_path, F_OK | ACCESS_DO_NOT_HOOK); + ASSERT_EQ(ret, 0); + + ret = hal_common_get_supported_interface_versions(HAL_MODULE_DEVICE_DISPLAY, + &vi.major_versions, &vi.minor_versions, &vi.num_versions); + ASSERT_EQ(ret, 0); + + ASSERT_THAT(&vi, HasExactVersionArray("1.2")); + ASSERT_THAT(&vi, HasExactVersionArray("2.1")); + ASSERT_THAT(&vi, HasExactVersionArray("3.0")); + + free(vi.major_versions); + vi.major_versions = NULL; + + free(vi.minor_versions); + vi.minor_versions = NULL; + + unlink(g_compatibility_result_path); + unset_compatibility_result_path(); + unsetenv("SYSTEMD_SCOPE"); +} + +TEST_F(HalccObjectTest, hal_get_manifest_version_success_without_result_file) +{ + int ret; + struct versions_info vi = { 0 , }; + + ret = access(g_compatibility_result_path, F_OK | ACCESS_DO_NOT_HOOK); + ASSERT_EQ(ret, -1); + + ret = hal_common_get_supported_interface_versions(HAL_MODULE_DEVICE_DISPLAY, + &vi.major_versions, &vi.minor_versions, &vi.num_versions); + ASSERT_EQ(ret, 0); + + ASSERT_THAT(&vi, HasExactVersionArray("1.2")); + ASSERT_THAT(&vi, HasExactVersionArray("2.1")); + ASSERT_THAT(&vi, HasExactVersionArray("3.0")); + + free(vi.major_versions); + vi.major_versions = NULL; + + free(vi.minor_versions); + vi.minor_versions = NULL; +}