[PATCH v1 10/15] qemufirmwaretest: Test qemuFirmwareFetchConfigs()

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/Makefile.am                             |  1 +
 .../etc/qemu/firmware/40-ovmf-sb.json         |  1 +
 .../etc/qemu/firmware/60-ovmf.json            |  0
 .../user/.config/qemu/firmware/10-bios.json   |  0
 .../share/qemu/firmware}/40-bios.json         |  0
 .../share/qemu/firmware}/50-ovmf-sb.json      |  0
 .../share/qemu/firmware}/60-ovmf.json         |  0
 .../share/qemu/firmware}/70-aavmf.json        |  0
 tests/qemufirmwaretest.c                      | 69 +++++++++++++++++--
 9 files changed, 66 insertions(+), 5 deletions(-)
 create mode 120000 tests/qemufirmwaredata/etc/qemu/firmware/40-ovmf-sb.json
 create mode 100644 tests/qemufirmwaredata/etc/qemu/firmware/60-ovmf.json
 create mode 100644 tests/qemufirmwaredata/home/user/.config/qemu/firmware/10-bios.json
 rename tests/qemufirmwaredata/{ => usr/share/qemu/firmware}/40-bios.json (100%)
 rename tests/qemufirmwaredata/{ => usr/share/qemu/firmware}/50-ovmf-sb.json (100%)
 rename tests/qemufirmwaredata/{ => usr/share/qemu/firmware}/60-ovmf.json (100%)
 rename tests/qemufirmwaredata/{ => usr/share/qemu/firmware}/70-aavmf.json (100%)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index d23a8c2812..aee078c41c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -703,6 +703,7 @@ qemusecuritytest_LDADD = $(qemu_LDADDS) $(LDADDS)
 qemufirmwaretest_SOURCES = \
 	qemufirmwaretest.c \
 	testutils.h testutils.c \
+	virfilewrapper.c virfilewrapper.h \
 	$(NULL)
 qemufirmwaretest_LDADD = $(qemu_LDADDS) $(LDADDS)
 
diff --git a/tests/qemufirmwaredata/etc/qemu/firmware/40-ovmf-sb.json b/tests/qemufirmwaredata/etc/qemu/firmware/40-ovmf-sb.json
new file mode 120000
index 0000000000..30f65574f3
--- /dev/null
+++ b/tests/qemufirmwaredata/etc/qemu/firmware/40-ovmf-sb.json
@@ -0,0 +1 @@
+../../../usr/share/qemu/firmware/50-ovmf-sb.json
\ No newline at end of file
diff --git a/tests/qemufirmwaredata/etc/qemu/firmware/60-ovmf.json b/tests/qemufirmwaredata/etc/qemu/firmware/60-ovmf.json
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qemufirmwaredata/home/user/.config/qemu/firmware/10-bios.json b/tests/qemufirmwaredata/home/user/.config/qemu/firmware/10-bios.json
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qemufirmwaredata/40-bios.json b/tests/qemufirmwaredata/usr/share/qemu/firmware/40-bios.json
similarity index 100%
rename from tests/qemufirmwaredata/40-bios.json
rename to tests/qemufirmwaredata/usr/share/qemu/firmware/40-bios.json
diff --git a/tests/qemufirmwaredata/50-ovmf-sb.json b/tests/qemufirmwaredata/usr/share/qemu/firmware/50-ovmf-sb.json
similarity index 100%
rename from tests/qemufirmwaredata/50-ovmf-sb.json
rename to tests/qemufirmwaredata/usr/share/qemu/firmware/50-ovmf-sb.json
diff --git a/tests/qemufirmwaredata/60-ovmf.json b/tests/qemufirmwaredata/usr/share/qemu/firmware/60-ovmf.json
similarity index 100%
rename from tests/qemufirmwaredata/60-ovmf.json
rename to tests/qemufirmwaredata/usr/share/qemu/firmware/60-ovmf.json
diff --git a/tests/qemufirmwaredata/70-aavmf.json b/tests/qemufirmwaredata/usr/share/qemu/firmware/70-aavmf.json
similarity index 100%
rename from tests/qemufirmwaredata/70-aavmf.json
rename to tests/qemufirmwaredata/usr/share/qemu/firmware/70-aavmf.json
diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c
index 0c5fb1e55a..a6c2577709 100644
--- a/tests/qemufirmwaretest.c
+++ b/tests/qemufirmwaretest.c
@@ -1,7 +1,9 @@
 #include <config.h>
 
 #include "testutils.h"
+#include "virfilewrapper.h"
 #include "qemu/qemu_firmware.h"
+#include "configmake.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -46,11 +48,65 @@ testParseFormatFW(const void *opaque)
 }
 
 
+static int
+testFWPrecedence(const void *opaque ATTRIBUTE_UNUSED)
+{
+    VIR_AUTOFREE(char *) fakehome = NULL;
+    VIR_AUTOPTR(virString) fwList = NULL;
+    size_t nfwList;
+    size_t i;
+    const char *expected[] = {
+        PREFIX "/share/qemu/firmware/40-bios.json",
+        SYSCONFDIR "/qemu/firmware/40-ovmf-sb.json",
+        PREFIX "/share/qemu/firmware/50-ovmf-sb.json",
+        PREFIX "/share/qemu/firmware/70-aavmf.json",
+    };
+
+    if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0)
+        return -1;
+
+    setenv("XDG_CONFIG_HOME", fakehome, 1);
+
+    if (qemuFirmwareFetchConfigs(&fwList) < 0)
+        return -1;
+
+    if (!fwList) {
+        fprintf(stderr, "Expected result, got nothing\n");
+        return -1;
+    }
+
+    nfwList = virStringListLength((const char **)fwList);
+    if (nfwList != ARRAY_CARDINALITY(expected)) {
+        fprintf(stderr, "Expected %zu paths, got %zu\n",
+                ARRAY_CARDINALITY(expected), nfwList);
+        return -1;
+    }
+
+    for (i = 0; i < ARRAY_CARDINALITY(expected); i++) {
+        if (STRNEQ_NULLABLE(expected[i], fwList[i])) {
+            fprintf(stderr,
+                    "Unexpected path (i=%zu). Expected %s got %s \n",
+                    i, expected[i], NULLSTR(fwList[i]));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 static int
 mymain(void)
 {
     int ret = 0;
 
+    virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
+                            abs_srcdir "/qemufirmwaredata/etc/qemu/firmware");
+    virFileWrapperAddPrefix(PREFIX "/share/qemu/firmware",
+                            abs_srcdir "/qemufirmwaredata/usr/share/qemu/firmware");
+    virFileWrapperAddPrefix("/home/user/.config/qemu/firmware",
+                            abs_srcdir "/qemufirmwaredata/home/user/.config/qemu/firmware");
+
 #define DO_PARSE_TEST(filename) \
     do { \
         if (virTestRun("QEMU FW " filename, \
@@ -58,13 +114,16 @@ mymain(void)
             ret = -1; \
     } while (0)
 
-    DO_PARSE_TEST("40-bios.json");
-    DO_PARSE_TEST("50-ovmf-sb.json");
-    DO_PARSE_TEST("60-ovmf.json");
-    DO_PARSE_TEST("70-aavmf.json");
+    DO_PARSE_TEST("usr/share/qemu/firmware/40-bios.json");
+    DO_PARSE_TEST("usr/share/qemu/firmware/50-ovmf-sb.json");
+    DO_PARSE_TEST("usr/share/qemu/firmware/60-ovmf.json");
+    DO_PARSE_TEST("usr/share/qemu/firmware/70-aavmf.json");
+
+    if (virTestRun("QEMU FW precedence test", testFWPrecedence, NULL) < 0)
+        ret = -1;
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 
-VIR_TEST_MAIN(mymain);
+VIR_TEST_MAIN(mymain)
-- 
2.19.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



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

  Powered by Linux