From e8ac4a79f17b741e46980d1db8ca8815b060d39e Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 30 Nov 2009 19:01:31 +0000 Subject: Make test suite output less verbose Only print out '.' for each test case, full test output can be re-enabled with VIR_TEST_VERBOSE=1, or VIR_TEST_DEBUG=XXXX Sample output now looks like TEST: statstest ........................................ 40 ................................... 75 OK PASS: statstest TEST: qparamtest ................................ 32 OK PASS: qparamtest TEST: ............ 12 OK --- tests/capabilityschematest | 3 +- tests/daemon-conf | 27 +++++----- tests/domainschematest | 3 +- tests/esxutilstest.c | 2 +- tests/eventtest.c | 78 ++++++++++++++--------------- tests/interfaceschematest | 3 +- tests/networkschematest | 3 +- tests/nodedevschematest | 3 +- tests/schematestutils.sh | 20 ++++---- tests/statstest.c | 4 +- tests/storagepoolschematest | 3 +- tests/storagevolschematest | 3 +- tests/test-lib.sh | 64 ++++++++++++++++++++++++ tests/test_conf.sh | 23 +++------ tests/testutils.c | 117 ++++++++++++++++++++++++++++++++++---------- tests/testutils.h | 4 +- tests/testutilsqemu.c | 2 +- tests/virsh-all | 25 ++++++---- 18 files changed, 263 insertions(+), 124 deletions(-) diff --git a/tests/capabilityschematest b/tests/capabilityschematest index 482dfe305..443984237 100755 --- a/tests/capabilityschematest +++ b/tests/capabilityschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="capabilityschemadata xencapsdata" SCHEMA="capability.rng" diff --git a/tests/daemon-conf b/tests/daemon-conf index 722fe4e43..1eb4be17b 100755 --- a/tests/daemon-conf +++ b/tests/daemon-conf @@ -2,15 +2,14 @@ # Get coverage of libvirtd's config-parsing code. test -z "$srcdir" && srcdir=$(pwd) -test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. -test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. +LC_ALL=C +. "$srcdir/test-lib.sh" -if test "$VERBOSE" = yes; then - set -x +if test "$verbose" = yes; then $abs_top_builddir/daemon/libvirtd --version fi -. "$srcdir/test-lib.sh" +test_intro "$this_test" test -z "$CONFIG_HEADER" && CONFIG_HEADER="$abs_top_builddir/config.h" @@ -30,10 +29,12 @@ sed -n 's/^#\([^ #]\)/\1/p' "$conf" > tmp.conf # time and running libvirtd with the resulting config. Each libvirtd # invocation must fail. n=$(wc -l < tmp.conf) -i=1 +i=0 +fail=0 while :; do + i=$(expr $i + 1) + param_name=$(sed -n "$i"'s/ = .*//p' tmp.conf) - printf "testing with corrupted config: $param_name\n" 1>&2 rhs=$(sed -n "$i"'s/.* = \(.*\)/\1/p' tmp.conf) f=in$i.conf case $rhs in @@ -59,9 +60,8 @@ while :; do # Check that the diagnostic we want appears grep "$msg" err 1>/dev/null 2>&1 RET=$? + test_result $i "corrupted config $param_name" $RET test "$RET" = "0" || fail=1 - - i=$(expr $i + 1) done # Run with the unmodified config file. @@ -76,13 +76,18 @@ sed 's,^log_outputs.*,log_outputs="3:file:'"$(pwd)/log"'",' tmp.conf > k \ || fail=1 mv k tmp.conf || fail=1 -printf "running libvirtd with a valid config file ($sleep_secs seconds)\n" 1>&2 $abs_top_builddir/daemon/libvirtd --pid-file=pid-file --config=tmp.conf > log 2>&1 & pid=$! sleep $sleep_secs kill $pid +RET=0 # Expect an orderly shut-down and successful exit. -wait $pid || fail=1 +wait $pid || RET=1 + +test_result $i "valid config file (sleeping $sleep_secs seconds)" $RET +test $RET = 0 || fail=1 + +test_final $i $fail # "cat log" would print this for non-root: # Cannot set group when not running as root diff --git a/tests/domainschematest b/tests/domainschematest index 27a93cf86..d513f5adf 100755 --- a/tests/domainschematest +++ b/tests/domainschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="domainschemadata qemuxml2argvdata sexpr2xmldata xmconfigdata xml2sexprdata" SCHEMA="domain.rng" diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index 058280dd7..f73df4878 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -75,7 +75,7 @@ testDiskNameToIndex(const void *data ATTRIBUTE_UNUSED) k = virDiskNameToIndex(name); if (k != i) { - if (virtTestGetDebug() > 0) { + if (virTestGetDebug() > 0) { fprintf(stderr, "\nExpect [%d]\n", i); fprintf(stderr, "Actual [%d]\n", k); } diff --git a/tests/eventtest.c b/tests/eventtest.c index 90c60bb9a..067e365ea 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -139,7 +139,7 @@ static void *eventThreadLoop(void *data ATTRIBUTE_UNUSED) { static int -verifyFired(int handle, int timer) +verifyFired(const char *name, int handle, int timer) { int handleFired = 0; int timerFired = 0; @@ -147,25 +147,25 @@ verifyFired(int handle, int timer) for (i = 0 ; i < NUM_FDS ; i++) { if (handles[i].fired) { if (i != handle) { - fprintf(stderr, "FAIL Handle %d fired, but expected %d\n", i, handle); + virtTestResult(name, 1, "Handle %d fired, but expected %d\n", i, handle); return EXIT_FAILURE; } else { if (handles[i].error != EV_ERROR_NONE) { - fprintf(stderr, "FAIL Handle %d fired, but had error %d\n", i, - handles[i].error); + virtTestResult(name, 1, "Handle %d fired, but had error %d\n", i, + handles[i].error); return EXIT_FAILURE; } handleFired = 1; } } else { if (i == handle) { - fprintf(stderr, "FAIL Handle %d should have fired, but didn't\n", handle); + virtTestResult(name, 1, "Handle %d should have fired, but didn't\n", handle); return EXIT_FAILURE; } } } if (handleFired != 1 && handle != -1) { - fprintf(stderr, "FAIL Something wierd happened, expecting handle %d\n", handle); + virtTestResult(name, 1, "Something wierd happened, expecting handle %d\n", handle); return EXIT_FAILURE; } @@ -173,34 +173,33 @@ verifyFired(int handle, int timer) for (i = 0 ; i < NUM_TIME ; i++) { if (timers[i].fired) { if (i != timer) { - fprintf(stderr, "FAIL Timer %d fired, but expected %d\n", i, timer); + virtTestResult(name, 1, "Timer %d fired, but expected %d\n", i, timer); return EXIT_FAILURE; } else { if (timers[i].error != EV_ERROR_NONE) { - fprintf(stderr, "FAIL Timer %d fired, but had error %d\n", i, - timers[i].error); + virtTestResult(name, 1, "Timer %d fired, but had error %d\n", i, + timers[i].error); return EXIT_FAILURE; } timerFired = 1; } } else { if (i == timer) { - fprintf(stderr, "FAIL Timer %d should have fired, but didn't\n", timer); + virtTestResult(name, 1, "Timer %d should have fired, but didn't\n", timer); return EXIT_FAILURE; } } } if (timerFired != 1 && timer != -1) { - fprintf(stderr, "FAIL Something wierd happened, expecting timer %d\n", timer); + virtTestResult(name, 1, "Something wierd happened, expecting timer %d\n", timer); return EXIT_FAILURE; } return EXIT_SUCCESS; } static void -startJob(const char *msg, int *test) +startJob(void) { - fprintf(stderr, "%2d: %s ", (*test)++, msg); eventThreadRunOnce = 1; eventThreadJobDone = 0; pthread_cond_signal(&eventThreadRunCond); @@ -210,7 +209,7 @@ startJob(const char *msg, int *test) } static int -finishJob(int handle, int timer) +finishJob(const char *name, int handle, int timer) { struct timespec waitTime; int rc; @@ -220,14 +219,14 @@ finishJob(int handle, int timer) while (!eventThreadJobDone && rc == 0) rc = pthread_cond_timedwait(&eventThreadJobCond, &eventThreadMutex, &waitTime); if (rc != 0) { - fprintf(stderr, "FAIL Timed out waiting for pipe event\n"); + virtTestResult(name, 1, "Timed out waiting for pipe event\n"); return EXIT_FAILURE; } - if (verifyFired(handle, timer) != EXIT_SUCCESS) + if (verifyFired(name, handle, timer) != EXIT_SUCCESS) return EXIT_FAILURE; - fprintf(stderr, "OK\n"); + virtTestResult(name, 0, NULL); return EXIT_SUCCESS; } @@ -252,7 +251,6 @@ mymain(int argc, char **argv) int i; pthread_t eventThread; char one = '1'; - int test = 1; progname = argv[0]; @@ -302,10 +300,10 @@ mymain(int argc, char **argv) /* First time, is easy - just try triggering one of our * registered handles */ - startJob("Simple write", &test); + startJob(); if (safewrite(handles[1].pipeFD[1], &one, 1) != 1) return EXIT_FAILURE; - if (finishJob(1, -1) != EXIT_SUCCESS) + if (finishJob("Simple write", 1, -1) != EXIT_SUCCESS) return EXIT_FAILURE; resetAll(); @@ -313,10 +311,10 @@ mymain(int argc, char **argv) /* Now lets delete one before starting poll(), and * try triggering another handle */ virEventRemoveHandleImpl(handles[0].watch); - startJob("Deleted before poll", &test); + startJob(); if (safewrite(handles[1].pipeFD[1], &one, 1) != 1) return EXIT_FAILURE; - if (finishJob(1, -1) != EXIT_SUCCESS) + if (finishJob("Deleted before poll", 1, -1) != EXIT_SUCCESS) return EXIT_FAILURE; resetAll(); @@ -327,13 +325,13 @@ mymain(int argc, char **argv) /* NB: this case is subject to a bit of a race condition. * We yield & sleep, and pray that the other thread gets * scheduled before we run EventRemoveHandleImpl */ - startJob("Interrupted during poll", &test); + startJob(); pthread_mutex_unlock(&eventThreadMutex); sched_yield(); usleep(100 * 1000); pthread_mutex_lock(&eventThreadMutex); virEventRemoveHandleImpl(handles[1].watch); - if (finishJob(-1, -1) != EXIT_SUCCESS) + if (finishJob("Interrupted during poll", -1, -1) != EXIT_SUCCESS) return EXIT_FAILURE; resetAll(); @@ -345,22 +343,22 @@ mymain(int argc, char **argv) * before poll() exits for the first safewrite(). We don't * see a hard failure in other cases, so nothing to worry * about */ - startJob("Deleted during dispatch", &test); + startJob(); handles[2].delete = handles[3].watch; if (safewrite(handles[2].pipeFD[1], &one, 1) != 1 || safewrite(handles[3].pipeFD[1], &one, 1) != 1) return EXIT_FAILURE; - if (finishJob(2, -1) != EXIT_SUCCESS) + if (finishJob("Deleted during dispatch", 2, -1) != EXIT_SUCCESS) return EXIT_FAILURE; resetAll(); /* Extreme fun, lets delete ourselves during dispatch */ - startJob("Deleted during dispatch", &test); + startJob(); handles[2].delete = handles[2].watch; if (safewrite(handles[2].pipeFD[1], &one, 1) != 1) return EXIT_FAILURE; - if (finishJob(2, -1) != EXIT_SUCCESS) + if (finishJob("Deleted during dispatch", 2, -1) != EXIT_SUCCESS) return EXIT_FAILURE; resetAll(); @@ -369,8 +367,8 @@ mymain(int argc, char **argv) /* Run a timer on its own */ virEventUpdateTimeoutImpl(timers[1].timer, 100); - startJob("Firing a timer", &test); - if (finishJob(-1, 1) != EXIT_SUCCESS) + startJob(); + if (finishJob("Firing a timer", -1, 1) != EXIT_SUCCESS) return EXIT_FAILURE; virEventUpdateTimeoutImpl(timers[1].timer, -1); @@ -380,8 +378,8 @@ mymain(int argc, char **argv) * try triggering another timer */ virEventUpdateTimeoutImpl(timers[1].timer, 100); virEventRemoveTimeoutImpl(timers[0].timer); - startJob("Deleted before poll", &test); - if (finishJob(-1, 1) != EXIT_SUCCESS) + startJob(); + if (finishJob("Deleted before poll", -1, 1) != EXIT_SUCCESS) return EXIT_FAILURE; virEventUpdateTimeoutImpl(timers[1].timer, -1); @@ -393,13 +391,13 @@ mymain(int argc, char **argv) /* NB: this case is subject to a bit of a race condition. * We yield & sleep, and pray that the other thread gets * scheduled before we run EventRemoveTimeoutImpl */ - startJob("Interrupted during poll", &test); + startJob(); pthread_mutex_unlock(&eventThreadMutex); sched_yield(); usleep(100 * 1000); pthread_mutex_lock(&eventThreadMutex); virEventRemoveTimeoutImpl(timers[1].timer); - if (finishJob(-1, -1) != EXIT_SUCCESS) + if (finishJob("Interrupted during poll", -1, -1) != EXIT_SUCCESS) return EXIT_FAILURE; resetAll(); @@ -413,9 +411,9 @@ mymain(int argc, char **argv) * about */ virEventUpdateTimeoutImpl(timers[2].timer, 100); virEventUpdateTimeoutImpl(timers[3].timer, 100); - startJob("Deleted during dispatch", &test); + startJob(); timers[2].delete = timers[3].timer; - if (finishJob(-1, 2) != EXIT_SUCCESS) + if (finishJob("Deleted during dispatch", -1, 2) != EXIT_SUCCESS) return EXIT_FAILURE; virEventUpdateTimeoutImpl(timers[2].timer, -1); @@ -423,9 +421,9 @@ mymain(int argc, char **argv) /* Extreme fun, lets delete ourselves during dispatch */ virEventUpdateTimeoutImpl(timers[2].timer, 100); - startJob("Deleted during dispatch", &test); + startJob(); timers[2].delete = timers[2].timer; - if (finishJob(-1, 2) != EXIT_SUCCESS) + if (finishJob("Deleted during dispatch", -1, 2) != EXIT_SUCCESS) return EXIT_FAILURE; for (i = 0 ; i < NUM_FDS ; i++) @@ -448,10 +446,10 @@ mymain(int argc, char **argv) VIR_EVENT_HANDLE_READABLE, testPipeReader, &handles[1], NULL); - startJob("Write duplicate", &test); + startJob(); if (safewrite(handles[1].pipeFD[1], &one, 1) != 1) return EXIT_FAILURE; - if (finishJob(1, -1) != EXIT_SUCCESS) + if (finishJob("Write duplicate", 1, -1) != EXIT_SUCCESS) return EXIT_FAILURE; //pthread_kill(eventThread, SIGTERM); diff --git a/tests/interfaceschematest b/tests/interfaceschematest index 8e9f6ee21..1ddbc53fa 100755 --- a/tests/interfaceschematest +++ b/tests/interfaceschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="interfaceschemadata" SCHEMA="interface.rng" diff --git a/tests/networkschematest b/tests/networkschematest index 72100551a..46f3fc52b 100755 --- a/tests/networkschematest +++ b/tests/networkschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="../src/network networkxml2xmlin networkxml2xmlout" SCHEMA="network.rng" diff --git a/tests/nodedevschematest b/tests/nodedevschematest index 3f0f03f9a..03a15779e 100755 --- a/tests/nodedevschematest +++ b/tests/nodedevschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="nodedevschemadata" SCHEMA="nodedev.rng" diff --git a/tests/schematestutils.sh b/tests/schematestutils.sh index 56e6d83cf..301b9ebc6 100644 --- a/tests/schematestutils.sh +++ b/tests/schematestutils.sh @@ -1,12 +1,11 @@ #!/bin/sh -test -z "$srcdir" && srcdir=`pwd` -test -z "$abs_srcdir" && abs_srcdir=`pwd` - check_schema () { DIRS=$1 -SCHEMA="$srcdir/../docs/schemas/$2" +SCHEMA="$abs_srcdir/../docs/schemas/$2" + +test_intro $this_test n=0 f=0 @@ -17,20 +16,21 @@ do for xml in $XML do n=`expr $n + 1` - printf "%4d) %.60s " $n $(basename $(dirname $xml))"/"$(basename $xml) cmd="xmllint --relaxng $SCHEMA --noout $xml" result=`$cmd 2>&1` ret=$? - if test $ret = 0; then - echo "OK" - else - echo "FAILED" + + test_result $n $(basename $(dirname $xml))"/"$(basename $xml) $ret + if test "$verbose" = "1" -a $ret != 0 ; then echo -e "$cmd\n$result" + fi + if test "$ret" != 0 ; then f=`expr $f + 1` fi done done -echo "Validated $n files, $f failed" + +test_final $n $f ret=0 test $f != 0 && ret=255 diff --git a/tests/statstest.c b/tests/statstest.c index 4c2ea7ffd..c7a54302e 100644 --- a/tests/statstest.c +++ b/tests/statstest.c @@ -25,7 +25,7 @@ static int testDevice(const char *path, int expect) if (actual == expect) { return 0; } else { - if (virtTestGetDebug()) + if (virTestGetDebug()) fprintf(stderr, "Expect %-6d Actual %-6d\n", expect, actual); return -1; } @@ -55,7 +55,7 @@ mymain(int argc ATTRIBUTE_UNUSED, * register a handler to stop error messages cluttering * up display */ - if (!virtTestGetDebug()) + if (!virTestGetDebug()) virSetErrorFunc(NULL, testQuietError); #define DO_TEST(dev, num) \ diff --git a/tests/storagepoolschematest b/tests/storagepoolschematest index 9aef38298..9844c7677 100755 --- a/tests/storagepoolschematest +++ b/tests/storagepoolschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="storagepoolxml2xmlin storagepoolxml2xmlout" SCHEMA="storagepool.rng" diff --git a/tests/storagevolschematest b/tests/storagevolschematest index 74b62030b..e1afa8dd9 100755 --- a/tests/storagevolschematest +++ b/tests/storagevolschematest @@ -1,7 +1,8 @@ #!/bin/sh : ${srcdir=.} -. $srcdir/schematestutils.sh +. $srcdir/test-lib.sh +. $abs_srcdir/schematestutils.sh DIRS="storagevolxml2xmlin storagevolxml2xmlout" SCHEMA="storagevol.rng" diff --git a/tests/test-lib.sh b/tests/test-lib.sh index a007109b8..43265f3a9 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -1,5 +1,11 @@ # source this file; set up for tests +test -z "$abs_srcdir" && abs_srcdir=$(pwd) +test -z "$abs_builddir" && abs_builddir=$(pwd) +test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. +test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. +test -z "$LC_ALL" && LC_ALL=C + # Skip this test if the shell lacks support for functions. unset function_test eval 'function_test() { return 11; }; function_test' @@ -8,6 +14,59 @@ if test $? != 11; then (exit 77); exit 77 fi +test_intro() +{ + name=$1 + if test "$verbose" = "0" ; then + echo "TEST: $name" + echo -n " " + fi +} + +test_result() +{ + counter=$1 + name=$2 + status=$3 + if test "$verbose" = "0" ; then + mod=`eval "expr \( $counter - 1 \) % 40"` + if test "$counter" != 1 -a "$mod" = 0 ; then + printf " %-3d\n" `eval "expr $counter - 1"` + echo -n " " + fi + if test "$status" = "0" ; then + echo -n "." + else + echo -n "!" + fi + else + if test "$status" = "0" ; then + printf "%3d) %-60s ... OK\n" "$counter" "$name" + else + printf "%3d) %-60s ... FAILED\n" "$counter" "$name" + fi + fi +} + +test_final() +{ + counter=$1 + status=$2 + + if test "$verbose" = "0" ; then + mod=`eval "expr \( $counter + 1 \) % 40"` + for i in `seq $mod 40` + do + echo -n " " + done + if test "$status" = "0" ; then + printf " %-3d OK\n" $counter + else + printf " %-3d FAILED\n" $counter + fi + fi +} + skip_test_() { echo "$0: skipping test: $@" 1>&2 @@ -137,6 +196,11 @@ test_dir_=$(pwd) this_test_() { echo "./$0" | sed 's,.*/,,'; } this_test=$(this_test_) +verbose=0 +if test -n "$VIR_TEST_DEBUG" -o -n "$VIR_TEST_VERBOSE" ; then + verbose=1 +fi + # This is a stub function that is run upon trap (upon regular exit and # interrupt). Override it with a per-test function, e.g., to unmount # a partition, or to undo any other global state changes. diff --git a/tests/test_conf.sh b/tests/test_conf.sh index 682f1f568..aa7abf6ca 100755 --- a/tests/test_conf.sh +++ b/tests/test_conf.sh @@ -1,35 +1,28 @@ #!/bin/sh test -z "$srcdir" && srcdir=$(pwd) -test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. -test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. -test -z "$abs_srcdir" && abs_srcdir=$(pwd) -test -z "$abs_builddir" && abs_builddir=$(pwd) - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi . "$srcdir/test-lib.sh" -set -e +test_intro $this_test fail=0 -i=1 +i=0 data_dir=$abs_srcdir/confdata for f in $(cd "$data_dir" && echo *.conf) do + i=`expr $i + 1` "$abs_builddir/conftest" "$data_dir/$f" > "$f-actual" expected="$data_dir"/`echo "$f" | sed s+\.conf$+\.out+` if compare "$expected" "$f-actual"; then - msg=OK + ret=0 else - msg=FAILED + ret=1 fail=1 fi - printf "%2d) %-60s ... %s\n" $i "$f" $msg - i=`expr $i + 1` + test_result $i "$f" $ret done +test_final $i $fail + (exit $fail); exit $fail diff --git a/tests/testutils.c b/tests/testutils.c index 25102ed90..f31099e6d 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -46,6 +46,7 @@ ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) static unsigned int testDebug = -1; +static unsigned int testVerbose = -1; static unsigned int testOOM = 0; static unsigned int testCounter = 0; @@ -62,6 +63,38 @@ virtTestCountAverage(double *items, int nitems) return (double) (sum / nitems); } + +void virtTestResult(const char *name, int ret, const char *msg, ...) +{ + va_list vargs; + va_start(vargs, msg); + + testCounter++; + if (virTestGetVerbose()) { + fprintf(stderr, "%3d) %-60s ", testCounter, name); + if (ret == 0) + fprintf(stderr, "OK\n"); + else { + fprintf(stderr, "FAILED\n"); + if (msg) { + vfprintf(stderr, msg, vargs); + } + } + } else { + if (testCounter != 1 && + !((testCounter-1) % 40)) { + fprintf(stderr, " %-3d\n", (testCounter-1)); + fprintf(stderr, " "); + } + if (ret == 0) + fprintf(stderr, "."); + else + fprintf(stderr, "!"); + } + + va_end(vargs); +} + /* * Runs test and count average time (if the nloops is grater than 1) * @@ -76,8 +109,8 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const testCounter++; if (testOOM < 2) { - fprintf(stderr, "%2d) %-65s ... ", testCounter, title); - fflush(stderr); + if (virTestGetVerbose()) + fprintf(stderr, "%2d) %-65s ... ", testCounter, title); } if (nloops > 1 && (ts = calloc(nloops, @@ -97,13 +130,25 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const } } if (testOOM < 2) { - if (ret == 0 && ts) - fprintf(stderr, "OK [%.5f ms]\n", - virtTestCountAverage(ts, nloops)); - else if (ret == 0) - fprintf(stderr, "OK\n"); - else - fprintf(stderr, "FAILED\n"); + if (virTestGetVerbose()) { + if (ret == 0 && ts) + fprintf(stderr, "OK [%.5f ms]\n", + virtTestCountAverage(ts, nloops)); + else if (ret == 0) + fprintf(stderr, "OK\n"); + else + fprintf(stderr, "FAILED\n"); + } else { + if (testCounter != 1 && + !((testCounter-1) % 40)) { + fprintf(stderr, " %-3d\n", (testCounter-1)); + fprintf(stderr, " "); + } + if (ret == 0) + fprintf(stderr, "."); + else + fprintf(stderr, "!"); + } } free(ts); @@ -255,10 +300,10 @@ int virtTestDifference(FILE *stream, const char *actualStart = actual; const char *actualEnd = actual + (strlen(actual)-1); - if (!virtTestGetDebug()) + if (!virTestGetDebug()) return 0; - if (virtTestGetDebug() < 2) { + if (virTestGetDebug() < 2) { /* Skip to first character where they differ */ while (*expectStart && *actualStart && *actualStart == *expectStart) { @@ -322,26 +367,34 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED) } #endif -unsigned int -virtTestGetDebug() { - char *debugStr; - unsigned int debug; - - if (testDebug != -1) - return testDebug; +static unsigned int +virTestGetFlag(const char *name) { + char *flagStr; + unsigned int flag; - testDebug = 0; - - if ((debugStr = getenv("VIR_TEST_DEBUG")) == NULL) + if ((flagStr = getenv(name)) == NULL) return 0; - if (virStrToLong_ui(debugStr, NULL, 10, &debug) < 0) + if (virStrToLong_ui(flagStr, NULL, 10, &flag) < 0) return 0; - testDebug = debug; + return flag; +} + +unsigned int +virTestGetDebug() { + if (testDebug == -1) + testDebug = virTestGetFlag("VIR_TEST_DEBUG"); return testDebug; } +unsigned int +virTestGetVerbose() { + if (testVerbose == -1) + testVerbose = virTestGetFlag("VIR_TEST_VERBOSE"); + return testVerbose || virTestGetDebug(); +} + int virtTestMain(int argc, char **argv, int (*func)(int, char **)) @@ -357,6 +410,10 @@ int virtTestMain(int argc, int worker = 0; #endif + fprintf(stderr, "TEST: %s\n", STRPREFIX(argv[0], "./") ? argv[0] + 2 : argv[0]); + if (!virTestGetVerbose()) + fprintf(stderr, " "); + if (virThreadInitialize() < 0 || virErrorInitialize() < 0 || virRandomInitialize(time(NULL) ^ getpid())) @@ -389,7 +446,7 @@ int virtTestMain(int argc, goto cleanup; #if TEST_OOM_TRACE - if (virtTestGetDebug()) + if (virTestGetDebug()) virAllocTestHook(virtTestErrorHook, NULL); #endif @@ -407,7 +464,7 @@ int virtTestMain(int argc, approxAlloc = virAllocTestCount(); testCounter++; - if (virtTestGetDebug()) + if (virTestGetDebug()) fprintf(stderr, "%d) OOM...\n", testCounter); else fprintf(stderr, "%d) OOM of %d allocs ", testCounter, approxAlloc); @@ -429,7 +486,7 @@ int virtTestMain(int argc, if (mp && (n % mp) != (worker - 1)) continue; - if (!virtTestGetDebug()) { + if (!virTestGetDebug()) { if (mp) fprintf(stderr, "%d", worker); else @@ -458,7 +515,7 @@ int virtTestMain(int argc, } } - if (virtTestGetDebug()) + if (virTestGetDebug()) fprintf(stderr, " ... OOM of %d allocs", approxAlloc); if (ret == EXIT_SUCCESS) @@ -472,6 +529,12 @@ cleanup: #endif virResetLastError(); + if (!virTestGetVerbose()) { + int i; + for (i = (testCounter % 40) ; i < 40 ; i++) + fprintf(stderr, " "); + fprintf(stderr, " %-3d %s\n", testCounter, ret == 0 ? "OK" : "FAIL"); + } return ret; } diff --git a/tests/testutils.h b/tests/testutils.h index e5d57504e..1f0374683 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -18,6 +18,7 @@ double virtTestCountAverage(double *items, int nitems); +void virtTestResult(const char *name, int ret, const char *msg, ...); int virtTestRun(const char *title, int nloops, int (*body)(const void *data), @@ -36,7 +37,8 @@ int virtTestDifference(FILE *stream, const char *expect, const char *actual); -unsigned int virtTestGetDebug(void); +unsigned int virTestGetDebug(void); +unsigned int virTestGetVerbose(void); int virtTestMain(int argc, char **argv, diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index eeeb5eca5..b07ab4882 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -132,7 +132,7 @@ virCapsPtr testQemuCapsInit(void) { NULL) == NULL) goto cleanup; - if (virtTestGetDebug()) { + if (virTestGetDebug()) { char *caps_str; caps_str = virCapabilitiesFormatXML(caps); diff --git a/tests/virsh-all b/tests/virsh-all index 81b3e5751..f1eb82cd7 100755 --- a/tests/virsh-all +++ b/tests/virsh-all @@ -17,13 +17,6 @@ # along with this program. If not, see . test -z "$srcdir" && srcdir=$(pwd) -test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. -test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. - -if test "$VERBOSE" = yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi . "$srcdir/test-lib.sh" @@ -35,10 +28,24 @@ $abs_top_builddir/tools/virsh -c $test_url help > cmds || framework_failure cmds=$(sed -n 's/^ \([^ ][^ ]*\) .*/\1/p' cmds) || framework_failure test -n "$cmds" || framework_failure +test_intro "virsh-all" + +counter=0 for i in $cmds; do - echo testing $i... 1>&2 - # For now, just run the command and ignore output and exit status. + counter=`eval "expr $counter + 1"` + + # For now, just run the command and ignore output $abs_top_builddir/tools/virsh -c $test_url $i < /dev/null > /dev/null 2>&1 + # Temporarily ignoring exit status + #status=$? + status=0 + test_result $counter $i $status + + if test "$status" = "1" ; then + fail=1 + fi done +test_final $counter $fail + (exit $fail); exit $fail -- cgit v1.2.3-65-gdbad