diff --git a/tests/testutils.c b/tests/testutils.c index 2fdf7b8e7a..89bab2a59e 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -68,7 +68,9 @@ static unsigned int testDebug = -1; static unsigned int testVerbose = -1; static unsigned int testOOM = 0; -static unsigned int testCounter = 0; +static size_t testCounter = 0; +static size_t testStart = 0; +static size_t testEnd = 0; char *progname; char *abs_srcdir; @@ -96,7 +98,7 @@ void virtTestResult(const char *name, int ret, const char *msg, ...) testCounter++; if (virTestGetVerbose()) { - fprintf(stderr, "%3d) %-60s ", testCounter, name); + fprintf(stderr, "%3zu) %-60s ", testCounter, name); if (ret == 0) fprintf(stderr, "OK\n"); else { @@ -112,7 +114,7 @@ void virtTestResult(const char *name, int ret, const char *msg, ...) } else { if (testCounter != 1 && !((testCounter-1) % 40)) { - fprintf(stderr, " %-3d\n", (testCounter-1)); + fprintf(stderr, " %-3zu\n", (testCounter-1)); fprintf(stderr, " "); } if (ret == 0) @@ -141,9 +143,16 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const testCounter++; + + /* Skip tests if out of range */ + if ((testStart != 0) && + (testCounter < testStart || + testCounter > testEnd)) + return 0; + if (testOOM < 2) { if (virTestGetVerbose()) - fprintf(stderr, "%2d) %-65s ... ", testCounter, title); + fprintf(stderr, "%2zu) %-65s ... ", testCounter, title); } if (nloops > 1 && (VIR_ALLOC_N(ts, nloops) < 0)) @@ -186,7 +195,7 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const } else { if (testCounter != 1 && !((testCounter-1) % 40)) { - fprintf(stderr, " %-3d\n", (testCounter-1)); + fprintf(stderr, " %-3zu\n", (testCounter-1)); fprintf(stderr, " "); } if (ret == 0) @@ -578,6 +587,7 @@ int virtTestMain(int argc, { int ret; bool abs_srcdir_cleanup = false; + char *testRange = NULL; #if TEST_OOM int approxAlloc = 0; int n; @@ -620,6 +630,33 @@ int virtTestMain(int argc, return EXIT_FAILURE; } + if ((testRange = getenv("VIR_TEST_RANGE")) != NULL) { + char *end = NULL; + unsigned int i; + if (virStrToLong_ui(testRange, &end, 10, &i) < 0) { + fprintf(stderr, "Cannot parse range %s\n", testRange); + return EXIT_FAILURE; + } + testStart = testEnd = i; + if (end && *end) { + if (*end != '-') { + fprintf(stderr, "Cannot parse range %s\n", testRange); + return EXIT_FAILURE; + } + end++; + if (virStrToLong_ui(end, NULL, 10, &i) < 0) { + fprintf(stderr, "Cannot parse range %s\n", testRange); + return EXIT_FAILURE; + } + testEnd = i; + + if (testEnd < testStart) { + fprintf(stderr, "Test range end %zu must be >= %zu\n", testEnd, testStart); + return EXIT_FAILURE; + } + } + } + #if TEST_OOM if ((oomStr = getenv("VIR_TEST_OOM")) != NULL) { if (virStrToLong_i(oomStr, NULL, 10, &oomCount) < 0) @@ -732,8 +769,8 @@ cleanup: virResetLastError(); if (!virTestGetVerbose() && ret != EXIT_AM_SKIP) { if (testCounter == 0 || testCounter % 40) - fprintf(stderr, "%*s", 40 - (testCounter % 40), ""); - fprintf(stderr, " %-3d %s\n", testCounter, ret == 0 ? "OK" : "FAIL"); + fprintf(stderr, "%*s", 40 - (int)(testCounter % 40), ""); + fprintf(stderr, " %-3zu %s\n", testCounter, ret == 0 ? "OK" : "FAIL"); } return ret; }