]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Introduce chxml2xmlmock
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 8 Mar 2024 14:03:04 +0000 (15:03 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Mar 2024 16:37:51 +0000 (17:37 +0100)
As of previous commit, the CH driver checks for /dev/kvm and/or
/dev/mshv presence. In order to make chxml2xmltest work
regardless of host configuration, introduce a mock that pretends
both of these files are accessible.

Fixes: 51c14df9670ba2f5d193b700f39e6464e1bc18c6
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tests/chxml2xmlmock.c [new file with mode: 0644]
tests/chxml2xmltest.c
tests/meson.build

diff --git a/tests/chxml2xmlmock.c b/tests/chxml2xmlmock.c
new file mode 100644 (file)
index 0000000..d4d7b34
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2024 Red Hat, Inc.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include <config.h>
+#include <unistd.h>
+
+#include "internal.h"
+#include "virfile.h"
+
+bool
+virFileExists(const char *path)
+{
+    if (STREQ(path, "/dev/kvm"))
+        return true;
+    if (STREQ(path, "/dev/mshv"))
+        return true;
+    return access(path, F_OK) == 0;
+}
index 97b485dc4aa9429dac3a5ecbb6f38c97f5e9a67a..a5a75a1505197ed808ac18c47933aa874ec82087 100644 (file)
@@ -74,4 +74,4 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("chxml2xml"))
index 4fc00e27dab03329a7a869b754e96f5dbe6c22c6..3fcfa6b1e0d5e8fc847f77fdd1928deac1024454 100644 (file)
@@ -350,6 +350,9 @@ if conf.has('WITH_CH')
   tests += [
     { 'name': 'chxml2xmltest', 'link_with': [ ch_driver_impl ] },
   ]
+  mock_libs += [
+    { 'name': 'chxml2xmlmock' },
+  ]
 endif
 
 if conf.has('WITH_ESX')