[libvirt] [PATCH] tests: avoid re-execing test once for each mock

Daniel P. Berrangé posted 1 patch 30 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200109180439.2665929-1-berrange@redhat.com
tests/qemucapsprobe.c |  8 +++++++-
tests/testutils.c     | 29 ++++++++++++++++++++++++-----
tests/testutils.h     | 10 +++-------
3 files changed, 34 insertions(+), 13 deletions(-)

[libvirt] [PATCH] tests: avoid re-execing test once for each mock

Posted by Daniel P. Berrangé 30 weeks ago
When debugging tests under GDB there is a significant time
delay each time an execve is done as GDB scans shared libraries
once again. For tests which use many mock libraries, we have
been invoking execve many times which makes the GDB experience
horrible. This changes our framework to activate the full
set of mock libraries in one single execve.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/qemucapsprobe.c |  8 +++++++-
 tests/testutils.c     | 29 ++++++++++++++++++++++++-----
 tests/testutils.h     | 10 +++-------
 3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c
index 6837f2a0f6..c7e8f3309d 100644
--- a/tests/qemucapsprobe.c
+++ b/tests/qemucapsprobe.c
@@ -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]);
diff --git a/tests/testutils.c b/tests/testutils.c
index 6f0ef2b2f1..b490609e36 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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;
diff --git a/tests/testutils.h b/tests/testutils.h
index 8a7ea38f43..2944c25e8b 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -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) { \
             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 \
-- 
2.24.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] tests: avoid re-execing test once for each mock

Posted by Michal Privoznik 30 weeks ago
On 1/9/20 7:04 PM, Daniel P. Berrangé wrote:
> When debugging tests under GDB there is a significant time
> delay each time an execve is done as GDB scans shared libraries
> once again. For tests which use many mock libraries, we have
> been invoking execve many times which makes the GDB experience
> horrible. This changes our framework to activate the full
> set of mock libraries in one single execve.

It's not only gdb, the performance drop is even more visible with 
valgrind --trace-children=yes.

> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/qemucapsprobe.c |  8 +++++++-
>   tests/testutils.c     | 29 ++++++++++++++++++++++++-----
>   tests/testutils.h     | 10 +++-------
>   3 files changed, 34 insertions(+), 13 deletions(-)
> 
> diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c
> index 6837f2a0f6..c7e8f3309d 100644
> --- a/tests/qemucapsprobe.c
> +++ b/tests/qemucapsprobe.c
> @@ -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]);
> diff --git a/tests/testutils.c b/tests/testutils.c
> index 6f0ef2b2f1..b490609e36 100644
> --- a/tests/testutils.c
> +++ b/tests/testutils.c
> @@ -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;
> diff --git a/tests/testutils.h b/tests/testutils.h
> index 8a7ea38f43..2944c25e8b 100644
> --- a/tests/testutils.h
> +++ b/tests/testutils.h
> @@ -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) { \

s/lib/libs/

>               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 \
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list