halcc: Add hal_common_get_supported_interface_versions() 51/313351/4
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 24 Jun 2024 08:32:09 +0000 (17:32 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 25 Jun 2024 04:55:55 +0000 (13:55 +0900)
It gets versions specified at manifest file.

Change-Id: Icdaa1e8c4615fa2aa046c1a6cd698f8061905a00
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
include/hal-common.h
src/hal-api-common.c
src/hal-api-compatibility-checker.c
src/hal-api-compatibility-checker.h
tests/unittest/test-hal-compatibility-checker.cc

index d9f1c5b0cfe48864eb59eae022d23ff3844fb0ed..fed844466143f3b4da8a0424cb6e87372a6d4cc0 100644 (file)
@@ -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
index bcfe65900c7f01e8225337aaf3524d31654c7e90..38697397af1a088687495f549fb756ede1f5cef5 100644 (file)
@@ -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);
+}
index efe1841d54652cf44157a593369e77d189029bef..26f63e3a7c3a0aad39dcc8fedd2d4acfa575fb69 100644 (file)
@@ -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;
+}
index 2114116b86908ec7c9a1c54d971b7af2129ac864..4c897a75a877a3fedf3f661342b460d953397f3a 100644 (file)
@@ -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);
index 9e88e9c93a67773deba8c715eedb9757a2a0182d..be921b9ccdbb35613184dc1aa3562f77687e9f67 100644 (file)
@@ -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;
+}