From: Denis Ovsienko Date: Mon, 20 Jan 2014 11:26:06 +0000 (+0400) Subject: test scripts overhaul X-Git-Tag: tcpdump-4.6.0~250 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/3cf6fb361f82b8c9a04684d65b7cba19f31fdbf3 test scripts overhaul Rewrite TESTonce to do only one thing (run a test with given parameters) but do it well. Split TESTrun.sh into functions and extend it to do only a specific test if requested. Justify format of the test results and move most of the test results printing from TESTrun.sh to TESTonce. --- diff --git a/tests/TESTonce b/tests/TESTonce index c5bcb34b..3a9195ad 100755 --- a/tests/TESTonce +++ b/tests/TESTonce @@ -1,39 +1,37 @@ #!/usr/bin/perl -$debug = 0; system("mkdir -p NEW DIFF"); -if(@ARGV == 1) { - open(TESTLIST, "TESTLIST") || die "can not open TESTLIST: $!\n"; - $wanted = $ARGV[0]; - #print "Searching for test case $wanted\n"; - while() { - #print "Processing $_\n"; - next unless (/^$wanted/); +if(@ARGV != 4) { + print "Usage: TESTonce name input output options\n"; + exit 20; +} - chop; - ($name,$input,$output,$options)=split(/\s+/,$_, 4); - last; - } - close(TESTLIST); +$name=$ARGV[0]; +$input=$ARGV[1]; +$output=$ARGV[2]; +$options=$ARGV[3]; - die "Can not find test $wanted\n" unless defined($input); +$r = system "../tcpdump 2>/dev/null -n -r $input $options | tee NEW/$output | diff -uw $output - >DIFF/$output.diff"; -} elsif(@ARGV == 4) { - $name=$ARGV[0]; - $input=$ARGV[1]; - $output=$ARGV[2]; - $options=$ARGV[3]; -} else { - print "Usage: TESTonce name [input output options]\n"; - exit 20; +if($r == 0) { + printf "%-30s: passed\n", $name; + unlink "DIFF/$output.diff"; + exit 0; } +printf "%-30s: TEST FAILED", $name; +open FOUT, '>>failure-outputs.txt'; +printf FOUT "Failed test: $name\n\n"; +close FOUT; +system "cat DIFF/$output.diff >> failure-outputs.txt"; -print "Running $name. \n" if $debug; -print " Input: $input, OUTPUT: $output, OPTIONS: $options\n" if $debug; - -print " "; -exec("../tcpdump 2>/dev/null -n -r $input $options | tee NEW/$output | diff -w - $output >DIFF/$output.diff"); -@cores = glob("core*"); -exit 10 if (@cores > 0); -exit 0; +if($r == -1) { + print " (failed to execute: $!)\n"; + exit 30; +} +if($r & 127) { + printf " (terminated with signal %u, %s coredump)\n", ($r & 127), ($r & 128) ? 'with' : 'without'; + exit ($r & 128) ? 10 : 20; +} +print "\n"; +exit $r >> 8; diff --git a/tests/TESTrun.sh b/tests/TESTrun.sh index d1baaa7b..a22260e3 100755 --- a/tests/TESTrun.sh +++ b/tests/TESTrun.sh @@ -4,59 +4,66 @@ mkdir -p NEW mkdir -p DIFF passed=0 failed=0 +INDENT=' ' cat /dev/null > failure-outputs.txt -# first run any specific tests. -for i in *.sh -do - case $i in TEST*.sh) continue;; esac - - if sh ./$i >DIFF/$i.result - then - echo $i: passed. - rm -f DIFF/$i.result +runComplexTests() +{ + for i in *.sh + do + case $i in TEST*.sh) continue;; esac + echo -n "$INDENT" + if sh ./$i + then passed=`expr $passed + 1` - else - echo $i: failed. + else failed=`expr $failed + 1` - fi -done - -echo $passed >.passed -echo $failed >.failed + fi + done +} -# now run typical tests -cat TESTLIST | while read name input output options -do - case $name in +runSimpleTests() +{ + local only=$1 + echo $passed >.passed + echo $failed >.failed + cat TESTLIST | while read name input output options + do + case $name in \#*) continue;; '') continue;; - esac - - if ./TESTonce $name $input $output "$options" - then - echo $name: passed. - rm -f DIFF/$output.diff + esac + [ "$only" != "" -a "$name" != "$only" ] && continue + echo -n "$INDENT" + if ./TESTonce $name $input $output "$options" + then passed=`expr $passed + 1` echo $passed >.passed - else - echo $name: failed. + else failed=`expr $failed + 1` echo $failed >.failed - echo "Failed test: $name" >> failure-outputs.txt - echo >> failure-outputs.txt - cat DIFF/$output.diff >> failure-outputs.txt - echo >> failure-outputs.txt - fi -done + fi + [ "$only" != "" -a "$name" == "$only" ] && break + done + # I hate shells with their stupid, useless subshells. + passed=`cat .passed` + failed=`cat .failed` +} -# I hate shells with their stupid, useless subshells. -passed=`cat .passed` -failed=`cat .failed` +if [ $# -eq 0 ] +then + runComplexTests + runSimpleTests +elif [ $# -eq 1 ] +then + runSimpleTests $1 +else + echo "Usage: $0 [test_name]" + exit 30 +fi # exit with number of failing tests. -echo -echo +echo '------------------------------------------------' printf "%4u tests failed\n" $failed printf "%4u tests passed\n" $passed echo @@ -64,8 +71,4 @@ echo cat failure-outputs.txt echo echo -exit $failed - - - - +exit $failed