halcc: Add halcc_hal_is_compatible_with_version() 79/311179/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 13 May 2024 07:57:09 +0000 (16:57 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 13 May 2024 08:02:16 +0000 (17:02 +0900)
The function checks whether the given major/minor version is covered
by the given hal. The hal manages version list and one of its element
version can support the given major/minor version if its version
meets BOTH of the below:
  - equal to the given major version
  - equal to or greater than the given minor version

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

index 7fc33c5df20a7386e1804bd5eb5572f80377d614..0d22bb1ab7d4eee55a7cd9168d83cd706b189587 100644 (file)
@@ -810,6 +810,30 @@ void halcc_hal_foreach_interface(halcc_hal *hal, halcc_iter_cb cb, void *user_da
        hashtable_foreach(hal->interfaces, cb, user_data);
 }
 
+bool halcc_hal_is_compatible_with_version(halcc_hal *hal, int major, int minor)
+{
+       if (!hal) {
+               printf("Invalid parameter\n");
+               return false;
+       }
+
+       for (int i = 0; i < hal->num_version; ++i) {
+               if (hal->version_list[i].major != major) {
+                       printf("Major not matched\n");
+                       continue;
+               }
+
+               if (hal->version_list[i].minor < minor) {
+                       printf("Minor not supported\n");
+                       continue;
+               }
+
+               return true;
+       }
+
+       return false;
+}
+
 int halcc_interface_new(halcc_interface **interface)
 {
        halcc_interface *iface;
index 6206f92b8bb5689fb356fd3c52b36eb51eb01ba6..3780b6449fe7ad831dc69ea78773262070be23fc 100644 (file)
@@ -86,6 +86,7 @@ int halcc_hal_add_interface(halcc_hal *hal, halcc_interface *interface);
 void halcc_hal_remove_interface(halcc_hal *hal,
        const char *interface_name, const char *instance_id);
 void halcc_hal_foreach_interface(halcc_hal *hal, halcc_iter_cb cb, void *user_data);
+bool halcc_hal_is_compatible_with_version(halcc_hal *hal, int major, int minor);
 
 int halcc_interface_new(halcc_interface **interface);
 void halcc_interface_free(halcc_interface *interface);
index d594926a399be9d2800662d7eb6e32e014c161d5..2f98780b3a4d09f585f13408ad72733578da95a5 100644 (file)
@@ -70,6 +70,7 @@ class HalccObjectTest : public ::testing::Test
        protected:
                static void SetUpTestSuite() {
                        int ret;
+                       bool compatibility;
 
                        ret = halcc_manifest_new(&g_manifest);
                        ASSERT_EQ(ret, 0);
@@ -77,8 +78,11 @@ class HalccObjectTest : public ::testing::Test
                        ret = halcc_parse_string(g_manifest_xml, strlen(g_manifest_xml), g_manifest);
                        ASSERT_EQ(ret, 0);
 
-                       ret = halcc_manifest_find_hal(g_manifest, "hal.test", 4, 8, &g_hal);
+                       ret = halcc_manifest_find_hal_by_name(g_manifest, "hal.test", &g_hal);
                        ASSERT_EQ(ret, 0);
+
+                       compatibility = halcc_hal_is_compatible_with_version(g_hal, 4, 8);
+                       ASSERT_EQ(compatibility, true);
                }
 
                static void TearDownTestSuite() {
@@ -129,24 +133,32 @@ TEST_F(HalccObjectTest, manifest_find_hal_success)
 {
        halcc_hal *hal = NULL;
        int ret;
+       bool compatibility;
 
-       ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 1, 5, &hal);
+       ret = halcc_manifest_find_hal_by_name(g_manifest, "hal.device.display", &hal);
        ASSERT_EQ(ret, 0);
+
+       compatibility = halcc_hal_is_compatible_with_version(hal, 1, 5);
+       ASSERT_EQ(compatibility, true);
 }
 
 TEST_F(HalccObjectTest, manifest_find_hal_fail)
 {
        halcc_hal *hal = NULL;
        int ret;
+       bool compatibility;
 
-       ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 1, 4, &hal);
-       ASSERT_EQ(ret, -ENOTSUP);
+       ret = halcc_manifest_find_hal_by_name(g_manifest, "hal.device.display", &hal);
+       ASSERT_EQ(ret, 0);
 
-       ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 1, 6, &hal);
-       ASSERT_EQ(ret, -ENOTSUP);
+       compatibility = halcc_hal_is_compatible_with_version(hal, 1, 4);
+       ASSERT_EQ(compatibility, true);
 
-       ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 2, 4, &hal);
-       ASSERT_EQ(ret, -ENOTSUP);
+       compatibility = halcc_hal_is_compatible_with_version(hal, 1, 6);
+       ASSERT_EQ(compatibility, false);
+
+       compatibility = halcc_hal_is_compatible_with_version(hal, 2, 4);
+       ASSERT_EQ(compatibility, false);
 }
 
 TEST_F(HalccObjectTest, manifest_find_hal_backward_compatible_success)