1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-08-30 05:50:08 +03:00

tests: Centralize VIR_TEST_DEBUG lookup, and document it

Provide a simple interface for other tests to lookup the testDebug variable.
Also remove a redundant error message in interface tests.

If anyone feels inclined to change this env variable to match the existing
LIBVIRT_* format, it should now be easier to do so.
This commit is contained in:
Cole Robinson
2009-10-16 11:37:36 -04:00
parent f5ee422c58
commit 9710856b33
6 changed files with 42 additions and 19 deletions

11
HACKING
View File

@ -37,6 +37,17 @@ and run the tests:
The latter test checks for memory leaks. The latter test checks for memory leaks.
If you encounter any failing tests, the VIR_TEST_DEBUG environment variable
may provide extra information to debug the failures. Larger values of
VIR_TEST_DEBUG may provide larger amounts of information:
VIR_TEST_DEBUG=1 make check (or)
VIR_TEST_DEBUG=2 make check
Also, individual tests can be run from inside the 'tests/' directory, like:
./qemuxml2xmltest
(6) Update tests and/or documentation, particularly if you are adding (6) Update tests and/or documentation, particularly if you are adding
a new feature or changing the output of a program. a new feature or changing the output of a program.

View File

@ -43,8 +43,6 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0; ret = 0;
fail: fail:
if (ret != 0)
fprintf(stderr, "expected: -------\n%s", actual);
free(actual); free(actual);
virInterfaceDefFree(dev); virInterfaceDefFree(dev);
return ret; return ret;

View File

@ -25,7 +25,7 @@ static int testDevice(const char *path, int expect)
if (actual == expect) { if (actual == expect) {
return 0; return 0;
} else { } else {
if (getenv("DEBUG_TESTS")) if (virtTestGetDebug())
fprintf(stderr, "Expect %-6d Actual %-6d\n", expect, actual); fprintf(stderr, "Expect %-6d Actual %-6d\n", expect, actual);
return -1; return -1;
} }
@ -55,7 +55,7 @@ mymain(int argc ATTRIBUTE_UNUSED,
* register a handler to stop error messages cluttering * register a handler to stop error messages cluttering
* up display * up display
*/ */
if (!getenv("VIR_TEST_DEBUG")) if (!virtTestGetDebug())
virSetErrorFunc(NULL, testQuietError); virSetErrorFunc(NULL, testQuietError);
#define DO_TEST(dev, num) \ #define DO_TEST(dev, num) \

View File

@ -45,7 +45,7 @@
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
unsigned int testDebug = 0; static unsigned int testDebug = -1;
static unsigned int testOOM = 0; static unsigned int testOOM = 0;
static unsigned int testCounter = 0; static unsigned int testCounter = 0;
@ -255,10 +255,10 @@ int virtTestDifference(FILE *stream,
const char *actualStart = actual; const char *actualStart = actual;
const char *actualEnd = actual + (strlen(actual)-1); const char *actualEnd = actual + (strlen(actual)-1);
if (!testDebug) if (!virtTestGetDebug())
return 0; return 0;
if (testDebug < 2) { if (virtTestGetDebug() < 2) {
/* Skip to first character where they differ */ /* Skip to first character where they differ */
while (*expectStart && *actualStart && while (*expectStart && *actualStart &&
*actualStart == *expectStart) { *actualStart == *expectStart) {
@ -322,12 +322,30 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED)
} }
#endif #endif
unsigned int
virtTestGetDebug() {
char *debugStr;
unsigned int debug;
if (testDebug != -1)
return testDebug;
testDebug = 0;
if ((debugStr = getenv("VIR_TEST_DEBUG")) == NULL)
return 0;
if (virStrToLong_ui(debugStr, NULL, 10, &debug) < 0)
return 0;
testDebug = debug;
return testDebug;
}
int virtTestMain(int argc, int virtTestMain(int argc,
char **argv, char **argv,
int (*func)(int, char **)) int (*func)(int, char **))
{ {
char *debugStr;
int ret; int ret;
#if TEST_OOM #if TEST_OOM
int approxAlloc = 0; int approxAlloc = 0;
@ -344,10 +362,6 @@ int virtTestMain(int argc,
virRandomInitialize(time(NULL) ^ getpid())) virRandomInitialize(time(NULL) ^ getpid()))
return 1; return 1;
if ((debugStr = getenv("VIR_TEST_DEBUG")) != NULL) {
if (virStrToLong_ui(debugStr, NULL, 10, &testDebug) < 0)
testDebug = 0;
}
#if TEST_OOM #if TEST_OOM
if ((oomStr = getenv("VIR_TEST_OOM")) != NULL) { if ((oomStr = getenv("VIR_TEST_OOM")) != NULL) {
@ -375,7 +389,7 @@ int virtTestMain(int argc,
goto cleanup; goto cleanup;
#if TEST_OOM_TRACE #if TEST_OOM_TRACE
if (testDebug) if (virtTestGetDebug())
virAllocTestHook(virtTestErrorHook, NULL); virAllocTestHook(virtTestErrorHook, NULL);
#endif #endif
@ -393,7 +407,7 @@ int virtTestMain(int argc,
approxAlloc = virAllocTestCount(); approxAlloc = virAllocTestCount();
testCounter++; testCounter++;
if (testDebug) if (virtTestGetDebug())
fprintf(stderr, "%d) OOM...\n", testCounter); fprintf(stderr, "%d) OOM...\n", testCounter);
else else
fprintf(stderr, "%d) OOM of %d allocs ", testCounter, approxAlloc); fprintf(stderr, "%d) OOM of %d allocs ", testCounter, approxAlloc);
@ -415,7 +429,7 @@ int virtTestMain(int argc,
if (mp && if (mp &&
(n % mp) != (worker - 1)) (n % mp) != (worker - 1))
continue; continue;
if (!testDebug) { if (!virtTestGetDebug()) {
if (mp) if (mp)
fprintf(stderr, "%d", worker); fprintf(stderr, "%d", worker);
else else
@ -444,7 +458,7 @@ int virtTestMain(int argc,
} }
} }
if (testDebug) if (virtTestGetDebug())
fprintf(stderr, " ... OOM of %d allocs", approxAlloc); fprintf(stderr, " ... OOM of %d allocs", approxAlloc);
if (ret == EXIT_SUCCESS) if (ret == EXIT_SUCCESS)

View File

@ -34,6 +34,8 @@ int virtTestDifference(FILE *stream,
const char *expect, const char *expect,
const char *actual); const char *actual);
unsigned int virtTestGetDebug(void);
int virtTestMain(int argc, int virtTestMain(int argc,
char **argv, char **argv,
int (*func)(int, char **)); int (*func)(int, char **));
@ -43,6 +45,4 @@ int virtTestMain(int argc,
return virtTestMain(argc,argv, func); \ return virtTestMain(argc,argv, func); \
} }
extern unsigned int testDebug;
#endif /* __VIT_TEST_UTILS_H__ */ #endif /* __VIT_TEST_UTILS_H__ */

View File

@ -132,7 +132,7 @@ virCapsPtr testQemuCapsInit(void) {
NULL) == NULL) NULL) == NULL)
goto cleanup; goto cleanup;
if (testDebug) { if (virtTestGetDebug()) {
char *caps_str; char *caps_str;
caps_str = virCapabilitiesFormatXML(caps); caps_str = virCapabilitiesFormatXML(caps);