[libosinfo PATCH v2 6/6] test-os: Add test_resources_inheritance()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 .../test-os-resources-inheritance-1.xml       |  25 +++
 .../test-os-resources-inheritance-2.xml       |  12 ++
 .../test-os-resources-inheritance-3.xml       |  21 +++
 .../test-os-resources-inheritance-4.xml       |  21 +++
 .../test-os-resources-inheritance-5.xml       |  12 ++
 tests/test-os.c                               | 162 ++++++++++++++++++
 6 files changed, 253 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
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-3.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-4.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-5.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..a9d1e87
--- /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>
+        <n-cpus>1</n-cpus>
+        <cpu>1</cpu>
+        <ram>1</ram>
+        <storage>1</storage>
+      </minimum>
+      <recommended>
+        <n-cpus>2</n-cpus>
+        <cpu>2</cpu>
+        <ram>2</ram>
+        <storage>2</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..555f7c6
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-2.xml
@@ -0,0 +1,12 @@
+<?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"/>
+
+    <resources arch="all" inherit="true"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-3.xml b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-3.xml
new file mode 100644
index 0000000..39d525a
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-3.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/resources/inheritance/3";>
+    <short-id>resourcesinheritance3</short-id>
+    <name>Resources Inheritance 3</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/resources/inheritance/2"/>
+
+    <resources arch="all">
+      <minimum>
+        <n-cpus>3</n-cpus>
+        <ram>3</ram>
+      </minimum>
+      <recommended>
+        <n-cpus>6</n-cpus>
+        <ram>6</ram>
+      </recommended>
+    </resources>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-4.xml b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-4.xml
new file mode 100644
index 0000000..a7bce68
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-4.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/resources/inheritance/4";>
+    <short-id>resourcesinheritance4</short-id>
+    <name>Resources Inheritance 4</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/resources/inheritance/3"/>
+
+    <resources arch="all">
+      <minimum>
+        <cpu>3</cpu>
+        <storage>3</storage>
+      </minimum>
+      <recommended>
+        <cpu>6</cpu>
+        <storage>6</storage>
+      </recommended>
+    </resources>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-5.xml b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-5.xml
new file mode 100644
index 0000000..e5ceab9
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-resources-inheritance-5.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/resources/inheritance/5";>
+    <short-id>resourcesinheritance5</short-id>
+    <name>Resources Inheritance 5</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/resources/inheritance/4"/>
+
+    <resources arch="all" inherit="true"/>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index 2ec7960..004a06d 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -188,6 +188,167 @@ test_device_driver(void)
 }
 
 
+static void
+check_resources(OsinfoDb *db,
+                const gchar *os_id,
+                OsinfoResourcesList *(*get_resourceslist)(OsinfoOs *),
+                gint list_len,
+                gint expected_n_cpus,
+                gint64 expected_cpu,
+                gint64 expected_ram,
+                gint64 expected_storage)
+{
+    OsinfoOs *os;
+    OsinfoResourcesList *resourceslist;
+    OsinfoResources *resources;
+
+    g_test_message("Testing \"%s\"", os_id);
+
+    os = osinfo_db_get_os(db, os_id);
+    g_assert_true(OSINFO_IS_OS(os));
+
+    resourceslist = get_resourceslist(os);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(resourceslist)), ==, list_len);
+
+    resources = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(resourceslist), 0));
+    g_assert_true(OSINFO_IS_RESOURCES(resources));
+
+    g_assert_cmpint(osinfo_resources_get_n_cpus(resources), ==, expected_n_cpus);
+    g_assert_cmpint(osinfo_resources_get_cpu(resources), ==, expected_cpu);
+    g_assert_cmpint(osinfo_resources_get_ram(resources), ==, expected_ram);
+    g_assert_cmpint(osinfo_resources_get_storage(resources), ==, expected_storage);
+
+    g_object_unref(resourceslist);
+}
+
+
+static void
+test_resources_inheritance(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    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:
+     * - minimum
+     *   - n_cpus: 1
+     *   - cpu: 1
+     *   - ram: 1
+     *   - storage: 1
+     * - recommended:
+     *   - n_cpus: 2
+     *   - cpu: 2
+     *   - ram: 2
+     *   - storage: 2
+     */
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/1";,
+                    osinfo_os_get_minimum_resources,
+                    1, 1, 1, 1, 1);
+
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/1";,
+                    osinfo_os_get_recommended_resources,
+                    1, 2, 2, 2, 2);
+
+    /**
+     * os2 (derives-from os1):
+     * - inherit: true
+     *
+     * - minimum
+     *   - n_cpus: 1
+     *   - cpu: 1
+     *   - ram: 1
+     *   - storage: 1
+     * - recommended:
+     *   - n_cpus: 2
+     *   - cpu: 2
+     *   - ram: 2
+     *   - storage: 2
+     */
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/2";,
+                    osinfo_os_get_minimum_resources,
+                    1, 1, 1, 1, 1);
+
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/2";,
+                    osinfo_os_get_recommended_resources,
+                    1, 2, 2, 2, 2);
+
+    /**
+     * os3 (derives-from os2):
+     * - minimum
+     *   - n_cpus: 3
+     *   - ram: 3
+     * - recommended:
+     *   - n_cpus: 6
+     *   - ram: 6
+     */
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/3";,
+                    osinfo_os_get_minimum_resources,
+                    1, 3, -1, 3, -1);
+
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/3";,
+                    osinfo_os_get_recommended_resources,
+                    1, 6, -1, 6, -1);
+
+    /**
+     * os4 (derives-from os3):
+     * - minimum
+     *   - cpu: 3
+     *   - storage: 3
+     * - recommended:
+     *   - cpus: 6
+     *   - storage: 6
+     */
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/4";,
+                    osinfo_os_get_minimum_resources,
+                    1, -1, 3, -1, 3);
+
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/4";,
+                    osinfo_os_get_recommended_resources,
+                    1, -1, 6, -1, 6);
+
+    /**
+     * os5 (derives-from os4):
+     * - inherit: true
+     *
+     * - minimum
+     *   - n_cpus: 3
+     *   - cpu: 3
+     *   - ram: 3
+     *   - storage: 3
+     * - recommended:
+     *   - n_cpus: 6
+     *   - cpus: 6
+     *   - ram: 6
+     *   - storage: 6
+     */
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/5";,
+                    osinfo_os_get_minimum_resources,
+                    1, 3, 3, 3, 3);
+
+    check_resources(db,
+                    "http://libosinfo.org/test/os/resources/inheritance/5";,
+                    osinfo_os_get_recommended_resources,
+                    1, 6, 6, 6, 6);
+
+    g_object_unref(db);
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -198,6 +359,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", test_resources_inheritance);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
-- 
2.19.1

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux