]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTrun.sh
updates to scripts for running in testdir vs builddir
[tcpdump] / tests / TESTrun.sh
1 #!/bin/sh
2
3 TZ=GMT0; export TZ
4 srcdir=${SRCDIR-..}
5
6 # make it absolute for later use.
7 srcdir=$(cd $srcdir && pwd)
8
9 # this should be run from the compiled build directory,
10 # with srcdir= set to wherever the source code is.
11 # not from the tests directory.
12 echo RUNNING from ${srcdir}
13
14 passedfile=$(pwd)/tests/.passed
15 failedfile=$(pwd)/tests/.failed
16 failureoutput=$(pwd)/tests/failure-outputs.txt
17 mkdir -p tests/NEW
18 mkdir -p tests/DIFF
19 cat /dev/null > ${failureoutput}
20
21 runComplexTests()
22 {
23 for i in ${srcdir}/tests/*.sh
24 do
25 case $i in
26 ${srcdir}/tests/TEST*.sh) continue;;
27 ${srcdir}/tests/\*.sh) continue;;
28 esac
29 echo Running $i
30 (sh $i ${srcdir})
31 done
32 passed=`cat ${passedfile}`
33 failed=`cat ${failedfile}`
34 }
35
36 runSimpleTests()
37 {
38 only=$1
39 cat ${srcdir}/tests/TESTLIST | while read name input output options
40 do
41 case $name in
42 \#*) continue;;
43 '') continue;;
44 esac
45 rm -f core
46 [ "$only" != "" -a "$name" != "$only" ] && continue
47 export SRCDIR=${srcdir}
48 # I hate shells with their stupid, useless subshells.
49 passed=`cat ${passedfile}`
50 failed=`cat ${failedfile}`
51 (cd tests # run TESTonce in tests directory
52 if ${srcdir}/tests/TESTonce $name ${srcdir}/tests/$input ${srcdir}/tests/$output "$options"
53 then
54 passed=`expr $passed + 1`
55 echo $passed >${passedfile}
56 else
57 failed=`expr $failed + 1`
58 echo $failed >${failedfile}
59 fi
60 if [ -d COREFILES ]; then
61 if [ -f core ]; then mv core COREFILES/$name.core; fi
62 fi)
63 [ "$only" != "" -a "$name" = "$only" ] && break
64 done
65 # I hate shells with their stupid, useless subshells.
66 passed=`cat ${passedfile}`
67 failed=`cat ${failedfile}`
68 }
69
70 passed=0
71 failed=0
72 echo $passed >${passedfile}
73 echo $failed >${failedfile}
74 if [ $# -eq 0 ]
75 then
76 runComplexTests
77 runSimpleTests
78 elif [ $# -eq 1 ]
79 then
80 runSimpleTests $1
81 else
82 echo "Usage: $0 [test_name]"
83 exit 30
84 fi
85
86 # exit with number of failing tests.
87 echo '------------------------------------------------'
88 printf "%4u tests failed\n" $failed
89 printf "%4u tests passed\n" $passed
90 echo
91 cat ${failureoutput}
92 echo
93 echo
94 exit $failed