run_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 | |-----------------+-----------| Suggested-by: Radim Krčmář <rkrcmar@xxxxxxxxxx> Signed-off-by: Peter Xu <peterx@xxxxxxxxxx> --- run_tests.sh | 12 ++++++++++-- scripts/functions.bash | 17 ++++++++++++++++- scripts/global.bash | 11 +++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index e1bb3a6..a4fc895 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -14,10 +14,11 @@ function usage() { cat <<EOF -Usage: $0 [-g group] [-h] [-v] +Usage: $0 [-g group] [-h] [-v] [-j N] -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 @@ -29,7 +30,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 @@ -38,6 +39,13 @@ while getopts "g:hv" opt; do usage exit ;; + j) + ut_run_queues=$OPTARG + if ! is_number "$ut_run_queues"; then + echo "Invalid -j option: $ut_run_queues" + exit 1 + fi + ;; v) verbose="yes" ;; diff --git a/scripts/functions.bash b/scripts/functions.bash index d1d2e1c..c6281f4 100644 --- a/scripts/functions.bash +++ b/scripts/functions.bash @@ -1,9 +1,18 @@ +source scripts/global.bash + function run_task() { local testname="$2" + while [[ "$(jobs | wc -l)" == $ut_run_queues ]]; do + # wait for any background test to finish + wait -n + done + RUNTIME_log_file="${ut_log_dir}/${testname}.log" - "$@" + + # start the testcase in the background + "$@" & } function for_each_unittest() @@ -20,6 +29,8 @@ function for_each_unittest() local accel local timeout + trap "wait; exit 130" SIGINT + exec {fd}<"$unittests" while read -u $fd line; do @@ -53,5 +64,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}<&- } diff --git a/scripts/global.bash b/scripts/global.bash index 77b0b29..52095bd 100644 --- a/scripts/global.bash +++ b/scripts/global.bash @@ -1,2 +1,13 @@ : ${ut_log_dir:=logs} : ${ut_log_summary:=${ut_log_dir}/SUMMARY} +: ${ut_run_queues:=1} + +function ut_in_parallel() +{ + [[ $ut_run_queues != 1 ]] +} + +function is_number() +{ + [[ "$1" =~ ^[0-9]+$ ]] +} -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html