mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
tests: cputests: introduce and use virTestRunLog
A helper that resets the log before each test and prints it on failure. It also takes the return variable as an argument, so it can be used to eliminate number of branches the compiler has to consider in the main function. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
0ee2cc3ad8
commit
8628cbe6ad
@ -912,23 +912,11 @@ mymain(void)
|
||||
flags, result \
|
||||
}; \
|
||||
g_autofree char *testLabel = NULL; \
|
||||
\
|
||||
g_free(virTestLogContentAndReset());\
|
||||
\
|
||||
testLabel = g_strdup_printf("%s(%s): %s", #api, \
|
||||
virArchToString(arch), name); \
|
||||
\
|
||||
if (virTestRun(testLabel, api, &data) < 0) { \
|
||||
if (virTestGetDebug()) { \
|
||||
char *log; \
|
||||
if ((log = virTestLogContentAndReset()) && \
|
||||
strlen(log) > 0) \
|
||||
VIR_TEST_DEBUG("\n%s", log); \
|
||||
VIR_FREE(log); \
|
||||
} \
|
||||
ret = -1; \
|
||||
} \
|
||||
\
|
||||
virTestRunLog(&ret, testLabel, api, &data); \
|
||||
} while (0)
|
||||
|
||||
#define DO_TEST_COMPARE(arch, host, cpu, result) \
|
||||
|
@ -180,6 +180,36 @@ virTestRun(const char *title,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* A wrapper for virTestRun that resets the log content before each run
|
||||
* and sets ret to -1 on failure. On success, ret is untouched.
|
||||
*/
|
||||
void
|
||||
virTestRunLog(int *ret,
|
||||
const char *title,
|
||||
int (*body)(const void *data),
|
||||
const void *data)
|
||||
{
|
||||
int rc;
|
||||
|
||||
g_free(virTestLogContentAndReset());
|
||||
|
||||
rc = virTestRun(title, body, data);
|
||||
|
||||
if (rc >= 0)
|
||||
return;
|
||||
|
||||
*ret = -1;
|
||||
|
||||
if (virTestGetDebug()) {
|
||||
g_autofree char *log = virTestLogContentAndReset();
|
||||
|
||||
if (strlen(log) > 0)
|
||||
VIR_TEST_DEBUG("\n%s", log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virTestLoadFile:
|
||||
* @file: name of the file to load
|
||||
|
@ -40,6 +40,10 @@ extern virArch virTestHostArch;
|
||||
int virTestRun(const char *title,
|
||||
int (*body)(const void *data),
|
||||
const void *data);
|
||||
void virTestRunLog(int *ret,
|
||||
const char *title,
|
||||
int (*body)(const void *data),
|
||||
const void *data);
|
||||
int virTestLoadFile(const char *file, char **buf);
|
||||
char *virTestLoadFilePath(const char *p, ...)
|
||||
G_GNUC_NULL_TERMINATED;
|
||||
|
Loading…
Reference in New Issue
Block a user