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(a)redhat.com>
---
tests/chxml2xmlmock.c | 33 +++++++++++++++++++++++++++++++++
tests/chxml2xmltest.c | 2 +-
tests/meson.build | 3 +++
3 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 tests/chxml2xmlmock.c
diff --git a/tests/chxml2xmlmock.c b/tests/chxml2xmlmock.c
new file mode 100644
index 0000000000..73b210f35e
--- /dev/null
+++ b/tests/chxml2xmlmock.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2024 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ */
+
+#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;
+}
diff --git a/tests/chxml2xmltest.c b/tests/chxml2xmltest.c
index 97b485dc4a..a5a75a1505 100644
--- a/tests/chxml2xmltest.c
+++ b/tests/chxml2xmltest.c
@@ -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"))
diff --git a/tests/meson.build b/tests/meson.build
index 4fc00e27da..3fcfa6b1e0 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -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')
--
2.43.0