summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Kerola2014-02-17 00:54:15 +0100
committerKarel Zak2014-02-17 15:01:02 +0100
commit40e6f7a06355cba0305e987ca6536b212e0718cf (patch)
tree641cc4f0cafd1abb18d54be86389495111372fca
parenttests: fdisk now prints SGI system partitions too (diff)
downloadkernel-qcow2-util-linux-40e6f7a06355cba0305e987ca6536b212e0718cf.tar.gz
kernel-qcow2-util-linux-40e6f7a06355cba0305e987ca6536b212e0718cf.tar.xz
kernel-qcow2-util-linux-40e6f7a06355cba0305e987ca6536b212e0718cf.zip
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 <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--tests/functions.sh34
-rwxr-xr-xtests/run.sh41
2 files changed, 55 insertions, 20 deletions
diff --git a/tests/functions.sh b/tests/functions.sh
index c802136e2..5e2292d9b 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -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"
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=<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 "---------------------------------------------------------------------"