[libvirt] [PATCH] tests: Allow multiple mock libraries

Make virtTestMain take variable number of libraries to mock. --- tests/testutils.c | 11 ++++++++--- tests/testutils.h | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/testutils.c b/tests/testutils.c index 9180e86..f4fbad2 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> @@ -842,9 +843,11 @@ virTestSetEnvPath(void) int virtTestMain(int argc, char **argv, - const char *lib, - int (*func)(void)) + int (*func)(void), + ...) { + const char *lib; + va_list ap; int ret; char *testRange = NULL; #ifdef TEST_OOM @@ -854,8 +857,10 @@ int virtTestMain(int argc, if (getenv("VIR_TEST_FILE_ACCESS")) VIRT_TEST_PRELOAD(TEST_MOCK); - if (lib) + va_start(ap, func); + while ((lib = va_arg(ap, const char *))) VIRT_TEST_PRELOAD(lib); + va_end(ap); progname = last_component(argv[0]); if (STRPREFIX(progname, "lt-")) diff --git a/tests/testutils.h b/tests/testutils.h index d1caf20..c892902 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -102,13 +102,13 @@ const char *virtTestCounterNext(void); int virtTestMain(int argc, char **argv, - const char *lib, - int (*func)(void)); + int (*func)(void), + ...); /* Setup, then call func() */ # define VIRT_TEST_MAIN(func) \ int main(int argc, char **argv) { \ - return virtTestMain(argc, argv, NULL, func); \ + return virtTestMain(argc, argv, func, NULL); \ } # define VIRT_TEST_PRELOAD(lib) \ @@ -131,9 +131,9 @@ int virtTestMain(int argc, } \ } while (0) -# define VIRT_TEST_MAIN_PRELOAD(func, lib) \ +# define VIRT_TEST_MAIN_PRELOAD(func, ...) \ int main(int argc, char **argv) { \ - return virtTestMain(argc, argv, lib, func); \ + return virtTestMain(argc, argv, func, __VA_ARGS__, NULL); \ } virCapsPtr virTestGenericCapsInit(void); -- 2.8.2

On 05/20/2016 10:27 AM, Peter Krempa wrote:
Make virtTestMain take variable number of libraries to mock. --- tests/testutils.c | 11 ++++++++--- tests/testutils.h | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-)
ACK - I've inserted this as a replacement to my patch 5 from the AES secret series, with of course the obvious change to move the "," between the libraries for my patch 6. John

On Fri, May 20, 2016 at 16:27:00 +0200, Peter Krempa wrote:
Make virtTestMain take variable number of libraries to mock. --- tests/testutils.c | 11 ++++++++--- tests/testutils.h | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/tests/testutils.c b/tests/testutils.c index 9180e86..f4fbad2 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -24,6 +24,7 @@
#include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> @@ -842,9 +843,11 @@ virTestSetEnvPath(void)
int virtTestMain(int argc, char **argv, - const char *lib, - int (*func)(void)) + int (*func)(void), + ...) { + const char *lib; + va_list ap; int ret; char *testRange = NULL; #ifdef TEST_OOM @@ -854,8 +857,10 @@ int virtTestMain(int argc, if (getenv("VIR_TEST_FILE_ACCESS")) VIRT_TEST_PRELOAD(TEST_MOCK);
- if (lib) + va_start(ap, func); + while ((lib = va_arg(ap, const char *))) VIRT_TEST_PRELOAD(lib); + va_end(ap);
progname = last_component(argv[0]); if (STRPREFIX(progname, "lt-"))
No doubt this is better than passing a string with comma separated list of libraries, but contrary to what you promised, it still adds one library followed by exec() at a time :-) Jirka
participants (3)
-
Jiri Denemark
-
John Ferlan
-
Peter Krempa