<sys/socket.h>: turn off MSG_NOSIGNAL
[minix3.git] / test / run
blob80d07c16ee6be9b2ebce50c9b25c5ab14e690b47
1 #!/bin/sh
3 # Are we running as root?
4 unset ROOT
5 if [ "`id -u`" = 0 ]
6 then ROOT=yes
7 fi
9 # Initialization
10 PATH=:/bin:/usr/bin
11 export PATH
13 rm -rf DIR* # remove any old junk lying around
14 passed=`expr 0` # count number of tests run correctly
15 failed=`expr 0` # count number of tests that failed
16 skipped=`expr 0` # count number of tests that were skipped
17 total=`expr 0` # total number of tests tried
18 badones= # list of tests that failed
20 # In the lists below, shell scripts should be listed without ".sh" suffix
22 # Programs that require setuid
23 setuids="test11 test33 test43 test44 test46 test56 test60 test61 test65 \
24 test69 test76 test73 test74 test77 test78"
25 # Scripts that require to be run as root
26 rootscripts="testisofs testvnd"
28 alltests="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
29 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
30 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
31 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 \
32 sh1 sh2 interp mfs isofs vnd"
33 tests_no=`expr 0`
35 # If root, make sure the setuid tests have the correct permissions
36 # and make the dir bin-owned.
37 if [ "$ROOT" ]
38 then /usr/sbin/chown bin .
39 /usr/sbin/chown root ${setuids}
40 chmod 4755 ${setuids}
43 tests=$alltests
45 # Are we given any args? If so, we might have to give
46 # or change our testlist
47 while getopts 'lt:T' opt
49 case $opt in
50 l) echo "$alltests"
51 exit 0
53 t) tests="$OPTARG"
55 T) tapmode=yes
56 diagprefix="# "
58 ?) echo "Usage: run [-l] [-t testlist] [-T]" >&2
59 echo " -l: list tests, exit" >&2
60 echo " -t: execute given set of tests, default: all" >&2
61 echo " -T: produce TAP-format output" >&2
62 exit 1
63 esac
64 done
66 # Count tests
67 for i in `echo $tests`; do
68 if [ -x ./test$i -o -x ./test${i}.sh ]; then
69 tests_no=`expr $tests_no + 1`
71 done
73 if [ $tests_no -eq 0 ]
74 then
75 echo "No test binaries found. did you compile?"
76 exit 1
79 # Print tests list whenever user asks for TAP mode. It is up
80 # to the caller to make sure it makes sense, i.e. he knows what it
81 # represents.
82 if [ "$tapmode" ]
83 then echo "1..$tests_no"
86 if [ "$tests" = "$alltests" ]
87 then # Print test welcome message
88 if [ ! "$tapmode" ]; then clear; fi
89 echo -n "${diagprefix}Running POSIX compliance test suite. "
90 echo "There are $tests_no tests in total."
91 echo "${diagprefix}"
94 # Provide an argument for test63
95 ARGS_63=`pwd`/mod
97 runtest() {
98 i=$1
99 ARG=$2
100 # setuid doesn't work with scripts, so we can only run those as root
101 if echo "$rootscripts" | tr ' ' '\n' | grep "^test${i}\$" >/dev/null
102 then needroot=1
103 else needroot=0
105 # depending on where we are, scripts might have a .sh suffix or not
106 if [ -x test${i}.sh ]
107 then NAME=./test${i}.sh
108 else NAME=./test$i
110 if [ "$ROOT" ]
111 then
112 if [ $needroot -eq 1 ]
113 then $NAME $ARG || return 1
114 else su - bin -c "cd `pwd`; $NAME $ARG" || return 1
116 else
117 if [ $needroot -eq 1 ]
118 then echo "skipping test$i, not root." >&2 && return 0
119 else $NAME $ARG || return 1
122 return 0
125 # Run all the tests, keeping track of who failed.
126 for i in `echo $tests`
128 if [ -x ./test$i -o -x ./test${i}.sh ]
129 then
130 total=`expr $total + 1`
131 FAIL=0
132 ARG=`eval echo "\\${ARGS_$i}"`
134 if [ "$tapmode" ]
135 then out=out.$$
136 rm -f $out
137 runtest $i $ARG >$out 2>&1
138 else runtest $i $ARG
141 FAIL=$?
143 if [ $FAIL -eq 0 ]
144 then if [ "$tapmode" ]
145 then echo "ok test $i"
147 passed=`expr $passed + 1`
148 else if [ "$tapmode" ]
149 then echo "not ok test $i"
151 failed=`expr $failed + 1`
152 badones=`echo $badones " " $i`
155 if [ "$tapmode" ]
156 then cat $out | sed "s/^/$diagprefix/"
157 rm -f $out
159 else
160 echo "${diagprefix}warning: skipping test$i"
161 skipped=`expr $skipped + 1`
163 done
165 # Print results of the tests.
166 if [ "$tests" = "$alltests" ]
167 then echo "${diagprefix}"
168 if test $total = $passed
169 then echo "${diagprefix}All $passed tests completed without error ($skipped skipped)."
170 else echo "${diagprefix}Testing completed. Score: $passed passed, $failed failed, skipped $skipped"
171 echo "${diagprefix}The following tests failed: $badones"
175 # if any test failed return an error
176 if [ $failed -gt 0 ]
177 then
178 exit 1
181 # echo " "