From: Youngjae Cho Date: Mon, 13 May 2024 07:57:09 +0000 (+0900) Subject: halcc: Add halcc_hal_is_compatible_with_version() X-Git-Tag: accepted/tizen/unified/20240611.122614~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=405475ef6fee9ba54b2ce166c41e06cdaf2a6e8b;p=platform%2Fhal%2Fapi%2Fcommon.git halcc: Add halcc_hal_is_compatible_with_version() 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 --- diff --git a/src/hal-api-compatibility-checker-object.c b/src/hal-api-compatibility-checker-object.c index 7fc33c5..0d22bb1 100644 --- a/src/hal-api-compatibility-checker-object.c +++ b/src/hal-api-compatibility-checker-object.c @@ -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; diff --git a/src/hal-api-compatibility-checker-object.h b/src/hal-api-compatibility-checker-object.h index 6206f92..3780b64 100644 --- a/src/hal-api-compatibility-checker-object.h +++ b/src/hal-api-compatibility-checker-object.h @@ -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); diff --git a/tests/unittest/test-hal-compatibility-checker.cc b/tests/unittest/test-hal-compatibility-checker.cc index d594926..2f98780 100644 --- a/tests/unittest/test-hal-compatibility-checker.cc +++ b/tests/unittest/test-hal-compatibility-checker.cc @@ -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)