mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00: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:
parent
f5ee422c58
commit
9710856b33
11
HACKING
11
HACKING
@ -37,6 +37,17 @@ and run the tests:
|
||||
|
||||
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
|
||||
a new feature or changing the output of a program.
|
||||
|
||||
|
@ -43,8 +43,6 @@ static int testCompareXMLToXMLFiles(const char *xml) {
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
if (ret != 0)
|
||||
fprintf(stderr, "expected: -------\n%s", actual);
|
||||
free(actual);
|
||||
virInterfaceDefFree(dev);
|
||||
return ret;
|
||||
|
@ -25,7 +25,7 @@ static int testDevice(const char *path, int expect)
|
||||
if (actual == expect) {
|
||||
return 0;
|
||||
} else {
|
||||
if (getenv("DEBUG_TESTS"))
|
||||
if (virtTestGetDebug())
|
||||
fprintf(stderr, "Expect %-6d Actual %-6d\n", expect, actual);
|
||||
return -1;
|
||||
}
|
||||
@ -55,7 +55,7 @@ mymain(int argc ATTRIBUTE_UNUSED,
|
||||
* register a handler to stop error messages cluttering
|
||||
* up display
|
||||
*/
|
||||
if (!getenv("VIR_TEST_DEBUG"))
|
||||
if (!virtTestGetDebug())
|
||||
virSetErrorFunc(NULL, testQuietError);
|
||||
|
||||
#define DO_TEST(dev, num) \
|
||||
|
@ -45,7 +45,7 @@
|
||||
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.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 testCounter = 0;
|
||||
@ -255,10 +255,10 @@ int virtTestDifference(FILE *stream,
|
||||
const char *actualStart = actual;
|
||||
const char *actualEnd = actual + (strlen(actual)-1);
|
||||
|
||||
if (!testDebug)
|
||||
if (!virtTestGetDebug())
|
||||
return 0;
|
||||
|
||||
if (testDebug < 2) {
|
||||
if (virtTestGetDebug() < 2) {
|
||||
/* Skip to first character where they differ */
|
||||
while (*expectStart && *actualStart &&
|
||||
*actualStart == *expectStart) {
|
||||
@ -322,12 +322,30 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED)
|
||||
}
|
||||
#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,
|
||||
char **argv,
|
||||
int (*func)(int, char **))
|
||||
{
|
||||
char *debugStr;
|
||||
int ret;
|
||||
#if TEST_OOM
|
||||
int approxAlloc = 0;
|
||||
@ -344,10 +362,6 @@ int virtTestMain(int argc,
|
||||
virRandomInitialize(time(NULL) ^ getpid()))
|
||||
return 1;
|
||||
|
||||
if ((debugStr = getenv("VIR_TEST_DEBUG")) != NULL) {
|
||||
if (virStrToLong_ui(debugStr, NULL, 10, &testDebug) < 0)
|
||||
testDebug = 0;
|
||||
}
|
||||
|
||||
#if TEST_OOM
|
||||
if ((oomStr = getenv("VIR_TEST_OOM")) != NULL) {
|
||||
@ -375,7 +389,7 @@ int virtTestMain(int argc,
|
||||
goto cleanup;
|
||||
|
||||
#if TEST_OOM_TRACE
|
||||
if (testDebug)
|
||||
if (virtTestGetDebug())
|
||||
virAllocTestHook(virtTestErrorHook, NULL);
|
||||
#endif
|
||||
|
||||
@ -393,7 +407,7 @@ int virtTestMain(int argc,
|
||||
|
||||
approxAlloc = virAllocTestCount();
|
||||
testCounter++;
|
||||
if (testDebug)
|
||||
if (virtTestGetDebug())
|
||||
fprintf(stderr, "%d) OOM...\n", testCounter);
|
||||
else
|
||||
fprintf(stderr, "%d) OOM of %d allocs ", testCounter, approxAlloc);
|
||||
@ -415,7 +429,7 @@ int virtTestMain(int argc,
|
||||
if (mp &&
|
||||
(n % mp) != (worker - 1))
|
||||
continue;
|
||||
if (!testDebug) {
|
||||
if (!virtTestGetDebug()) {
|
||||
if (mp)
|
||||
fprintf(stderr, "%d", worker);
|
||||
else
|
||||
@ -444,7 +458,7 @@ int virtTestMain(int argc,
|
||||
}
|
||||
}
|
||||
|
||||
if (testDebug)
|
||||
if (virtTestGetDebug())
|
||||
fprintf(stderr, " ... OOM of %d allocs", approxAlloc);
|
||||
|
||||
if (ret == EXIT_SUCCESS)
|
||||
|
@ -34,6 +34,8 @@ int virtTestDifference(FILE *stream,
|
||||
const char *expect,
|
||||
const char *actual);
|
||||
|
||||
unsigned int virtTestGetDebug(void);
|
||||
|
||||
int virtTestMain(int argc,
|
||||
char **argv,
|
||||
int (*func)(int, char **));
|
||||
@ -43,6 +45,4 @@ int virtTestMain(int argc,
|
||||
return virtTestMain(argc,argv, func); \
|
||||
}
|
||||
|
||||
extern unsigned int testDebug;
|
||||
|
||||
#endif /* __VIT_TEST_UTILS_H__ */
|
||||
|
@ -132,7 +132,7 @@ virCapsPtr testQemuCapsInit(void) {
|
||||
NULL) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if (testDebug) {
|
||||
if (virtTestGetDebug()) {
|
||||
char *caps_str;
|
||||
|
||||
caps_str = virCapabilitiesFormatXML(caps);
|
||||
|
Loading…
Reference in New Issue
Block a user