xref: /minix3/minix/tests/run (revision 3ba6090f825dfbac97538b19928b0ab1e37909d6)
1433d6423SLionel Sambuc#!/bin/sh
2433d6423SLionel Sambuc
3433d6423SLionel Sambuc# Are we running as root?
4433d6423SLionel Sambucunset ROOT
5433d6423SLionel Sambucif [ "`id -u`" = 0 ]
6433d6423SLionel Sambucthen	ROOT=yes
7433d6423SLionel Sambucfi
8433d6423SLionel Sambuc
9433d6423SLionel Sambuc# Initialization
10d1abad94SBen GrasPATH=:/bin:/usr/bin:/sbin
11433d6423SLionel Sambucexport PATH
12433d6423SLionel Sambuc
13433d6423SLionel Sambucrm -rf DIR*			# remove any old junk lying around
14433d6423SLionel Sambucpassed=`expr 0`			# count number of tests run correctly
15433d6423SLionel Sambucfailed=`expr 0`			# count number of tests that failed
16433d6423SLionel Sambucskipped=`expr 0`		# count number of tests that were skipped
17433d6423SLionel Sambuctotal=`expr 0`			# total number of tests tried
18433d6423SLionel Sambucbadones=			# list of tests that failed
1986e41e22SErik van der Kouweexport USENETWORK		# set to "yes" for test48+82 to use the network
20433d6423SLionel Sambuc
21433d6423SLionel Sambuc# In the lists below, shell scripts should be listed without ".sh" suffix
22433d6423SLionel Sambuc
23433d6423SLionel Sambuc# Programs that require setuid
24433d6423SLionel Sambucsetuids="test11 test33 test43 test44 test46 test56 test60 test61 test65 \
25*3ba6090fSDavid van Moolenbroek	 test69 test73 test74 test78 test83 test85 test87 test88 test89 \
26*3ba6090fSDavid van Moolenbroek	 test92 test93 test94"
27433d6423SLionel Sambuc# Scripts that require to be run as root
286f3e0bcdSDavid van Moolenbroekrootscripts="testisofs testvnd testrmib testrelpol"
29433d6423SLionel Sambuc
30433d6423SLionel Sambucalltests="1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 \
31433d6423SLionel Sambuc         21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
32433d6423SLionel Sambuc         41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
33294d1590SErik van der Kouwe         61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
34*3ba6090fSDavid van Moolenbroek         81 82 83 84 85 86 87 88 89 90 91 92 93 94 \
35baa5830fSDavid van Moolenbroek	 sh1 sh2 interp mfs isofs vnd rmib"
36433d6423SLionel Sambuctests_no=`expr 0`
37433d6423SLionel Sambuc
38433d6423SLionel Sambuc# If root, make sure the setuid tests have the correct permissions
39433d6423SLionel Sambuc# and make the dir bin-owned.
40433d6423SLionel Sambucif [ "$ROOT" ]
41433d6423SLionel Sambucthen	/usr/sbin/chown bin .
42433d6423SLionel Sambuc	/usr/sbin/chown root ${setuids}
43433d6423SLionel Sambuc	chmod 4755 ${setuids}
44433d6423SLionel Sambucfi
45433d6423SLionel Sambuc
46433d6423SLionel Sambuctests=$alltests
47433d6423SLionel Sambuc
48433d6423SLionel Sambuc# Are we given any args? If so, we might have to give
49433d6423SLionel Sambuc# or change our testlist
50433d6423SLionel Sambucwhile getopts 'lt:T' opt
51433d6423SLionel Sambucdo
52433d6423SLionel Sambuc	case $opt in
53433d6423SLionel Sambuc	l)	echo "$alltests"
54433d6423SLionel Sambuc		exit 0
55433d6423SLionel Sambuc		;;
56433d6423SLionel Sambuc	t)      tests="$OPTARG"
57433d6423SLionel Sambuc		;;
58433d6423SLionel Sambuc	T)	tapmode=yes
59433d6423SLionel Sambuc		diagprefix="# "
60433d6423SLionel Sambuc		;;
61433d6423SLionel Sambuc	?)      echo "Usage: run [-l] [-t testlist] [-T]" >&2
62433d6423SLionel Sambuc		echo "	-l: list tests, exit" >&2
63433d6423SLionel Sambuc		echo "	-t: execute given set of tests, default: all" >&2
64433d6423SLionel Sambuc		echo "	-T: produce TAP-format output" >&2
65433d6423SLionel Sambuc		exit 1
66433d6423SLionel Sambuc	esac
67433d6423SLionel Sambucdone
68433d6423SLionel Sambuc
69433d6423SLionel Sambuc# Count tests
70433d6423SLionel Sambucfor i in `echo $tests`; do
71433d6423SLionel Sambuc   if [ -x ./test$i -o -x ./test${i}.sh ]; then
72433d6423SLionel Sambuc      tests_no=`expr $tests_no + 1`
73433d6423SLionel Sambuc   fi
74433d6423SLionel Sambucdone
75433d6423SLionel Sambuc
76433d6423SLionel Sambucif [  $tests_no -eq 0 ]
77433d6423SLionel Sambucthen
78433d6423SLionel Sambuc	echo "No test binaries found. did you compile?"
79433d6423SLionel Sambuc	exit 1
80433d6423SLionel Sambucfi
81433d6423SLionel Sambuc
82433d6423SLionel Sambuc# Print tests list whenever user asks for TAP mode. It is up
83433d6423SLionel Sambuc# to the caller to make sure it makes sense, i.e. he knows what it
84433d6423SLionel Sambuc# represents.
85433d6423SLionel Sambucif [ "$tapmode" ]
86433d6423SLionel Sambucthen	echo "1..$tests_no"
87433d6423SLionel Sambucfi
88433d6423SLionel Sambuc
89433d6423SLionel Sambucif [ "$tests" = "$alltests" ]
90433d6423SLionel Sambucthen	# Print test welcome message
91433d6423SLionel Sambuc	if [ ! "$tapmode" ]; then clear; fi
92433d6423SLionel Sambuc	echo -n "${diagprefix}Running POSIX compliance test suite. "
93433d6423SLionel Sambuc	echo "There are $tests_no tests in total."
94433d6423SLionel Sambuc	echo "${diagprefix}"
95433d6423SLionel Sambucfi
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc# Provide an argument for test63
98433d6423SLionel SambucARGS_63=`pwd`/mod
99433d6423SLionel Sambuc
100433d6423SLionel Sambucruntest() {
101433d6423SLionel Sambuc	i=$1
102433d6423SLionel Sambuc	ARG=$2
103433d6423SLionel Sambuc	# setuid doesn't work with scripts, so we can only run those as root
104433d6423SLionel Sambuc	if echo "$rootscripts" | tr ' ' '\n' | grep "^test${i}\$" >/dev/null
105433d6423SLionel Sambuc	then needroot=1
106433d6423SLionel Sambuc	else needroot=0
107433d6423SLionel Sambuc	fi
108433d6423SLionel Sambuc	# depending on where we are, scripts might have a .sh suffix or not
109433d6423SLionel Sambuc	if [ -x test${i}.sh ]
110433d6423SLionel Sambuc	then NAME=./test${i}.sh
111433d6423SLionel Sambuc	else NAME=./test$i
112433d6423SLionel Sambuc	fi
113433d6423SLionel Sambuc	if [ "$ROOT" ]
114433d6423SLionel Sambuc	then
115433d6423SLionel Sambuc		if [ $needroot -eq 1 ]
116433d6423SLionel Sambuc		then $NAME $ARG || return 1
117b8d14720SLionel Sambuc		else su bin -c "$NAME $ARG" || return 1
118433d6423SLionel Sambuc		fi
119433d6423SLionel Sambuc	else
120433d6423SLionel Sambuc		if [ $needroot -eq 1 ]
121433d6423SLionel Sambuc		then echo "skipping test$i, not root." >&2 && return 0
122433d6423SLionel Sambuc		else $NAME $ARG || return 1
123433d6423SLionel Sambuc		fi
124433d6423SLionel Sambuc	fi
125433d6423SLionel Sambuc	return 0
126433d6423SLionel Sambuc}
127433d6423SLionel Sambuc
128433d6423SLionel Sambuc# Run all the tests, keeping track of who failed.
129433d6423SLionel Sambucfor i in `echo $tests`
130433d6423SLionel Sambucdo
131433d6423SLionel Sambuc   if [ -x ./test$i -o -x ./test${i}.sh ]
132433d6423SLionel Sambuc   then
133433d6423SLionel Sambuc      total=`expr $total + 1`
134433d6423SLionel Sambuc      FAIL=0
135433d6423SLionel Sambuc      ARG=`eval echo "\\${ARGS_$i}"`
136433d6423SLionel Sambuc
137433d6423SLionel Sambuc      if [ "$tapmode" ]
138433d6423SLionel Sambuc      then	out=out.$$
139433d6423SLionel Sambuc		rm -f $out
140433d6423SLionel Sambuc		runtest $i $ARG >$out 2>&1
141433d6423SLionel Sambuc      else	runtest $i $ARG
142433d6423SLionel Sambuc      fi
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc      FAIL=$?
145433d6423SLionel Sambuc
146433d6423SLionel Sambuc      if [ $FAIL -eq 0 ]
147433d6423SLionel Sambuc         then	if [ "$tapmode" ]
148433d6423SLionel Sambuc		then	echo "ok test $i"
149433d6423SLionel Sambuc		fi
150433d6423SLionel Sambuc		passed=`expr $passed + 1`
151433d6423SLionel Sambuc         else	if [ "$tapmode" ]
152433d6423SLionel Sambuc		then	echo "not ok test $i"
153433d6423SLionel Sambuc		fi
154433d6423SLionel Sambuc		failed=`expr $failed + 1`
155433d6423SLionel Sambuc		badones=`echo $badones " " $i`
156433d6423SLionel Sambuc      fi
157433d6423SLionel Sambuc
158433d6423SLionel Sambuc      if [ "$tapmode" ]
159433d6423SLionel Sambuc      then	cat $out | sed "s/^/$diagprefix/"
160433d6423SLionel Sambuc		rm -f $out
161433d6423SLionel Sambuc      fi
162433d6423SLionel Sambuc   else
163433d6423SLionel Sambuc      echo "${diagprefix}warning: skipping test$i"
164433d6423SLionel Sambuc      skipped=`expr $skipped + 1`
165433d6423SLionel Sambuc   fi
166433d6423SLionel Sambucdone
167433d6423SLionel Sambuc
168433d6423SLionel Sambuc# Print results of the tests.
169433d6423SLionel Sambucif [ "$tests" = "$alltests" ]
170433d6423SLionel Sambucthen	echo "${diagprefix}"
171433d6423SLionel Sambuc	if test $total = $passed
172433d6423SLionel Sambuc	   then echo "${diagprefix}All $passed tests completed without error ($skipped skipped)."
173433d6423SLionel Sambuc	   else echo "${diagprefix}Testing completed. Score: $passed passed, $failed failed, skipped $skipped"
174433d6423SLionel Sambuc	        echo "${diagprefix}The following tests failed: $badones"
175433d6423SLionel Sambuc	fi
176433d6423SLionel Sambucfi
177433d6423SLionel Sambuc
178433d6423SLionel Sambuc# if any test failed return an error
179433d6423SLionel Sambucif [ $failed -gt 0 ]
180433d6423SLionel Sambucthen
181433d6423SLionel Sambuc	exit 1
182433d6423SLionel Sambucfi
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc# echo " "
185