[PATCH] Allow test cases to be run selectively

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

When debugging a failing test with many test cases, it is useful
to be able to skip most tests. Introducing a new environment
variable VIR_TEST_RANGE=N-M enables execution of only the test
cases numbered N-M inclusive, starting from 1.

For example, to skip all the cgroup tests except 2

$ VIR_TEST_RANGE=2-3 VIR_TEST_DEBUG=1 ./vircgrouptest
TEST: vircgrouptest
 2) New cgroup for driver                                             ... Unexpected found LXC cgroup: 1
libvirt: Cgroup error : Failed to create controller cpu for group: No such file or directory
FAILED
 3) New cgroup for domain driver                                      ... Cannot find LXC cgroup: 1
libvirt: Cgroup error : Failed to create controller cpu for group: No such file or directory
FAILED

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tests/testutils.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index 2fdf7b8..89bab2a 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;
 }
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]