Use the LD_PRELOAD .so library used in 'qemucapsprobe' to regenerate the
files. The library is instrumented to write the replies to 'caps.json'
and instrumentation in the test move it to the correct place.
Use 'fix-files.sh' to do so as it's using a static variable to
track the initial newline.
---
fix-files.sh | 1 +
tests/Makefile.am | 1 +
tests/qemucapabilitiestest.c | 4 +++-
tests/qemucapsprobemock.c | 11 +++++++++++
4 files changed, 16 insertions(+), 1 deletion(-)
create mode 100755 fix-files.sh
diff --git a/fix-files.sh b/fix-files.sh
new file mode 100755
index 0000000000..93465b96db
--- /dev/null
+++ b/fix-files.sh
@@ -0,0 +1 @@
+for i in `seq 0 50`; do VIR_TEST_RANGE="$i" ./tests/qemucapabilitiestest; done
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1ce3dbb50f..a805b1b837 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -604,6 +604,7 @@ qemucapabilitiestest_SOURCES = \
testutilsqemu.c testutilsqemu.h \
$(NULL)
qemucapabilitiestest_LDADD = libqemumonitortestutils.la \
+ libqemutestdriver.la \
$(qemu_LDADDS) $(LDADDS)
qemucapsprobe_SOURCES = \
diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c
index 633389f263..c3c814630e 100644
--- a/tests/qemucapabilitiestest.c
+++ b/tests/qemucapabilitiestest.c
@@ -81,6 +81,8 @@ testQemuCaps(const void *opaque)
if (virTestCompareToFile(actual, capsFile) < 0)
goto cleanup;
+ rename(abs_srcdir "/caps.json", repliesFile);
+
ret = 0;
cleanup:
VIR_FREE(repliesFile);
@@ -202,4 +204,4 @@ mymain(void)
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/qemucapsprobemock.so")
diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c
index 5936975505..9b691dcf0e 100644
--- a/tests/qemucapsprobemock.c
+++ b/tests/qemucapsprobemock.c
@@ -25,6 +25,7 @@
#include "internal.h"
#include "viralloc.h"
#include "virjson.h"
+#include "virfile.h"
#include "qemu/qemu_monitor.h"
#include "qemu/qemu_monitor_json.h"
@@ -38,19 +39,29 @@
} while (0)
static bool first = true;
+static const char *dumppath = abs_srcdir "/caps.json";
static void
printLineSkipEmpty(const char *line,
FILE *fp)
{
+ FILE *fp2;
const char *p;
+ if (!(fp2 = fopen(dumppath, "a"))) {
+ fprintf(stderr, "failed to open '%s'", dumppath);
+ abort();
+ }
+
for (p = line; *p; p++) {
if (p[0] == '\n' && p[1] == '\n')
continue;
fputc(*p, fp);
+ fputc(*p, fp2);
}
+
+ VIR_FORCE_FCLOSE(fp2);
}
--
2.16.2