]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTrun.sh
VRRP: Add a test capture file
[tcpdump] / tests / TESTrun.sh
1 #!/bin/sh
2
3 #
4 # Force UTC, so time stamps are printed in a standard time zone, and
5 # tests don't have to be run in the time zone in which the output
6 # file was generated.
7 #
8 TZ=GMT0; export TZ
9
10 #
11 # Get the tests directory from $0.
12 #
13 testsdir=`dirname "$0"`
14
15 #
16 # Convert it to an absolute path, so it works even after we do a cd.
17 #
18 testsdir=`cd ${testsdir}; pwd`
19
20 echo Running tests from ${testsdir}
21
22 passedfile=`pwd`/tests/.passed
23 failedfile=`pwd`/tests/.failed
24 failureoutput=`pwd`/tests/failure-outputs.txt
25 mkdir -p tests/NEW
26 mkdir -p tests/DIFF
27 cat /dev/null > ${failureoutput}
28
29 runComplexTests()
30 {
31 for i in ${testsdir}/*.sh
32 do
33 case $i in
34 ${testsdir}/TEST*.sh) continue;;
35 ${testsdir}/\*.sh) continue;;
36 esac
37 echo Running $i
38 (cd tests && sh $i ${srcdir})
39 done
40 passed=`cat ${passedfile}`
41 failed=`cat ${failedfile}`
42 }
43
44 runSimpleTests()
45 {
46 only=$1
47 cat ${testsdir}/TESTLIST | while read name input output options
48 do
49 case $name in
50 \#*) continue;;
51 '') continue;;
52 esac
53 rm -f core
54 [ "$only" != "" -a "$name" != "$only" ] && continue
55 # I hate shells with their stupid, useless subshells.
56 passed=`cat ${passedfile}`
57 failed=`cat ${failedfile}`
58 (cd tests # run TESTonce in tests directory
59 if ${testsdir}/TESTonce $name ${testsdir}/$input ${testsdir}/$output "$options"
60 then
61 passed=`expr $passed + 1`
62 echo $passed >${passedfile}
63 else
64 failed=`expr $failed + 1`
65 echo $failed >${failedfile}
66 fi)
67 [ "$only" != "" -a "$name" = "$only" ] && break
68 done
69 # I hate shells with their stupid, useless subshells.
70 passed=`cat ${passedfile}`
71 failed=`cat ${failedfile}`
72 }
73
74 passed=0
75 failed=0
76 echo $passed >${passedfile}
77 echo $failed >${failedfile}
78 if [ $# -eq 0 ]
79 then
80 runComplexTests
81 runSimpleTests
82 elif [ $# -eq 1 ]
83 then
84 runSimpleTests $1
85 else
86 echo "Usage: $0 [test_name]"
87 exit 30
88 fi
89
90 # exit with number of failing tests.
91 echo '------------------------------------------------'
92 printf "%4u tests failed\n" $failed
93 printf "%4u tests passed\n" $passed
94 echo
95 cat ${failureoutput}
96 echo
97 echo
98 exit $failed