]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuxml2argvmock: Pretend FW blobs are always present
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 31 Jul 2025 09:19:43 +0000 (11:19 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 11 Aug 2025 09:53:19 +0000 (11:53 +0200)
Soon, the QEMU driver, specifically the part that picks firmware
based on firmware descriptor files (qemu_firmware.c) is going to
check for the presence of those firmware blobs (well, for their
realpath()). Just collect the list of all blobs we use in our
tests and mock virFileCanonicalizePath() so that for any path on
that list its strdup()-ed version is returned.

This means, qemuxmlconftest won't touch host files really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/qemuxml2argvmock.c

index e3f933c44f6b1b173691f5b66c9d4e8bc6cc0bae..9d10b5655fd533ca02b90cac6650add602972cfa 100644 (file)
@@ -33,6 +33,7 @@
 #include "virscsivhost.h"
 #include "virtpm.h"
 #include "virutil.h"
+#include "virfile.h"
 #include "qemu/qemu_interface.h"
 #include "qemu/qemu_command.h"
 #include "domain_interface.h"
@@ -296,3 +297,37 @@ virNetDevSetMTU(const char *ifname G_GNUC_UNUSED,
 {
     return 0;
 }
+
+static char *(*real_virFileCanonicalizePath)(const char *path);
+
+char *
+virFileCanonicalizePath(const char *path)
+{
+    size_t i;
+    const char *fws[] = {
+        /* These are locations from our firmware descriptors
+         * stored in qemufirmwaredata/. */
+        "/usr/share/edk2/",
+        "/usr/share/OVMF/",
+        "/usr/share/AAVMF/",
+        "/usr/share/seabios/",
+
+        /* These are 'random' locations from domain XMLs stored
+         * in qemuxmlconfdata/. */
+        "/path/to/OVMF_CODE.fd",
+        "/path/to/guest_BOTH.fd",
+        "/path/to/OVMF_VARS.fd",
+    };
+
+    for (i = 0; i < G_N_ELEMENTS(fws); i++) {
+        if (STRPREFIX(path, fws[i])) {
+            return g_strdup(path);
+        }
+    }
+
+    if (!real_virFileCanonicalizePath) {
+        VIR_MOCK_REAL_INIT(virFileCanonicalizePath);
+    }
+
+    return real_virFileCanonicalizePath(path);
+}