From 6326865e6b9ac21e1569d51d414cb29913999442 Mon Sep 17 00:00:00 2001
From: Michal Privoznik
When running our test suite it may happen that the test result is
+ nondeterministic because of the test suite relying on a particular file
+ in the system being accessible or having some specific value. To catch
+ this kind of errors, the test suite has a module for that prints any
+ path touched that fulfils constraints described above
+ into a file. To enable it just set
+ VIR_TEST_FILE_ACCESS
environment variable.
+ Then VIR_TEST_FILE_ACCESS_OUTPUT
environment
+ variable can alter location where the file is stored.
+ VIR_TEST_FILE_ACCESS=1 VIR_TEST_FILE_ACCESS_OUTPUT="/tmp/file_access.txt" ./qemuxml2argvtest ++
The Valgrind test should produce similar output to
make check
. If the output has traces within libvirt
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0d72245894..ca3c8c34a1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,7 +18,9 @@
# old automake does not provide abs_{src,build}dir variables
abs_builddir = $(shell pwd)
+abs_topbuilddir = $(shell cd .. && pwd)
abs_srcdir = $(shell cd $(srcdir) && pwd)
+abs_topsrcdir = $(shell cd $(top_srcdir) && pwd)
SHELL = $(PREFERABLY_POSIX_SHELL)
@@ -33,7 +35,9 @@ INCLUDES = \
AM_CFLAGS = \
-Dabs_builddir="\"$(abs_builddir)\"" \
+ -Dabs_topbuilddir="\"$(abs_topbuilddir)\"" \
-Dabs_srcdir="\"$(abs_srcdir)\"" \
+ -Dabs_topsrcdir="\"$(abs_topsrcdir)\"" \
$(LIBXML_CFLAGS) \
$(LIBNL_CFLAGS) \
$(GNUTLS_CFLAGS) \
@@ -1147,7 +1151,9 @@ virtestmock_la_SOURCES = \
virtestmock.c
virtestmock_la_CFLAGS = $(AM_CFLAGS)
virtestmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
-virtestmock_la_LIBADD = $(MOCKLIBS_LIBS)
+virtestmock_la_LIBADD = \
+ $(MOCKLIBS_LIBS) \
+ ../src/libvirt_util.la
else ! WITH_LINUX
EXTRA_DIST += virusbtest.c virusbmock.c \
virnetdevbandwidthtest.c virnetdevbandwidthmock.c \
diff --git a/tests/testutils.c b/tests/testutils.c
index 79d076378a..9180e86ed2 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -156,6 +156,11 @@ virtTestRun(const char *title,
{
int ret = 0;
+ /* Some test are fragile about environ settings. If that's
+ * the case, don't poison it. */
+ if (getenv("VIR_TEST_MOCK_PROGNAME"))
+ setenv("VIR_TEST_MOCK_TESTNAME", title, 1);
+
if (testCounter == 0 && !virTestGetVerbose())
fprintf(stderr, " ");
@@ -280,6 +285,7 @@ virtTestRun(const char *title,
}
#endif /* TEST_OOM */
+ unsetenv("VIR_TEST_MOCK_TESTNAME");
return ret;
}
@@ -832,8 +838,11 @@ virTestSetEnvPath(void)
return ret;
}
+#define TEST_MOCK (abs_builddir "/.libs/virtestmock.so")
+
int virtTestMain(int argc,
char **argv,
+ const char *lib,
int (*func)(void))
{
int ret;
@@ -842,6 +851,18 @@ int virtTestMain(int argc,
char *oomstr;
#endif
+ if (getenv("VIR_TEST_FILE_ACCESS"))
+ VIRT_TEST_PRELOAD(TEST_MOCK);
+
+ if (lib)
+ VIRT_TEST_PRELOAD(lib);
+
+ progname = last_component(argv[0]);
+ if (STRPREFIX(progname, "lt-"))
+ progname += 3;
+
+ setenv("VIR_TEST_MOCK_PROGNAME", progname, 1);
+
virFileActivateDirOverride(argv[0]);
if (virTestSetEnvPath() < 0)
@@ -850,9 +871,6 @@ int virtTestMain(int argc,
if (!virFileExists(abs_srcdir))
return EXIT_AM_HARDFAIL;
- progname = last_component(argv[0]);
- if (STRPREFIX(progname, "lt-"))
- progname += 3;
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", argv[0]);
fputs("effective environment variables:\n"
diff --git a/tests/testutils.h b/tests/testutils.h
index 123a4fb17b..d1caf20e70 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -102,12 +102,13 @@ const char *virtTestCounterNext(void);
int virtTestMain(int argc,
char **argv,
+ const char *lib,
int (*func)(void));
/* Setup, then call func() */
-# define VIRT_TEST_MAIN(func) \
- int main(int argc, char **argv) { \
- return virtTestMain(argc, argv, func); \
+# define VIRT_TEST_MAIN(func) \
+ int main(int argc, char **argv) { \
+ return virtTestMain(argc, argv, NULL, func); \
}
# define VIRT_TEST_PRELOAD(lib) \
@@ -132,8 +133,7 @@ int virtTestMain(int argc,
# define VIRT_TEST_MAIN_PRELOAD(func, lib) \
int main(int argc, char **argv) { \
- VIRT_TEST_PRELOAD(lib); \
- return virtTestMain(argc, argv, func); \
+ return virtTestMain(argc, argv, lib, func); \
}
virCapsPtr virTestGenericCapsInit(void);
diff --git a/tests/virtestmock.c b/tests/virtestmock.c
index 0877956b02..59ca5e5b07 100644
--- a/tests/virtestmock.c
+++ b/tests/virtestmock.c
@@ -24,9 +24,14 @@
#include