]> granicus.if.org Git - re2c/commitdiff
Run tests in parallel with "-j<threads>" option.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 26 Mar 2015 16:37:25 +0000 (16:37 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 26 Mar 2015 16:37:25 +0000 (16:37 +0000)
re2c/run_tests.sh.in

index 9b6ad50cce2488a6123be1f1223d979257b4432a..545b93d21a7e0c58be6eb6bcf13ee4d88b4ead15 100644 (file)
 #!/bin/bash
-_XPG=1
-result=0
-errcnt=0
-tstcnt=0;
-if test "$1" == "--valgrind"; then
-valgrind=`which valgrind`
-shift
-else
-valgrind=
+
+valgrind=""
+threads=1
+tests=()
+for arg in $*
+do
+       case $arg in
+               "--valgrind" ) valgrind=`which valgrind` ;;
+               "-j"* )
+                       number=${arg#-j}
+                       number_pattern='^[0-9]+$'
+                       if [[ $number =~ $number_pattern ]]
+                       then
+                               threads=$number
+                       fi
+                       ;;
+               * ) tests+=("$arg") ;;
+       esac
+done
+
+if [ ${#tests[@]} -eq 0 ]
+then
+       tests=(`for i in test lessons; do find @top_srcdir@/$i -name '*.re'; done | sort`)
 fi
-diff -u $0 $0 >/dev/null 2>&1 && diff='diff -u' || diff='diff'
-#diff="${diff} -I '#line [0-9]*'"
-if uname|grep -q -i 'CYGWIN' && test -x "@WINBUILDDIR@/re2c.exe"; then
-re2c='@WINBUILDDIR@/re2c.exe'
-else
+tests_per_thread=$((${#tests[@]} / threads + 1))
+packs=()
+for ((i = 0; i < threads; i++))
+do
+       j=$((i * tests_per_thread))
+       packs[$i]=${tests[@]:j:tests_per_thread}
+done
+
 re2c='@builddir@/re2c'
+if test ! -x "${re2c}"
+then
+       echo "Cannot find re2c executable (${re2c})."
+       exit 1
 fi
-if test ! -x "${re2c}"; then
-  echo "Cannot find re2c executable (${re2c})."
-fi
-if test -n "${valgrind}"; then
-  valgrind_options="-q --track-origins=yes --num-callers=50 --leak-check=full --show-reachable=yes --malloc-fill=0xa1 --free-fill=0xa1 "
-  valgrind="${valgrind} ${valgrind_options} "
-  echo "Using valgrind"
+
+if test -n "${valgrind}"
+then
+       valgrind_options=(
+               "-q"
+               "--track-origins=yes"
+               "--num-callers=50"
+               "--leak-check=full"
+               "--show-reachable=yes"
+               "--malloc-fill=0xa1"
+               "--free-fill=0xa1"
+               )
+       valgrind="${valgrind} ${valgrind_options[@]} "
+       echo $valgrind
 fi
 re2c="${valgrind}${re2c}"
-echo "Testing: ${re2c}"
-if ${re2c} -v|grep -q 're2c @PACKAGE_VERSION@ *\r*'; then
-echo "Version: @PACKAGE_VERSION@"
-else
-echo "Warning: test build for @PACKAGE_VERSION@ but testing `${re2c} -v`"
-fi
-echo "Diffing: ${diff}"
-if test $# = 0; then
-tests=`for i in test lessons; do find @top_srcdir@/$i -name '*.re'; done|sort`
-else
-tests="$@"
-fi;
-for x in $tests; do
-       tstcnt=$(($tstcnt+1))
-       switches=`basename $x|sed -e 's/^[^.]*\.\(.*\)\.re$/-\1/g' -e 's/^[^-].*//g' -e 's/\([^ ]\)--/\1 --/g' -e 's/(\([^)]*\))/ \1/g' -e 's/- //g'`
-       genname=`printf "%s" "$switches"|sed -e 's,--.*$,,g' -e 's,^.[^o]*$,,g' -e 's,^[^ot]*t.*o.*$,,g' -e 's,^-[^o]*o\(.*\),@builddir@/test/\1,g'`
-       headers=`printf "%s" "$switches"|sed -e 's,--.*$,,g' -e 's,^.[^t]*$,,g' -e 's,^[^ot]*o.*t.*$,,g' -e 's,^-[^t]*t\(.*\),@builddir@/test/\1,g'`
-       switches=`printf "%s" "$switches"|sed -e 's,^-\([^ot-]*[ot]\)\(.*\)$,-\1@builddir@/test/\2,g'`
-       # don't use the -o flag, since it makes it harder to diff.
-       echo $x: $switches
-       outname=@builddir@/test/`basename ${x%.re}.c.temp`
-       outdiff=@builddir@/test/`basename ${x%.re}.c.diff`
-       typname=@builddir@/test/`basename ${x%.re}.h.temp`
-       typdiff=@builddir@/test/`basename ${x%.re}.h.diff`
-       $re2c $switches $x 2>&1 | LC_ALL=C sed -e "s,$x,`basename $x`,g" -e "s,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g" > $outname
-       if test -n "$genname"; then
-               cat $genname | sed -e 's,@builddir@/test/,,g' -e "s,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g" > $outname
-               rm $genname
-       fi
-       ok=1
-       if test -n "$headers"; then
-               cat $headers | sed -e 's,@builddir@/test/,,g' -e "s,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g" > $typname
-               rm $headers
-               if test ! -f ${x%.re}.h; then
-                       echo "Missing: ${x%.re}.h"
-                       result=1
-                       errcnt=$(($errcnt+1))
-               elif ${diff} ${x%.re}.h $typname > $typdiff; then
-                       echo "Passed header test."
-                       rm $typname
+
+run_pack ()
+{
+       local log="$1"
+       shift 1
+
+       local errcnt=0
+       for x in $*
+       do
+               local switches=`basename $x | sed -e 's/^[^.]*\.\(.*\)\.re$/-\1/g' -e 's/^[^-].*//g' -e 's/\([^ ]\)--/\1 --/g' -e 's/(\([^)]*\))/ \1/g' -e 's/- //g'`
+               local genname=` printf "%s" "$switches" | sed -e 's,--.*$,,g' -e 's,^.[^o]*$,,g' -e 's,^[^ot]*t.*o.*$,,g' -e 's,^-[^o]*o\(.*\),@builddir@/test/\1,g'`
+               local headers=` printf "%s" "$switches" | sed -e 's,--.*$,,g' -e 's,^.[^t]*$,,g' -e 's,^[^ot]*o.*t.*$,,g' -e 's,^-[^t]*t\(.*\),@builddir@/test/\1,g'`
+               local switches=`printf "%s" "$switches" | sed -e 's,^-\([^ot-]*[ot]\)\(.*\)$,-\1@builddir@/test/\2,g'`
+               # don't use the -o flag, since it makes it harder to diff.
+               local outname=@builddir@/test/`basename ${x%.re}.c.temp`
+               local outdiff=@builddir@/test/`basename ${x%.re}.c.diff`
+               local typname=@builddir@/test/`basename ${x%.re}.h.temp`
+               local typdiff=@builddir@/test/`basename ${x%.re}.h.diff`
+
+               $re2c $switches $x 2>&1 | LC_ALL=C sed -e "s,$x,`basename $x`,g" -e "s,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g" > $outname
+               if test -n "$genname"
+               then
+                       cat $genname | sed -e 's,@builddir@/test/,,g' -e "s,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g" > $outname
+                       rm $genname
+               fi
+
+               if test ! -f ${x%.re}.c
+               then
+                       echo "FAIL missing ${x%.re}.c"
+                       local errcnt=$(($errcnt + 1))
                else
-                       echo "Failed: ${x%.re}.h ${x%.re}.h.temp differ."
-                       result=1
-                       errcnt=$(($errcnt+1))
-                       ok=0
+                       local r=`diff ${x%.re}.c $outname > $outdiff; echo $?`
+                       if [[ $r == 0 ]]
+                       then
+                               echo "OK $x: $switches"
+                               rm $outname
+                       else
+                               echo "FAIL $x: $switches"
+                               local errcnt=$(($errcnt + 1))
+                       fi
                fi
-       fi
-       if test ! -f ${x%.re}.c; then
-               echo "Missing: ${x%.re}.c"
-               result=1
-               errcnt=$(($errcnt+1))
-       elif ${diff} ${x%.re}.c $outname > $outdiff; then
-               if test $ok = 1; then
-                       echo "Passed."
+
+               if test -n "$headers"
+               then
+                       cat $headers | sed -e 's,@builddir@/test/,,g' -e "s,/\* Generated by re2c .*\*/,/\* Generated by re2c \*/,g" > $typname
+                       rm $headers
+                       if test ! -f ${x%.re}.h
+                       then
+                               echo "FAIL missing ${x%.re}.h"
+                               local errcnt=$(($errcnt + 1))
+                       elif diff ${x%.re}.h $typname > $typdiff
+                       then
+                               echo "OK $x: $switches"
+                               rm $typname
+                       else
+                               echo "FAIL $x: $switches"
+                               local errcnt=$(($errcnt + 1))
+                       fi
                fi
-               rm $outname
-       else
-               echo "Failed: ${x%.re}.c ${x%.re}.c.temp differ."
-               result=1
-               errcnt=$(($errcnt+1))
-       fi
-       test -f $outdiff -a ! -s $outdiff && rm -f $outdiff
-       test -f $typdiff -a ! -s $typdiff && rm -f $typdiff
+               test -f $outdiff -a ! -s $outdiff && rm -f $outdiff
+               test -f $typdiff -a ! -s $typdiff && rm -f $typdiff
+       done
+       echo $errcnt > $log
+}
+
+logs=()
+for ((i = 0; i < ${#packs[@]}; i++))
+do
+       logs[$i]=`date +%y%m%d%H%M%S`_$i
+       run_pack ${logs[i]} ${packs[i]} &
+       wait_pids="$wait_pids %$((i + 1))"
+done
+wait $wait_pids
+
+errors=0
+for ((i = 0; i < ${#logs[@]}; i++))
+do
+       error=`cat ${logs[i]}`
+       errors=$((errors + error))
+       rm ${logs[i]}
 done
-if test $result = 0; then
-       echo "All $tstcnt tests passed successfully."
+
+
+if [ $errors -eq 0 ]
+then
+       echo "All ${#tests[@]} tests passed successfully."
+       exit 0
 else
-       echo "Error: $errcnt out $tstcnt tests failed."
+       echo "Error: $errors out ${#tests[@]} tests failed."
+       exit 1
 fi
-exit $result