ALlow OOM tests to be parallelized

This commit is contained in:
Daniel P. Berrange 2008-07-07 10:10:29 +00:00
parent 8d18d826a4
commit 0caf27a2b0
2 changed files with 47 additions and 3 deletions

View File

@ -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

View 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);