[Libosinfo] [libosinfo PATCH 11/11] test-os: Add basic test for resources

Fabiano Fidêncio fabiano at fidencio.org
Tue Jan 22 19:28:20 UTC 2019


This test only ensures that libosinfo is able to properly load the
resource info from an OS entry.

Signed-off-by: Fabiano Fidêncio <fabiano at fidencio.org>
---
 tests/test-os.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tests/test-os.c b/tests/test-os.c
index 1c13c56..f4e758d 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -218,6 +218,58 @@ test_device_driver(void)
 }
 
 
+static void test_resources_basic(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    OsinfoResourcesList *resources_list;
+    OsinfoResources *resources;
+    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);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/resources/basic");
+
+    resources_list = osinfo_os_get_minimum_resources(os);
+    resources = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(resources_list), 0));
+    g_assert_cmpint(osinfo_resources_get_n_cpus(resources), ==, 1);    
+    g_assert_cmpint(osinfo_resources_get_cpu(resources), ==, 1);    
+    g_assert_cmpint(osinfo_resources_get_ram(resources), ==, 1);    
+    g_assert_cmpint(osinfo_resources_get_storage(resources), ==, 1);    
+
+    g_clear_object(&resources_list);
+    resources_list = osinfo_os_get_recommended_resources(os);
+    resources = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(resources_list), 0));
+    g_assert_cmpint(osinfo_resources_get_n_cpus(resources), ==, 2);    
+    g_assert_cmpint(osinfo_resources_get_cpu(resources), ==, 2);    
+    g_assert_cmpint(osinfo_resources_get_ram(resources), ==, 2);    
+    g_assert_cmpint(osinfo_resources_get_storage(resources), ==, 2);    
+
+    g_clear_object(&resources_list);
+    resources_list = osinfo_os_get_maximum_resources(os);
+    resources = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(resources_list), 0));
+    g_assert_cmpint(osinfo_resources_get_n_cpus(resources), ==, 3);    
+    g_assert_cmpint(osinfo_resources_get_cpu(resources), ==, 3);    
+    g_assert_cmpint(osinfo_resources_get_ram(resources), ==, 3);    
+    g_assert_cmpint(osinfo_resources_get_storage(resources), ==, 3);    
+
+    g_clear_object(&resources_list);
+    resources_list = osinfo_os_get_network_install_resources(os);
+    resources = OSINFO_RESOURCES(osinfo_list_get_nth(OSINFO_LIST(resources_list), 0));
+    g_assert_cmpint(osinfo_resources_get_n_cpus(resources), ==, 4);    
+    g_assert_cmpint(osinfo_resources_get_cpu(resources), ==, 4);    
+    g_assert_cmpint(osinfo_resources_get_ram(resources), ==, 4);    
+    g_assert_cmpint(osinfo_resources_get_storage(resources), ==, 4);    
+
+    g_object_unref(resources_list);
+    g_object_unref(db);
+}
+
+
 static void test_n_cpus(OsinfoResources *resources1, OsinfoResources *resources2)
 {
     gint resources1_cpus, resources2_cpus;
@@ -947,6 +999,7 @@ main(int argc, char *argv[])
                     test_devices_inheritance_basic);
     g_test_add_func("/os/devices/inheritance/removal",
                     test_devices_inheritance_removal);
+    g_test_add_func("/os/resources/basic", test_resources_basic);
     g_test_add_func("/os/resources/minimum_recommended_maximum",
                     test_resources_minimum_recommended_maximum);
     g_test_add_func("/os/resources/uniqueness", test_resources_uniqueness);
-- 
1.8.3.1




More information about the Libosinfo mailing list