diff --git a/ChangeLog b/ChangeLog index f513193e8a..c9af194c15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jul 7 11:02:56 BST 2008 Daniel P. Berrange + + * 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 * proxy/libvirt_proxy.c: fix a compilation problem without Xen diff --git a/tests/testutils.c b/tests/testutils.c index 8e5d3dee0d..fc6348f51f 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -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);