]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: make tests to run parallel
authorSami Kerola <kerolasa@iki.fi>
Sun, 16 Feb 2014 23:54:15 +0000 (23:54 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Feb 2014 14:01:02 +0000 (15:01 +0100)
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 <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
tests/functions.sh
tests/run.sh

index c802136e2fe46fb713962550ec7a958b94280b08..5e2292d9b82ac5fa76f7268ec1b90af6f7d0b8d5 100644 (file)
@@ -31,8 +31,17 @@ function ts_canonicalize {
        fi
 }
 
+function ts_report {
+       if [ "$TS_PARALLEL" == "yes" ]; then
+               echo "$TS_TITLE $1"
+       else
+               echo "$1"
+       fi
+
+}
+
 function ts_skip_subtest {
-       echo " IGNORE ($1)"
+       ts_report " IGNORE ($1)"
 }
 
 function ts_skip {
@@ -51,9 +60,9 @@ function ts_skip_nonroot {
 
 function ts_failed_subtest {
        if [ x"$1" == x"" ]; then
-               echo " FAILED ($TS_NS)"
+               ts_report " FAILED ($TS_NS)"
        else
-               echo " FAILED ($1)"
+               ts_report " FAILED ($1)"
        fi
 }
 
@@ -64,9 +73,9 @@ function ts_failed {
 
 function ts_ok_subtest {
        if [ x"$1" == x"" ]; then
-               echo " OK"
+               ts_report " OK"
        else
-               echo " OK ($1)"
+               ts_report " OK ($1)"
        fi
 }
 
@@ -162,6 +171,7 @@ function ts_init_env {
        ts_init_core_env
 
        TS_VERBOSE=$(ts_has_option "verbose" "$*")
+       TS_PARALLEL=$(ts_has_option "parallel" "$*")
 
        BLKID_FILE="$TS_OUTDIR/${TS_TESTNAME}.blkidtab"
 
@@ -209,7 +219,12 @@ function ts_init_subtest {
        [ $TS_NSUBTESTS -eq 0 ] && echo
        TS_NSUBTESTS=$(( $TS_NSUBTESTS + 1 ))
 
-       printf "%16s: %-27s ..." "" "$TS_SUBNAME"
+       if [ "$TS_PARALLEL" == "yes" ]; then
+               TS_TITLE=$(printf "%13s: %-30s ...\n%16s: %-27s ..." "$TS_COMPONENT" "$TS_DESC" "" "$TS_SUBNAME")
+       else
+               TS_TITLE=$(printf "%16s: %-27s ..." "" "$TS_SUBNAME")
+               echo -n "$TS_TITLE"
+       fi
 }
 
 function ts_init {
@@ -223,7 +238,12 @@ function ts_init {
 
        ts_init_env "$*"
 
-       printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC"
+       if [ "$TS_PARALLEL" == "yes" ]; then
+               TS_TITLE=$(printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC")
+       else
+               TS_TITLE=$(printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC")
+               echo -n "$TS_TITLE"
+       fi
 
        [ "$is_fake" == "yes" ] && ts_skip "fake mode"
        [ "$TS_OPTIONAL" == "yes" -a "$is_force" != "yes" ] && ts_skip "optional"
index 8a7924ae144d736db2852d4d48d419c8a000909d..a20da4785b33dc7b5ab0467e8904ec7ac8b9b778 100755 (executable)
@@ -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=<path>   autotools top source directory"
                echo "  --builddir=<path> autotools top build directory"
+               echo "  --parallel=<num>  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 "---------------------------------------------------------------------"