public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 2/9] tests: make tests to run parallel
Date: Sun, 16 Feb 2014 23:54:15 +0000	[thread overview]
Message-ID: <1392594862-15807-2-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1392594862-15807-1-git-send-email-kerolasa@iki.fi>

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.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 tests/functions.sh | 15 +++++++--------
 tests/run.sh       | 32 +++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/tests/functions.sh b/tests/functions.sh
index 17fa6d2..f6f2a5c 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -38,7 +38,7 @@ function ts_check_test_command {
 }
 
 function ts_skip_subtest {
-	echo " IGNORE ($1)"
+	echo "$TITLE IGNORE ($1)"
 }
 
 function ts_skip {
@@ -57,9 +57,9 @@ function ts_skip_nonroot {
 
 function ts_failed_subtest {
 	if [ x"$1" == x"" ]; then
-		echo " FAILED ($TS_NS)"
+		echo "$TITLE FAILED ($TS_NS)"
 	else
-		echo " FAILED ($1)"
+		echo "$TITLE FAILED ($1)"
 	fi
 }
 
@@ -70,9 +70,9 @@ function ts_failed {
 
 function ts_ok_subtest {
 	if [ x"$1" == x"" ]; then
-		echo " OK"
+		echo "$TITLE OK"
 	else
-		echo " OK ($1)"
+		echo "$TITLE OK ($1)"
 	fi
 }
 
@@ -214,8 +214,7 @@ function ts_init_subtest {
 
 	[ $TS_NSUBTESTS -eq 0 ] && echo
 	TS_NSUBTESTS=$(( $TS_NSUBTESTS + 1 ))
-
-	printf "%16s: %-27s ..." "" "$TS_SUBNAME"
+	TITLE=$(printf "%13s: %-30s ...\n%16s: %-27s ..." "$TS_COMPONENT" "$TS_DESC" "" "$TS_SUBNAME")
 }
 
 function ts_init {
@@ -229,7 +228,7 @@ function ts_init {
 
 	ts_init_env "$*"
 
-	printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC"
+	TITLE=$(printf "%13s: %-30s ..." "$TS_COMPONENT" "$TS_DESC")
 
 	[ "$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 8a7924a..4f55295 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -23,6 +23,8 @@ OPTS=
 top_srcdir=
 top_builddir=
 
+paraller_jobs=$(lscpu -bp | grep -cv '^#')
+
 while [ -n "$1" ]; do
 	case "$1" in
 	--force)
@@ -49,6 +51,9 @@ while [ -n "$1" ]; do
 	--builddir=*)
 		top_builddir="${1##--builddir=}"
 		;;
+	--parallel=*)
+		paraller_jobs="${1##--parallel=}"
+		;;
 	--*)
 		echo "Unknown option $1"
 		echo "Usage: "
@@ -61,6 +66,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 +93,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 +110,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 +125,21 @@ 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
-
+>| $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 "---------------------------------------------------------------------"
-- 
1.9.0


  reply	other threads:[~2014-02-16 23:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-16 23:54 [PATCH 1/9] tests: avoid executing dirname(1) command Sami Kerola
2014-02-16 23:54 ` Sami Kerola [this message]
2014-02-17 14:11   ` [PATCH 2/9] tests: make tests to run parallel Karel Zak
2014-02-16 23:54 ` [PATCH 3/9] tools: add usage information to checkconfig.sh Sami Kerola
2014-02-16 23:54 ` [PATCH 4/9] docs: make hexdump.1 color specification easier to understand Sami Kerola
2014-02-16 23:54 ` [PATCH 5/9] tests: align last.1 with recent phantom detection Sami Kerola
2014-02-16 23:54 ` [PATCH 6/9] swaplabel: wrong version number in check Sami Kerola
2014-02-16 23:54 ` [PATCH 7/9] isosize: move file name printing after error determination Sami Kerola
2014-02-16 23:54 ` [PATCH 8/9] tests: add isosize --sectors and --divisor tests Sami Kerola
2014-02-16 23:54 ` [PATCH 9/9] isosize: make --divisor to require argument Sami Kerola

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392594862-15807-2-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox