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