]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: avoid re-execing test once for each mock
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 9 Jan 2020 18:01:44 +0000 (18:01 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 10 Jan 2020 10:45:34 +0000 (10:45 +0000)
When debugging tests under GDB/valgrind there is a significant
delay each time an execve is done as they scan shared libraries
once again. For tests which use many mock libraries, we have
been invoking execve many times which makes the debug experience
horrible. This changes our framework to activate the full
set of mock libraries in one single execve.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
tests/qemucapsprobe.c
tests/testutils.c
tests/testutils.h

index 6837f2a0f652d5061eb71c49b4a6ca8ef1c50c16..c7e8f3309d810578d25ba0d0121ddc4f438701d2 100644 (file)
@@ -46,8 +46,14 @@ main(int argc, char **argv)
 {
     virThread thread;
     virQEMUCapsPtr caps;
+    const char *mock = VIR_TEST_MOCK("qemucapsprobe");
 
-    VIR_TEST_PRELOAD(VIR_TEST_MOCK("qemucapsprobe"));
+    if (!virFileIsExecutable(mock)) {
+        perror(mock);
+        return EXIT_FAILURE;
+    }
+
+    VIR_TEST_PRELOAD(mock);
 
     if (argc != 2) {
         fprintf(stderr, "%s QEMU_binary\n", argv[0]);
index 6f0ef2b2f19b339a5890368a9785f379d4457e2f..b490609e363315c4b743aece9725a9c33c6b3e6f 100644 (file)
@@ -856,15 +856,34 @@ int virTestMain(int argc,
     virLogOutputPtr *outputs = NULL;
     g_autofree char *baseprogname = NULL;
     const char *progname;
-
-    if (getenv("VIR_TEST_FILE_ACCESS"))
-        VIR_TEST_PRELOAD(VIR_TEST_MOCK("virtest"));
+    g_autofree const char **preloads = NULL;
+    size_t npreloads = 0;
+    g_autofree char *mock = NULL;
+
+    if (getenv("VIR_TEST_FILE_ACCESS")) {
+        preloads = g_renew(const char *, preloads, npreloads + 2);
+        preloads[npreloads++] = VIR_TEST_MOCK("virtest");
+        preloads[npreloads] = NULL;
+    }
 
     va_start(ap, func);
-    while ((lib = va_arg(ap, const char *)))
-        VIR_TEST_PRELOAD(lib);
+    while ((lib = va_arg(ap, const char *))) {
+        if (!virFileIsExecutable(lib)) {
+            perror(lib);
+            return EXIT_FAILURE;
+        }
+
+        preloads = g_renew(const char *, preloads, npreloads + 2);
+        preloads[npreloads++] = lib;
+        preloads[npreloads] = NULL;
+    }
     va_end(ap);
 
+    if (preloads) {
+        mock = g_strjoinv(":", (char **)preloads);
+        VIR_TEST_PRELOAD(mock);
+    }
+
     progname = baseprogname = g_path_get_basename(argv[0]);
     if (STRPREFIX(progname, "lt-"))
         progname += 3;
index 8a7ea38f439b79dab0fdcd15819eeb8dd19a93bb..ad62dfb6470560c2437b8d44e2dada5ded4fb50e 100644 (file)
@@ -127,19 +127,15 @@ int virTestMain(int argc,
 # define MOCK_EXT ".so"
 #endif
 
-#define VIR_TEST_PRELOAD(lib) \
+#define VIR_TEST_PRELOAD(libs) \
     do { \
         const char *preload = getenv(PRELOAD_VAR); \
-        if (preload == NULL || strstr(preload, lib) == NULL) { \
+        if (preload == NULL || strstr(preload, libs) == NULL) { \
             char *newenv; \
-            if (!virFileIsExecutable(lib)) { \
-                perror(lib); \
-                return EXIT_FAILURE; \
-            } \
             if (!preload) { \
-                newenv = (char *) lib; \
+                newenv = (char *) libs; \
             } else { \
-                newenv = g_strdup_printf("%s:%s", lib, preload); \
+                newenv = g_strdup_printf("%s:%s", libs, preload); \
             } \
             g_setenv(PRELOAD_VAR, newenv, TRUE); \
             FORCE_FLAT_NAMESPACE \