run_tests: support concurrent test execution
v4 cover run_tests: support concurrent test execution
v4:
- add .gitignore for logs/ [Drew]
- instead of create globals.bash, renaming function.bash into common.bash, put globals inside [Drew]
- instead of removing logs/ directly when start run_tests, move it into logs.old so we at least have the last time result cached [Drew]
- s/ut_/unittest_/ through the whole series [Drew]
- remove unittest_log_summary var [Drew]
- remove radim's s-b in patch 2 since it does not suite [Drew]
- tiny fix on the usage lines [Drew]
- use bash arithmetic where proper [Drew]
- remove ut_in_parallel since not used [Drew]
v3:
- better handling for ctrl-c during run_tests.sh [Radim]
v2:
- patch 1: do per-test logging in all cases
- patch 2: throw away task.bash, instead, take Radim's suggestion to use jobs
run_tests.sh is getting slower. Maybe it's time to let it run faster. An obvious issue is that, we were running the tests sequentially in the past.
This series provides another new "-j" parameter. "-j 8" means we run the tests on 8 task queues. That'll fasten the script a lot. A very quick test of mine shows 3x speed boost with 8 task queues.
Please review, thanks.
Peter Xu (2):
run_tests: put logs into per-test file
run_tests: allow run tests in parallel
.gitignore | 3 ++-
Makefile | 4 ++--
run_tests.sh | 34 ++++++++++++++++++++++++---------
scripts/{functions.bash => common.bash} | 27 ++++++++++++++++++++++++--
scripts/mkstandalone.sh | 2 +-
5 files changed, 55 insertions(+), 15 deletions(-)
rename scripts/{functions.bash => common.bash} (63%)Signature · 1 line
2.7.4
PATCH v4 1/2 run_tests: put logs into per-test file
We were using test.log before to keep all the test logs. This patch creates one log file per test case under logs/ directory with name "TESTNAME.log". Meanwhile, we will keep the last time log into logs.old/.
Renaming scripts/functions.bash into scripts/common.bash to store some more global variables.
---
.gitignore | 3 ++-
Makefile | 4 ++--
run_tests.sh | 22 +++++++++++++++-------
scripts/{functions.bash => common.bash} | 13 +++++++++++--
scripts/mkstandalone.sh | 2 +-
5 files changed, 31 insertions(+), 13 deletions(-)
rename scripts/{functions.bash => common.bash} (75%).gitignore +2 -1
@@ -12,7 +12,8 @@ cscope.* /lib/asm /config.mak /*-run -/test.log /msr.out /tests /build-head +logs +logs.old
Makefile +2 -2
@@ -94,9 +94,9 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* \ + $(RM) lib/asm config.mak $(TEST_DIR)-run msr.out cscope.* \ build-head - $(RM) -r tests + $(RM) -r tests logs logs.old cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic cscope:
run_tests.sh +15 -7
@@ -7,7 +7,7 @@ if [ ! -f config.mak ]; then exit 1 fi source config.mak -source scripts/functions.bash +source scripts/common.bash function usage() {
@@ -46,17 +46,25 @@ while getopts "g:hv" opt; do esac done -RUNTIME_log_stderr () { cat >> test.log; } +# RUNTIME_log_file will be configured later +RUNTIME_log_stderr () { cat >> $RUNTIME_log_file; } RUNTIME_log_stdout () { if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then - ./scripts/pretty_print_stacks.py $1 >> test.log + ./scripts/pretty_print_stacks.py $1 >> $RUNTIME_log_file else - cat >> test.log + cat >> $RUNTIME_log_file fi } - config=$TEST_DIR/unittests.cfg -rm -f test.log -printf "BUILD_HEAD=$(cat build-head)\n\n" > test.log + +rm -rf $unittest_log_dir.old +if ! mv $unittest_log_dir $unittest_log_dir.log; then + echo "Failed to backup $unittest_log_dir" + exit 2 +fi + +mkdir $unittest_log_dir +echo "BUILD_HEAD=$(cat build-head)" > $unittest_log_dir/SUMMARY + for_each_unittest $config run
scripts/common.bash renamed from scripts/functions.bash +11 -2
@@ -1,3 +1,12 @@ +: ${unittest_log_dir:=logs} + +function run_task() +{ + local testname="$2" + + RUNTIME_log_file="${unittest_log_dir}/${testname}.log" + "$@" +} function for_each_unittest() {
@@ -17,7 +26,7 @@ function for_each_unittest() while read -u $fd line; do if [[ "$line" =~ ^\[(.*)\]$ ]]; then - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" testname=${BASH_REMATCH[1]} smp=1 kernel=""
@@ -45,6 +54,6 @@ function for_each_unittest() timeout=${BASH_REMATCH[1]} fi done - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" exec {fd}<&- }
scripts/mkstandalone.sh +1 -1
@@ -5,7 +5,7 @@ if [ ! -f config.mak ]; then exit 1 fi source config.mak -source scripts/functions.bash +source scripts/common.bash escape () {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 1/2] run_tests: put logs into per-test file
Quoted 23 lines · Peter Xu
We were using test.log before to keep all the test logs. This patch creates one log file per test case under logs/ directory with name "TESTNAME.log". Meanwhile, we will keep the last time log into logs.old/.
Renaming
scripts/functions.bashintoscripts/common.bashto store some more global variables.Signed-off-by Peter Xu <[email protected]>--- .gitignore | 3 ++- Makefile | 4 ++-- run_tests.sh | 22 +++++++++++++++------- scripts/{functions.bash => common.bash} | 13 +++++++++++-- scripts/mkstandalone.sh | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) rename scripts/{functions.bash => common.bash} (75%).gitignore +0
-0
.gitignore cscope.* · line 19
Quoted 9 lines
.gitignore +2
-1@@ -12,7 +12,8 @@ cscope.* /lib/asm /config.mak /*-run -/test.log /msr.out /tests /build-head +logs +logs.old
Without the leading '/' logs[.old] files or dirs in subdirs will also be ignored. You can add trailing '/' to all the dirs in .gitignore too in order to ensure we only ignore dirs.
Makefile libfdt_clean: · line 98
Quoted 11 lines
Makefile +1
-1@@ -94,9 +94,9 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d distclean: clean libfdt_clean - $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* \ + $(RM) lib/asm config.mak $(TEST_DIR)-run msr.out cscope.* \ build-head
Can move build-head up now
Quoted 32 lines
Makefile +1
-1- $(RM) -r tests + $(RM) -r tests logs logs.old cscope: cscope_dirs = lib lib/libfdt lib/linux $(TEST_DIR) $(ARCH_LIBDIRS) lib/asm-generic cscope:run_tests.sh +5
-4@@ -7,7 +7,7 @@ if [ ! -f config.mak ]; then exit 1 fi source config.mak -source scripts/functions.bash +source scripts/common.bash function usage() {@@ -46,17 +46,25 @@ while getopts "g:hv" opt; do esac done -RUNTIME_log_stderr () { cat >> test.log; } +# RUNTIME_log_file will be configured later +RUNTIME_log_stderr () { cat >> $RUNTIME_log_file; } RUNTIME_log_stdout () { if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then - ./scripts/pretty_print_stacks.py $1 >> test.log + ./scripts/pretty_print_stacks.py $1 >> $RUNTIME_log_file else - cat >> test.log + cat >> $RUNTIME_log_file
run_tests.sh while getopts "g:hv" opt; do · line 62
Quoted 10 lines
run_tests.sh +3
-3fi } - config=$TEST_DIR/unittests.cfg -rm -f test.log -printf "BUILD_HEAD=$(cat build-head)\n\n" > test.log + +rm -rf $unittest_log_dir.old +if ! mv $unittest_log_dir $unittest_log_dir.log; then
You remove the destination above, so this should never fail.
Quoted 62 lines
run_tests.sh +7
-0+ echo "Failed to backup $unittest_log_dir" + exit 2 +fi + +mkdir $unittest_log_dir +echo "BUILD_HEAD=$(cat build-head)" > $unittest_log_dir/SUMMARY + for_each_unittest $config runscripts/common.bash renamed from scripts/functions.bash +11
-2@@ -1,3 +1,12 @@ +: ${unittest_log_dir:=logs} + +function run_task() +{ + local testname="$2" + + RUNTIME_log_file="${unittest_log_dir}/${testname}.log" + "$@" +} function for_each_unittest() {@@ -17,7 +26,7 @@ function for_each_unittest() while read -u $fd line; do if [[ "$line" =~ ^\[(.*)\]$ ]]; then - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" testname=${BASH_REMATCH[1]} smp=1 kernel=""@@ -45,6 +54,6 @@ function for_each_unittest() timeout=${BASH_REMATCH[1]} fi done - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" exec {fd}<&- }scripts/mkstandalone.sh +1
-1@@ -5,7 +5,7 @@ if [ ! -f config.mak ]; then exit 1 fi source config.mak -source scripts/functions.bash +source scripts/common.bash escape () {Signature · 1 line
2.7.4
thanks,
drew
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 1/2] run_tests: put logs into per-test file
Quoted 29 lines · Andrew Jones
Quoted 28 lines · Peter Xu
We were using test.log before to keep all the test logs. This patch creates one log file per test case under logs/ directory with name "TESTNAME.log". Meanwhile, we will keep the last time log into logs.old/.
Renaming
scripts/functions.bashintoscripts/common.bashto store some more global variables.Signed-off-by Peter Xu <[email protected]>--- .gitignore | 3 ++- Makefile | 4 ++-- run_tests.sh | 22 +++++++++++++++------- scripts/{functions.bash => common.bash} | 13 +++++++++++-- scripts/mkstandalone.sh | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) rename scripts/{functions.bash => common.bash} (75%).gitignore +0
-1@@ -12,7 +12,8 @@ cscope.* /lib/asm /config.mak /*-run -/test.log /msr.out
Quoted 8 lines
.gitignore cscope.* · line 19
Quoted 4 lines
.gitignore +2
-0/tests /build-head +logs +logs.oldWithout the leading '/' logs[.old] files or dirs in subdirs will also be ignored. You can add trailing '/' to all the dirs in .gitignore too in order to ensure we only ignore dirs.
Will do.
Quoted 8 lines
Quoted 8 lines
Makefile +0
-0@@ -94,9 +94,9 @@ libfdt_clean: $(LIBFDT_objdir)/.*.d
Quoted 6 lines
Makefile libfdt_clean: · line 98
Quoted 4 lines
Makefile +1
-1distclean: clean libfdt_clean - $(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.* \ + $(RM) lib/asm config.mak $(TEST_DIR)-run msr.out cscope.* \ build-headCan move build-head up now
Yep.
[...]
Quoted 9 lines
Makefile libfdt_clean: · line 102
Quoted 7 lines
Makefile +3
-3- config=$TEST_DIR/unittests.cfg -rm -f test.log -printf "BUILD_HEAD=$(cat build-head)\n\n" > test.log + +rm -rf $unittest_log_dir.old +if ! mv $unittest_log_dir $unittest_log_dir.log; thenYou remove the destination above, so this should never fail.
Hmm looks so... :) Let me fix.
(And I used rm -rf again, but with ".old" it looks much safer so I
dare to use it)
Thanks,
-- peterx
PATCH v4 2/2 run_tests: allow run tests in parallel
In reply to Peter Xurun_task.sh is getting slow. This patch is trying to make it faster by running the tests concurrently.
We provide a new parameter "-j" for the run_tests.sh, which can be used to specify how many run queues we want for the tests. Default queue length is 1, which is the old behavior.
Quick test on my laptop (4 cores, 2 threads each) shows 3x speed boost:
|-----------------+-----------| | command | time used | |-----------------+-----------| | run_test.sh | 75s | | run_test.sh -j8 | 27s | |-----------------+-----------|
--- run_tests.sh | 12 ++++++++++-- scripts/common.bash | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-)
run_tests.sh +10 -2
@@ -13,10 +13,11 @@ function usage() { cat <<EOF -Usage: $0 [-g group] [-h] [-v] +Usage: $0 [-g group] [-h] [-v] [-j num_run_queues] -g: Only execute tests in the given group -h: Output this help text + -j: Execute tests in parallel -v: Enables verbose mode Set the environment variable QEMU=/path/to/qemu-system-ARCH to
@@ -28,7 +29,7 @@ EOF RUNTIME_arch_run="./$TEST_DIR/run" source scripts/runtime.bash -while getopts "g:hv" opt; do +while getopts "g:hj:v" opt; do case $opt in g) only_group=$OPTARG
@@ -37,6 +38,13 @@ while getopts "g:hv" opt; do usage exit ;; + j) + unittest_run_queues=$OPTARG + if ! (( "$unittest_run_queues" > 0 )); then + echo "Invalid -j option: $unittest_run_queues" + exit 1 + fi + ;; v) verbose="yes" ;;
scripts/common.bash +15 -1
@@ -1,11 +1,19 @@ : ${unittest_log_dir:=logs} +: ${unittest_run_queues:=1} function run_task() { local testname="$2" + while (( "$(jobs | wc -l)" == $unittest_run_queues )); do + # wait for any background test to finish + wait -n + done + RUNTIME_log_file="${unittest_log_dir}/${testname}.log" - "$@" + + # start the testcase in the background + "$@" & } function for_each_unittest()
@@ -22,6 +30,8 @@ function for_each_unittest() local accel local timeout + trap "wait; exit 130" SIGINT + exec {fd}<"$unittests" while read -u $fd line; do
@@ -55,5 +65,9 @@ function for_each_unittest() fi done run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + + # wait all task finish + wait + exec {fd}<&- }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 2/2] run_tests: allow run tests in parallel
Quoted 49 lines · Peter Xu
run_task.shis getting slow. This patch is trying to make it faster by running the tests concurrently.We provide a new parameter "-j" for the
run_tests.sh, which can be used to specify how many run queues we want for the tests. Default queue length is 1, which is the old behavior.Quick test on my laptop (4 cores, 2 threads each) shows 3x speed boost:
|-----------------+-----------| | command | time used | |-----------------+-----------| | run_test.sh | 75s | | run_test.sh -j8 | 27s | |-----------------+-----------|Signed-off-by Peter Xu <[email protected]>--- run_tests.sh | 12 ++++++++++-- scripts/common.bash | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-)run_tests.sh +3
-2@@ -13,10 +13,11 @@ function usage() { cat <<EOF -Usage: $0 [-g group] [-h] [-v] +Usage: $0 [-g group] [-h] [-v] [-j num_run_queues] -g: Only execute tests in the given group -h: Output this help text + -j: Execute tests in parallel -v: Enables verbose mode Set the environment variable QEMU=/path/to/qemu-system-ARCH to@@ -28,7 +29,7 @@ EOF RUNTIME_arch_run="./$TEST_DIR/run" source scripts/runtime.bash -while getopts "g:hv" opt; do +while getopts "g:hj:v" opt; do case $opt in g) only_group=$OPTARG
run_tests.sh while getopts "g:hv" opt; do · line 43
Quoted 6 lines
run_tests.sh +3
-0@@ -37,6 +38,13 @@ while getopts "g:hv" opt; do usage exit ;; + j) + unittest_run_queues=$OPTARG + if ! (( "$unittest_run_queues" > 0 )); then
The equivalent expression without '!' is (( $var <= 0 )), and no need for the "'s around the var.
Quoted 12 lines
run_tests.sh +4
-0+ echo "Invalid -j option: $unittest_run_queues" + exit 1 + fi + ;; v) verbose="yes" ;;scripts/common.bash +0
-0
scripts/common.bash line 8
Quoted 8 lines
scripts/common.bash +2
-0@@ -1,11 +1,19 @@ : ${unittest_log_dir:=logs} +: ${unittest_run_queues:=1} function run_task() { local testname="$2" + while (( "$(jobs | wc -l)" == $unittest_run_queues )); do
Why the "'s? The result must resolve to an int, otherwise we don't want ((...))
Quoted 22 lines
scripts/common.bash +9
-1+ # wait for any background test to finish + wait -n + done + RUNTIME_log_file="${unittest_log_dir}/${testname}.log" - "$@" + + # start the testcase in the background + "$@" & } function for_each_unittest()@@ -22,6 +30,8 @@ function for_each_unittest() local accel local timeout + trap "wait; exit 130" SIGINT + exec {fd}<"$unittests" while read -u $fd line; do
scripts/common.bash function for_each_unittest() · line 69
Quoted 5 lines
scripts/common.bash +2
-0@@ -55,5 +65,9 @@ function for_each_unittest() fi done run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + + # wait all task finish
wait until all tasks finish
Quoted 8 lines
scripts/common.bash +2
-0+ wait + exec {fd}<&- }Signature · 1 line
2.7.4
Re: [Qemu-devel] [kvm-unit-tests PATCH v4 2/2] run_tests: allow run tests in parallel
Quoted 104 lines · Andrew Jones
Quoted 49 lines · Peter Xu
run_task.shis getting slow. This patch is trying to make it faster by running the tests concurrently.We provide a new parameter "-j" for the
run_tests.sh, which can be used to specify how many run queues we want for the tests. Default queue length is 1, which is the old behavior.Quick test on my laptop (4 cores, 2 threads each) shows 3x speed boost:
|-----------------+-----------| | command | time used | |-----------------+-----------| | run_test.sh | 75s | | run_test.sh -j8 | 27s | |-----------------+-----------|Signed-off-by Peter Xu <[email protected]>--- run_tests.sh | 12 ++++++++++-- scripts/common.bash | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-)run_tests.sh +3
-2@@ -13,10 +13,11 @@ function usage() { cat <<EOF -Usage: $0 [-g group] [-h] [-v] +Usage: $0 [-g group] [-h] [-v] [-j num_run_queues] -g: Only execute tests in the given group -h: Output this help text + -j: Execute tests in parallel -v: Enables verbose mode Set the environment variable QEMU=/path/to/qemu-system-ARCH to@@ -28,7 +29,7 @@ EOF RUNTIME_arch_run="./$TEST_DIR/run" source scripts/runtime.bash -while getopts "g:hv" opt; do +while getopts "g:hj:v" opt; do case $opt in g) only_group=$OPTARGrun_tests.sh while getopts "g:hv" opt; do · line 43
Quoted 6 lines
run_tests.sh +3
-0@@ -37,6 +38,13 @@ while getopts "g:hv" opt; do usage exit ;; + j) + unittest_run_queues=$OPTARG + if ! (( "$unittest_run_queues" > 0 )); thenThe equivalent expression without '!' is (( $var <= 0 )), and no need for the "'s around the var.
Quoted 12 lines
run_tests.sh +4
-0+ echo "Invalid -j option: $unittest_run_queues" + exit 1 + fi + ;; v) verbose="yes" ;;scripts/common.bash +0
-0scripts/common.bash line 8
Quoted 8 lines
scripts/common.bash +2
-0@@ -1,11 +1,19 @@ : ${unittest_log_dir:=logs} +: ${unittest_run_queues:=1} function run_task() { local testname="$2" + while (( "$(jobs | wc -l)" == $unittest_run_queues )); doWhy the "'s? The result must resolve to an int, otherwise we don't want ((...))
Quoted 20 lines
scripts/common.bash +9
-1+ # wait for any background test to finish + wait -n + done + RUNTIME_log_file="${unittest_log_dir}/${testname}.log" - "$@" + + # start the testcase in the background + "$@" & } function for_each_unittest()@@ -22,6 +30,8 @@ function for_each_unittest() local accel local timeout + trap "wait; exit 130" SIGINT + exec {fd}<"$unittests"
Quoted 9 lines
scripts/common.bash function for_each_unittest() · line 69
Quoted 7 lines
scripts/common.bash +2
-0while read -u $fd line; do@@ -55,5 +65,9 @@ function for_each_unittest() fi done run_task "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + + # wait all task finishwait until all tasks finish
Fixing all three places, thanks!
-- peterx