[Libosinfo] [libosinfo PATCH] test-os: Add test_resources_inheritance()

Fabiano Fidêncio fidencio at redhat.com
Mon Nov 12 14:07:24 UTC 2018


Now that resources are inherited between OSes that derives-from/clone
some other OS, let's have a test case to ensure it's not going to break
in the future.

https://gitlab.com/libosinfo/osinfo-db/issues/15

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 .../test-os-resources-inheritance-1.xml       | 25 +++++
 .../test-os-resources-inheritance-2.xml       | 10 ++
 tests/test-os.c                               | 91 +++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-1.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-2.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-1.xml b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-1.xml
new file mode 100644
index 0000000..aea35ed
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-1.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/resources/inheritance/1">
+    <short-id>resourcesinheritance1</short-id>
+    <name>Resources Inheritance 1</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <resources arch="all">
+      <minimum>
+        <cpu>123456789</cpu>
+        <n-cpus>5</n-cpus>
+        <ram>123456789</ram>
+        <storage>123456789</storage>
+      </minimum>
+      <recommended>
+        <cpu>987654321</cpu>
+        <n-cpus>7</n-cpus>
+        <ram>987654321</ram>
+        <storage>987654321</storage>
+      </recommended>
+    </resources>
+
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-2.xml b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-2.xml
new file mode 100644
index 0000000..61043ca
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-2.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/resources/inheritance/2">
+    <short-id>resourcesinheritance2</short-id>
+    <name>Resources Inheritance 2</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/resources/inheritance/1"/>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index 2ec7960..f289772 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -188,6 +188,94 @@ test_device_driver(void)
 }
 
 
+static void
+test_resources_inheritance_basic(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os1, *os2;
+    OsinfoResourcesList *os1_minimum_list, *os1_recommended_list;
+    OsinfoResourcesList *os2_minimum_list, *os2_recommended_list;
+    OsinfoResources *os1_minimum, *os1_recommended;
+    OsinfoResources *os2_minimum, *os2_recommended;
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = g_object_ref(osinfo_loader_get_db(loader));
+    g_object_unref(loader);
+
+    os1 = osinfo_db_get_os(db, "http://libosinfo.org/test/os/resources/inheritance/1");
+    g_assert(OSINFO_IS_OS(os1));
+
+    os1_minimum_list = osinfo_os_get_minimum_resources(os1);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(os1_minimum_list)), ==, 1);
+
+    os1_recommended_list = osinfo_os_get_recommended_resources(os1);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(os1_recommended_list)), ==, 1);
+
+    os1_minimum = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(os1_minimum_list), 0));
+    g_assert(OSINFO_IS_RESOURCES(os1_minimum));
+
+    os1_recommended = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(os1_recommended_list), 0));
+    g_assert(OSINFO_IS_RESOURCES(os1_recommended));
+
+    os2 = osinfo_db_get_os(db, "http://libosinfo.org/test/os/resources/inheritance/2");
+    g_assert(OSINFO_IS_OS(os2));
+
+    os2_minimum_list = osinfo_os_get_minimum_resources(os2);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(os2_minimum_list)), ==, 1);
+
+    os2_recommended_list = osinfo_os_get_recommended_resources(os2);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(os2_recommended_list)), ==, 1);
+
+    os2_minimum = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(os2_minimum_list), 0));
+    g_assert(OSINFO_IS_RESOURCES(os2_minimum));
+
+    os2_recommended = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(os2_recommended_list), 0));
+    g_assert(OSINFO_IS_RESOURCES(os2_recommended));
+
+
+    g_assert_cmpint(osinfo_resources_get_cpu(os1_minimum),
+                    ==,
+                    osinfo_resources_get_cpu(os2_minimum));
+
+    g_assert_cmpint(osinfo_resources_get_n_cpus(os1_minimum),
+                    ==,
+                    osinfo_resources_get_n_cpus(os2_minimum));
+
+    g_assert_cmpint(osinfo_resources_get_ram(os1_minimum),
+                    ==,
+                    osinfo_resources_get_ram(os2_minimum));
+
+    g_assert_cmpint(osinfo_resources_get_storage(os1_minimum),
+                    ==,
+                    osinfo_resources_get_storage(os2_minimum));
+
+    g_assert_cmpint(osinfo_resources_get_cpu(os1_recommended),
+                    ==,
+                    osinfo_resources_get_cpu(os2_recommended));
+
+    g_assert_cmpint(osinfo_resources_get_n_cpus(os1_recommended),
+                    ==,
+                    osinfo_resources_get_n_cpus(os2_recommended));
+
+    g_assert_cmpint(osinfo_resources_get_ram(os1_recommended),
+                    ==,
+                    osinfo_resources_get_ram(os2_recommended));
+
+    g_assert_cmpint(osinfo_resources_get_storage(os1_recommended),
+                    ==,
+                    osinfo_resources_get_storage(os2_recommended));
+
+    g_object_unref(db);
+    g_object_unref(os1_minimum_list);
+    g_object_unref(os1_recommended_list);
+    g_object_unref(os2_minimum_list);
+    g_object_unref(os2_recommended_list);
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -198,6 +286,7 @@ main(int argc, char *argv[])
     g_test_add_func("/os/devices", test_devices);
     g_test_add_func("/os/devices_filter", test_devices_filter);
     g_test_add_func("/os/device_driver", test_device_driver);
+    g_test_add_func("/os/resources_inheritance/basic", test_resources_inheritance_basic);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
@@ -206,6 +295,8 @@ main(int argc, char *argv[])
     osinfo_oslist_get_type();
     osinfo_devicelist_get_type();
     osinfo_filter_get_type();
+    osinfo_resources_get_type();
+    osinfo_resourceslist_get_type();
 
     return g_test_run();
 }
-- 
2.19.1




More information about the Libosinfo mailing list