From 40e6f7a06355cba0305e987ca6536b212e0718cf Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 16 Feb 2014 23:54:15 +0000 Subject: tests: make tests to run parallel Unarguably this change makes test output to be more messy, but when I compare run time tells with clear numbers parallel is quicker. For me the quickness is important factor. Running test suite always after a change is preferrably quick, and if something is indicated to be broken it is ok to spend time in drilling down what happen. $ time ./tests/run.sh --parallel=5 [...] real 1m48.037s Same without parallelization. $ time ./tests/run.sh real 3m16.687s The default is changed to be parallel, where job count is same as number of CPUs. [kzak@redhat.com: - propagate --parallel into function.sh - don't use extra title for non-parallel execution - disable by default] Signed-off-by: Sami Kerola Signed-off-by: Karel Zak --- tests/run.sh | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'tests/run.sh') diff --git a/tests/run.sh b/tests/run.sh index 8a7924ae1..a20da4785 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -22,6 +22,7 @@ OPTS= top_srcdir= top_builddir= +paraller_jobs=1 while [ -n "$1" ]; do case "$1" in @@ -49,6 +50,14 @@ while [ -n "$1" ]; do --builddir=*) top_builddir="${1##--builddir=}" ;; + --parallel=*) + paraller_jobs="${1##--parallel=}" + OPTS="$OPTS --parallel" + ;; + --parallel) + paraller_jobs=$(lscpu -bp | grep -cv '^#') + OPTS="$OPTS --parallel" + ;; --*) echo "Unknown option $1" echo "Usage: " @@ -61,6 +70,7 @@ while [ -n "$1" ]; do echo " --nonroot ignore test suite if user is root" echo " --srcdir= autotools top source directory" echo " --builddir= autotools top build directory" + echo " --parallel= number of parallel test jobs, default: num cpus" echo exit 1 ;; @@ -87,12 +97,12 @@ fi OPTS="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir" +declare -a comps if [ -n "$SUBTESTS" ]; then # selected tests only for s in $SUBTESTS; do if [ -d "$top_srcdir/tests/ts/$s" ]; then - co=$(find $top_srcdir/tests/ts/$s -type f -perm /a+x -regex ".*/[^\.~]*" | sort) - comps="$comps $co" + comps+=( $(find $top_srcdir/tests/ts/$s -type f -perm /a+x -regex ".*/[^\.~]*") ) else echo "Unknown test component '$s'" exit 1 @@ -104,7 +114,7 @@ else exit 1 fi - comps=$(find $top_srcdir/tests/ts/ -type f -perm /a+x -regex ".*/[^\.~]*" | sort) + comps=( $(find $top_srcdir/tests/ts/ -type f -perm /a+x -regex ".*/[^\.~]*") ) fi @@ -119,21 +129,26 @@ echo " For development purpose only. " echo " Don't execute on production system! " echo -res=0 -count=0 -for ts in $comps; do - $ts "$OPTS" - res=$(( $res + $? )) - count=$(( $count + 1 )) -done +if [ $paraller_jobs -gt 1 ]; then + echo " Executing the tests in parallel ($paraller_jobs jobs) " + echo +fi +count=0 +>| $top_srcdir/tests/failures +printf "%s\n" ${comps[*]} | + xargs -I '{}' -P $paraller_jobs -n 1 bash -c "'{}' \"$OPTS\" || + echo 1 >> $top_srcdir/tests/failures" +declare -a fail_file +fail_file=( $( < $top_srcdir/tests/failures ) ) +rm -f $top_srcdir/tests/failures echo echo "---------------------------------------------------------------------" -if [ $res -eq 0 ]; then - echo " All $count tests PASSED" +if [ ${#fail_file[@]} -eq 0 ]; then + echo " All ${#comps[@]} tests PASSED" res=0 else - echo " $res tests of $count FAILED" + echo " ${#fail_file[@]} tests of ${#comps[@]} FAILED" res=1 fi echo "---------------------------------------------------------------------" -- cgit v1.2.3-55-g7522