summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2014-10-21 18:40:48 -0700
committerKent Overstreet <kmo@daterainc.com>2014-10-28 13:03:32 -0700
commit8a98e238ec39eeac1abe9b7c91a0074b5757e3bf (patch)
tree4f2b87ff32849f1ed1617e5dba5998348a5f8740
parentf971dd618a7ce6fdbd8aa630a3054e9860e5bc3e (diff)
testy: run tests in parallel
Change-Id: I0c8245acb408d68f4d9fee7252c20157d57fe123
-rwxr-xr-xtesty73
-rwxr-xr-xtesty.run-test21
2 files changed, 63 insertions, 31 deletions
diff --git a/testy b/testy
index 812e07c..ea2449d 100755
--- a/testy
+++ b/testy
@@ -19,6 +19,9 @@ KTESTARGS=""
WORKDIR=""
KEEP_GOING=0
+# hack
+( cd "$KTESTDIR/kmo-batch" && make kmo-batch )
+
read_tests()
{
# For every pattern/test in the test list, if $file matches the pattern
@@ -101,13 +104,13 @@ run_test()
case "$testfile" in
*.ktest)
- "$KTESTDIR/ktest" run $KTESTARGS "$testfile"
+ "$KTESTDIR/testy.run-test" "$KTESTDIR/ktest" run $KTESTARGS "$testfile"
;;
*.actest)
- $ACTEST -w "$WORKDIR" "$testfile"
+ "$KTESTDIR/testy.run-test" "$ACTEST" -w "$WORKDIR" "$testfile"
;;
*)
- "$testfile"
+ "$KTESTDIR/testy.run-test" "$testfile"
;;
esac
}
@@ -165,41 +168,49 @@ while getopts "hnfp:k:Ki:b:j:w:o:x" arg; do
done
shift $((OPTIND - 1))
-tests_failed=$(mktemp)
-tests_to_run=$(mktemp)
+ret=0
+tmpfile=$(mktemp)
# If get_tests fail we want the whole script to fail, so we can't call
# it from $(...) -- redirect output to a file then read the file later
# instead.
-get_tests "$@" > "$tests_to_run"
+get_tests "$@" > "$tmpfile"
+tests_to_run=$(sort -u "$tmpfile")
+
+rm "$tmpfile"
if [ "$DRYRUN" == 0 ]; then
- # shellcheck disable=SC2013
- for testfile in $(sort -u "$tests_to_run"); do
- testname=$(basename "$testfile")
- starttime=$(date +%s)
- failed=0
-
- run_test "$testfile" > "/tmp/$testname.log" 2>&1 || failed=1
-
- duration=$(($(date +%s) - starttime))
-
- if [ $failed = 1 ]; then
- # Note that we're on the right hand side of |, so we can't just
- # set a variable and test it at the end of the loop...
- echo "$testname" >> "$tests_failed"
- sed "s/^/[$testname] /" "/tmp/$testname.log"
- echo "[$testname] FAILURE: test finished at $(date +%s) -- $(date) after $duration seconds"
- [ $KEEP_GOING = 0 ] && break
- else
- echo "[$testname] SUCCESS: test finished at $(date +%s) -- $(date) after $duration seconds"
- fi
+ logdir=$(mktemp -d)
+
+ for testfile in $tests_to_run; do
+ testname=$(basename "$testfile")
+
+ run_test "$testfile" \
+ |& sed "s/^/[$testname] /" > "$logdir/$testname" &
+
+ sleep 2
done
+
+ wait
+
+ # shellcheck disable=SC2044
+ for testlog in $(find "$logdir" -type f); do
+ line=$(tail -n1 "$testlog")
+ case $line in
+ *SUCCESS:*)
+ echo "$line"
+ ;;
+ *)
+ ret=1
+ cat "$testlog"
+ [ $KEEP_GOING = 0 ] && break
+ ;;
+ esac
+ done
+
+ rm -rf "$logdir"
else
- sort -u "$tests_to_run"
+ echo "$tests_to_run"
fi
-rm "$tests_to_run"
-
-# Exit with failure if some tests failed
-test -z "$(cat "$tests_failed")"
+exit $ret
diff --git a/testy.run-test b/testy.run-test
new file mode 100755
index 0000000..b138c56
--- /dev/null
+++ b/testy.run-test
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# little wrapper to get correct start and end times
+
+set -o nounset
+set -o errexit
+set -o pipefail
+export PS4='+`basename ${BASH_SOURCE[0]}`:${LINENO}:${FUNCNAME[0]:+${FUNCNAME[0]}()}+ '
+
+KTESTDIR=$(dirname "$(readlink -f "$0")")
+
+starttime=$(date +%s)
+testfile=$1
+
+status="FAILURE"
+
+$KTESTDIR/kmo-batch/kmo-batch run $@ && status="SUCCESS"
+
+duration=$(($(date +%s) - starttime))
+
+echo "$status: test finished at $(date +%s) -- $(date) after $duration seconds"