[Libosinfo] [libosinfo PATCH 7/7] test-firmware: Add tests
Fabiano Fidêncio
fidencio at redhat.com
Tue May 7 13:16:53 UTC 2019
Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
.../os/libosinfo.org/test-db-firmware.xml | 16 +++
.../test-os-firmwares-inheritance-1.xml | 12 ++
.../test-os-firmwares-inheritance-2.xml | 10 ++
.../test-os-firmwares-inheritance-3.xml | 12 ++
.../test-os-firmwares-inheritance-4.xml | 10 ++
.../test-os-firmwares-inheritance-5.xml | 12 ++
.../test-os-firmwares-inheritance-6.xml | 10 ++
tests/test-firmware.c | 40 ++++++
tests/test-os.c | 118 ++++++++++++++++++
9 files changed, 240 insertions(+)
create mode 100644 tests/dbdata/os/libosinfo.org/test-db-firmware.xml
create mode 100644 tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-1.xml
create mode 100644 tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-2.xml
create mode 100644 tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-3.xml
create mode 100644 tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-4.xml
create mode 100644 tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-5.xml
create mode 100644 tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-6.xml
diff --git a/tests/dbdata/os/libosinfo.org/test-db-firmware.xml b/tests/dbdata/os/libosinfo.org/test-db-firmware.xml
new file mode 100644
index 0000000..6872d63
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-db-firmware.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+ <os id="http://libosinfo.org/test/db/firmware">
+ <short-id>db-firmware</short-id>
+ <name>DB Firmware</name>
+ <version>unknown</version>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+
+ <firmware arch="x86_64" type="efi"/>
+ <firmware arch="x86_64" type="bios"/>
+
+ <firmware arch="i686" type="efi" supported="false"/>
+ <firmware arch="i686" type="bios"/>
+ </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-1.xml b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-1.xml
new file mode 100644
index 0000000..59a0770
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-1.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+ <os id="http://libosinfo.org/test/os/firmwares/inheritance/1">
+ <short-id>firmwaresinheritance1</short-id>
+ <name>Firmwares Inheritance 1</name>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+
+ <firmware arch="x86_64" type="bios"/>
+ <firmware arch="x86_64" type="efi"/>
+ </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-2.xml b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-2.xml
new file mode 100644
index 0000000..a252936
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-firmwares-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/firmwares/inheritance/2">
+ <short-id>firmwaresinheritance2</short-id>
+ <name>Firmwares Inheritance 2</name>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+ <derives-from id="http://libosinfo.org/test/os/firmwares/inheritance/1"/>
+ </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-3.xml b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-3.xml
new file mode 100644
index 0000000..795cbf1
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-3.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+ <os id="http://libosinfo.org/test/os/firmwares/inheritance/3">
+ <short-id>firmwaresinheritance3</short-id>
+ <name>Firmwares Inheritance 3</name>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+ <derives-from id="http://libosinfo.org/test/os/firmwares/inheritance/2"/>
+
+ <firmware arch="x86_64" type="bios" supported="false"/>
+ </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-4.xml b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-4.xml
new file mode 100644
index 0000000..3ebc182
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-4.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+ <os id="http://libosinfo.org/test/os/firmwares/inheritance/4">
+ <short-id>firmwaresinheritance4</short-id>
+ <name>Firmwares Inheritance 4</name>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+ <derives-from id="http://libosinfo.org/test/os/firmwares/inheritance/3"/>
+ </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-5.xml b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-5.xml
new file mode 100644
index 0000000..139a79e
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-firmwares-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/firmwares/inheritance/5">
+ <short-id>firmwaresinheritance5</short-id>
+ <name>Firmwares Inheritance 5</name>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+ <derives-from id="http://libosinfo.org/test/os/firmwares/inheritance/4"/>
+
+ <firmware arch="x86_64" type="bios"/>
+ </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-6.xml b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-6.xml
new file mode 100644
index 0000000..de774fa
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-firmwares-inheritance-6.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+ <os id="http://libosinfo.org/test/os/firmwares/inheritance/6">
+ <short-id>firmwaresinheritance6</short-id>
+ <name>Firmwares Inheritance 6</name>
+ <vendor>libosinfo.org</vendor>
+ <family>test</family>
+ <derives-from id="http://libosinfo.org/test/os/firmwares/inheritance/5"/>
+ </os>
+</libosinfo>
diff --git a/tests/test-firmware.c b/tests/test-firmware.c
index a78758a..53b1ae4 100644
--- a/tests/test-firmware.c
+++ b/tests/test-firmware.c
@@ -34,15 +34,55 @@ test_basic(void)
g_assert_cmpstr(osinfo_firmware_get_firmware_type(firmware), ==, TYPE);
}
+static void
+test_loaded(void)
+{
+ OsinfoLoader *loader = osinfo_loader_new();
+ OsinfoDb *db;
+ OsinfoOs *os;
+ OsinfoFilter *filter;
+ OsinfoFirmwareList *list;
+ gint list_len;
+ GError *error = NULL;
+
+ osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+ g_assert_no_error(error);
+ db = osinfo_loader_get_db(loader);
+
+ os = osinfo_db_get_os(db, "http://libosinfo.org/test/db/firmware");
+
+ list = osinfo_os_get_firmware_list(os, NULL);
+ list_len = osinfo_list_get_length(OSINFO_LIST(list));
+ g_assert_cmpint(list_len, ==, 3);
+ g_object_unref(list);
+
+ filter = osinfo_filter_new();
+ osinfo_filter_add_constraint(filter,
+ OSINFO_FIRMWARE_PROP_ARCHITECTURE, "i686");
+ list = osinfo_os_get_firmware_list(os, filter);
+ list_len = osinfo_list_get_length(OSINFO_LIST(list));
+ g_assert_cmpint(list_len, ==, 1);
+ g_object_unref(list);
+
+ g_object_unref(loader);
+}
+
int
main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/firmware/basic", test_basic);
+ g_test_add_func("/firmware/loaded/basic", test_loaded);
/* Upfront so we don't confuse valgrind */
osinfo_firmware_get_type();
+ osinfo_firmwarelist_get_type();
+ osinfo_db_get_type();
+ osinfo_filter_get_type();
+ osinfo_list_get_type();
+ osinfo_loader_get_type();
+ osinfo_os_get_type();
return g_test_run();
}
diff --git a/tests/test-os.c b/tests/test-os.c
index fe7c2d6..cefa99e 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -651,6 +651,123 @@ test_multiple_short_ids(void)
g_object_unref(db);
}
+static void
+check_firmwares(OsinfoDb *db,
+ const gchar *os_id,
+ gint list_len)
+{
+ OsinfoOs *os;
+ OsinfoFirmwareList *firmwarelist;
+
+ g_test_message("Testing \"%s\"", os_id);
+
+ os = osinfo_db_get_os(db, os_id);
+ g_assert_true(OSINFO_IS_OS(os));
+
+ firmwarelist = osinfo_os_get_firmware_list(os, NULL);
+ g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(firmwarelist)), ==, list_len);
+
+ g_object_unref(firmwarelist);
+}
+
+
+static void
+test_firmwares_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:
+ * - firmwares:
+ * - explicitly added
+ * - x86_64 | bios
+ * - x86_64 | efi
+ * - explicitly removed
+ * - expected:
+ * - x86_64 | bios
+ * - x86_64 | efi
+
+ */
+ check_firmwares(db,
+ "http://libosinfo.org/test/os/firmwares/inheritance/1",
+ 2);
+
+ /**
+ * os2 (derives-from os1):
+ * - firmwares
+ * - explicitly added
+ * - explicitly removed
+ * - expected:
+ * - x86_64 | bios
+ * - x86_64 | efi
+ */
+ check_firmwares(db,
+ "http://libosinfo.org/test/os/firmwares/inheritance/2",
+ 2);
+
+ /**
+ * os3 (derives-from os2):
+ * - firmwares
+ * - explicitly added
+ * - explicitly removed
+ * - x86_64 | bios
+ * - expected:
+ * - x86_64 | efi
+
+ */
+ check_firmwares(db,
+ "http://libosinfo.org/test/os/firmwares/inheritance/3",
+ 1);
+
+ /**
+ * os4 (derives-from os3):
+ * - firmwares
+ * - explicitly added
+ * - explicitly removed
+ * - expected:
+ * - x86_64 | efi
+ */
+ check_firmwares(db,
+ "http://libosinfo.org/test/os/firmwares/inheritance/4",
+ 1);
+
+ /**
+ * os5 (derives-from os4):
+ * - firmwares
+ * - explicitly added
+ * - x86_64 | bios
+ * - explicitly removed
+ * - expected:
+ * - x86_64 | bios
+ * - x86_64 | efi
+ */
+ check_firmwares(db,
+ "http://libosinfo.org/test/os/firmwares/inheritance/5",
+ 2);
+
+ /**
+ * os6 (derives-from os5):
+ * - firmwares
+ * - explicitly added
+ * - explicitly removed
+ * - expected:
+ * - x86_64 | bios
+ * - x86_64 | efi
+ */
+ check_firmwares(db,
+ "http://libosinfo.org/test/os/firmwares/inheritance/6",
+ 2);
+
+ g_object_unref(db);
+}
+
int
main(int argc, char *argv[])
{
@@ -670,6 +787,7 @@ main(int argc, char *argv[])
g_test_add_func("/os/resources/inheritance", test_resources_inheritance);
g_test_add_func("/os/find_install_script", test_find_install_script);
g_test_add_func("/os/mulitple_short_ids", test_multiple_short_ids);
+ g_test_add_func("/os/firmwares/inheritance", test_firmwares_inheritance);
/* Upfront so we don't confuse valgrind */
osinfo_platform_get_type();
--
2.21.0
More information about the Libosinfo
mailing list