]> xenbits.xensource.com Git - libvirt.git/commitdiff
ALlow OOM tests to be parallelized
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 7 Jul 2008 10:10:29 +0000 (10:10 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 7 Jul 2008 10:10:29 +0000 (10:10 +0000)
ChangeLog
tests/testutils.c

index f513193e8ab6352b13055e64f573477bcdfb00b8..c9af194c15fce01691d4f7fa873ca9bacc820bbd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Jul  7 11:02:56 BST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       * tests/testutils.c: Allow OOM testing to be parallelized by
+       setting VIR_TEST_MP=1
+
 Mon Jul  7 11:59:07 CEST 2008 Daniel Veillard <veillard@redhat.com>
 
        * proxy/libvirt_proxy.c: fix a compilation problem without Xen
index 8e5d3dee0d6eb1521677957518887d92237d6030..fc6348f51f7d45b3153a973bac5b3370ee266a93 100644 (file)
@@ -330,7 +330,9 @@ int virtTestMain(int argc,
     int n;
     char *oomStr = NULL, *debugStr;
     int oomCount;
-
+    int mp = 0;
+    pid_t *workers;
+    int worker = 0;
     if ((debugStr = getenv("VIR_TEST_DEBUG")) != NULL) {
         if (virStrToLong_ui(debugStr, NULL, 10, &testDebug) < 0)
             testDebug = 0;
@@ -346,6 +348,13 @@ int virtTestMain(int argc,
             testOOM = 1;
     }
 
+    if (getenv("VIR_TEST_MP") != NULL) {
+        mp = sysconf(_SC_NPROCESSORS_ONLN);
+        fprintf(stderr, "Using %d worker processes\n", mp);
+        if (VIR_ALLOC_N(workers, mp) < 0)
+            return EXIT_FAILURE;
+    }
+
     if (testOOM)
         virAllocTestInit();
 
@@ -371,11 +380,27 @@ int virtTestMain(int argc,
         else
             fprintf(stderr, "%d) OOM of %d allocs ", testCounter, approxAlloc);
 
+        if (mp) {
+            int i;
+            for (i = 0 ; i < mp ; i++) {
+                workers[i] = fork();
+                if (workers[i] == 0) {
+                    worker = i + 1;
+                    break;
+                }
+            }
+        }
+
         /* Run once for each alloc, failing a different one
            and validating that the test case failed */
-        for (n = 0; n < approxAlloc ; n++) {
+        for (n = 0; n < approxAlloc && (!mp || worker) ; n++) {
+            if ((n % mp) != (worker - 1))
+                continue;
             if (!testDebug) {
-                fprintf(stderr, ".");
+                if (mp)
+                    fprintf(stderr, "%d", worker);
+                else
+                    fprintf(stderr, ".");
                 fflush(stderr);
             }
             virAllocTestOOM(n+1, oomCount);
@@ -386,6 +411,20 @@ int virtTestMain(int argc,
             }
         }
 
+        if (mp) {
+            if (worker) {
+                _exit(ret);
+            } else {
+                int i, status;
+                for (i = 0 ; i < mp ; i++) {
+                    waitpid(workers[i], &status, 0);
+                    if (WEXITSTATUS(status) != EXIT_SUCCESS)
+                        ret = EXIT_FAILURE;
+                }
+                VIR_FREE(workers);
+            }
+        }
+
         if (testDebug)
             fprintf(stderr, " ... OOM of %d allocs", approxAlloc);