提交 975f2d1c 编写于 作者: D Daniel P. Berrangé

tests: avoid re-execing test once for each mock

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: NMichal Privoznik <mprivozn@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 66ec00ab
...@@ -46,8 +46,14 @@ main(int argc, char **argv) ...@@ -46,8 +46,14 @@ main(int argc, char **argv)
{ {
virThread thread; virThread thread;
virQEMUCapsPtr caps; 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) { if (argc != 2) {
fprintf(stderr, "%s QEMU_binary\n", argv[0]); fprintf(stderr, "%s QEMU_binary\n", argv[0]);
......
...@@ -856,15 +856,34 @@ int virTestMain(int argc, ...@@ -856,15 +856,34 @@ int virTestMain(int argc,
virLogOutputPtr *outputs = NULL; virLogOutputPtr *outputs = NULL;
g_autofree char *baseprogname = NULL; g_autofree char *baseprogname = NULL;
const char *progname; const char *progname;
g_autofree const char **preloads = NULL;
if (getenv("VIR_TEST_FILE_ACCESS")) size_t npreloads = 0;
VIR_TEST_PRELOAD(VIR_TEST_MOCK("virtest")); 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); va_start(ap, func);
while ((lib = va_arg(ap, const char *))) while ((lib = va_arg(ap, const char *))) {
VIR_TEST_PRELOAD(lib); 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); va_end(ap);
if (preloads) {
mock = g_strjoinv(":", (char **)preloads);
VIR_TEST_PRELOAD(mock);
}
progname = baseprogname = g_path_get_basename(argv[0]); progname = baseprogname = g_path_get_basename(argv[0]);
if (STRPREFIX(progname, "lt-")) if (STRPREFIX(progname, "lt-"))
progname += 3; progname += 3;
......
...@@ -127,19 +127,15 @@ int virTestMain(int argc, ...@@ -127,19 +127,15 @@ int virTestMain(int argc,
# define MOCK_EXT ".so" # define MOCK_EXT ".so"
#endif #endif
#define VIR_TEST_PRELOAD(lib) \ #define VIR_TEST_PRELOAD(libs) \
do { \ do { \
const char *preload = getenv(PRELOAD_VAR); \ const char *preload = getenv(PRELOAD_VAR); \
if (preload == NULL || strstr(preload, lib) == NULL) { \ if (preload == NULL || strstr(preload, libs) == NULL) { \
char *newenv; \ char *newenv; \
if (!virFileIsExecutable(lib)) { \
perror(lib); \
return EXIT_FAILURE; \
} \
if (!preload) { \ if (!preload) { \
newenv = (char *) lib; \ newenv = (char *) libs; \
} else { \ } else { \
newenv = g_strdup_printf("%s:%s", lib, preload); \ newenv = g_strdup_printf("%s:%s", libs, preload); \
} \ } \
g_setenv(PRELOAD_VAR, newenv, TRUE); \ g_setenv(PRELOAD_VAR, newenv, TRUE); \
FORCE_FLAT_NAMESPACE \ FORCE_FLAT_NAMESPACE \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册