some bug fixes and enhancements to tester

This commit is contained in:
Remzi Arpaci-Dusseau
2019-02-16 08:06:40 -05:00
parent 6cb2958151
commit 396a3565cf

View File

@@ -2,46 +2,81 @@
# run_test testnumber # run_test testnumber
run_test () { run_test () {
testfile=tests/$1.run local testnum=$1
eval $(cat $testfile) > tests-out/$1.out 2> tests-out/$1.err local testfile=tests/$testnum.run
return 0 eval $(cat $testfile) > tests-out/$testnum.out 2> tests-out/$testnum.err
} }
# check_test testnumber out/err print_error_message () {
check_test () { local testnum=$1
outdiff=$(diff tests/$1.$2 tests-out/$1.$2) local contrunning=$2
outerr=$? local filetype=$3
if (( $outerr != 0 )); then builtin echo -e "\e[31mtest $testnum: standard $filetype incorrect\e[0m"
builtin echo -e "\e[31mtest $testnum: standard $2 incorrect\e[0m" echo " what results should be found in file: tests/$testnum.$filetype"
echo "should be:" echo " what results produced by your program: tests-out/$testnum.$filetype"
cat tests/$1.$2 echo " compare the two using diff, cmp, or related tools to debug"
echo "is:" if (( $contrunning == 0 )); then
cat tests-out/$1.$2
exit 1 exit 1
fi fi
return 0
} }
# run_and_check testnumber printerror # check_test testnumber contrunning out/err
check_test () {
local testnum=$1
local contrunning=$2
local filetype=$3
# option to use cmp instead?
returnval=$(diff tests/$testnum.$filetype tests-out/$testnum.$filetype)
if (( $? != 0 )); then
echo -n 1
else
echo -n 0
fi
}
# run_and_check testnumber contrunning verbose printerror
# testnumber: the test to run and check # testnumber: the test to run and check
# printerrer: if 1, print an error if test does not exist # printerrer: if 1, print an error if test does not exist
run_and_check () { run_and_check () {
if [[ ! -f tests/$1.run ]]; then local testnum=$1
if (( $2 == 1 )); then local contrunning=$2
echo "test $1 does not exist" >&2; exit 1 local verbose=$3
local failmode=$4
if [[ ! -f tests/$testnum.run ]]; then
if (( $failmode == 1 )); then
echo "test $testnum does not exist" >&2; exit 1
fi fi
exit 0 exit 0
fi fi
run_test $1 if (( $verbose == 1 )); then
check_test $1 out echo "running test $testnum"
check_test $1 err cat tests/$testnum.desc
builtin echo -e "\e[32mtest $1: passed\e[0m" fi
return 0 run_test $testnum
outcheck=$(check_test $testnum $contrunning out)
errcheck=$(check_test $testnum $contrunning err)
# echo "results: outcheck:$outcheck errcheck:$errcheck"
if (( $outcheck == 0 )) && (( $errcheck == 0 )); then
builtin echo -e "\e[32mtest $testnum: passed\e[0m"
else
if (( $outcheck == 1 )); then
print_error_message $testnum $contrunning out
fi
if (( $errcheck == 1 )); then
print_error_message $testnum $contrunning err
fi
fi
} }
# usage: call when args not parsed, or when help needed # usage: call when args not parsed, or when help needed
usage () { usage () {
echo "usage: run-tests.sh [-h] [-v] [-t test]" echo "usage: run-tests.sh [-h] [-v] [-t test]"
echo " -h help message"
echo " -v verbose"
echo " -t n run only test n"
echo " -c continue even after failure"
return 0 return 0
} }
@@ -49,9 +84,10 @@ usage () {
# main program # main program
# #
verbose=0 verbose=0
contrunning=0
specific="" specific=""
args=`getopt hvt: $*` args=`getopt hvct: $*`
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
usage; exit 1 usage; exit 1
fi fi
@@ -66,6 +102,9 @@ for i; do
-v) -v)
verbose=1 verbose=1
shift;; shift;;
-c)
contrunning=1
shift;;
-t) -t)
specific=$2 specific=$2
shift shift
@@ -87,14 +126,14 @@ fi
# run just one test # run just one test
if [[ $specific != "" ]]; then if [[ $specific != "" ]]; then
run_and_check $specific 1 run_and_check $specific $contrunning $verbose 1
exit 0 exit 0
fi fi
# run all tests # run all tests
(( testnum = 1 )) (( testnum = 1 ))
while true; do while true; do
run_and_check $testnum 0 run_and_check $testnum $contrunning $verbose 0
(( testnum = $testnum + 1 )) (( testnum = $testnum + 1 ))
done done