run: allow scripts to be run as root

Forward-port of the run script change in the testvnd
commit on the 3.3.0 branch by David.

Needed to cleanly run the testisofs test as root in
the Jenkins environment.

'While here,' also fix messy which output in testsh2.

Change-Id: I6ec472e1386a54ae74b6e55394f01fa7c5ce53a9
This commit is contained in:
Ben Gras 2013-11-28 09:52:15 +00:00
parent d3e3c78051
commit 1f317d315c
3 changed files with 37 additions and 17 deletions

View File

@ -17,11 +17,15 @@ skipped=`expr 0` # count number of tests that were skipped
total=`expr 0` # total number of tests tried total=`expr 0` # total number of tests tried
badones= # list of tests that failed badones= # list of tests that failed
# Tests which require setuid # In the lists below, shell scripts should be listed without ".sh" suffix
# Programs that require setuid
setuids="test11 test33 test43 test44 test46 test56 test60 test61 test65 \ setuids="test11 test33 test43 test44 test46 test56 test60 test61 test65 \
test69" # test73" test69" # test73"
# Scripts that require to be run as root
rootscripts="testisofs"
alltests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ alltests="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \ 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
61 62 63 64 65 66 67 68 69 70 71 72 75 \ 61 62 63 64 65 66 67 68 69 70 71 72 75 \
@ -71,7 +75,7 @@ done
# Count tests # Count tests
for i in `echo $tests`; do for i in `echo $tests`; do
if [ -x ./test$i ]; then if [ -x ./test$i -o -x ./test${i}.sh ]; then
tests_no=`expr $tests_no + 1` tests_no=`expr $tests_no + 1`
fi fi
done done
@ -103,9 +107,27 @@ ARGS_63=`pwd`/mod
runtest() { runtest() {
i=$1 i=$1
ARG=$2 ARG=$2
# setuid doesn't work with scripts, so we can only run those as root
if echo "$rootscripts" | tr ' ' '\n' | grep "^test${i}\$" >/dev/null
then needroot=1
else needroot=0
fi
# depending on where we are, scripts might have a .sh suffix or not
if [ -x test${i}.sh ]
then NAME=./test${i}.sh
else NAME=./test$i
fi
if [ "$ROOT" ] if [ "$ROOT" ]
then su - bin -c "cd `pwd`; ./test$i $ARG" || return 1 then
else ./test$i $ARG || return 1 if [ $needroot -eq 1 ]
then $NAME $ARG || return 1
else su - bin -c "cd `pwd`; $NAME $ARG" || return 1
fi
else
if [ $needroot -eq 1 ]
then echo "skipping test$i, not root" >&2 && return 0
else $NAME $ARG || return 1
fi
fi fi
return 0 return 0
} }
@ -113,13 +135,11 @@ runtest() {
# Run all the tests, keeping track of who failed. # Run all the tests, keeping track of who failed.
for i in `echo $tests` for i in `echo $tests`
do do
if [ -x ./test$i ] if [ -x ./test$i -o -x ./test${i}.sh ]
then then
total=`expr $total + 1` total=`expr $total + 1`
FAIL=0 FAIL=0
unset ARG ARG=`eval echo "\\${ARGS_$i}"`
testid="`echo $i | sed 's/\..*//'`"
ARG=`eval echo "\\${ARGS_$testid}"`
if [ "$tapmode" ] if [ "$tapmode" ]
then out=out.$$ then out=out.$$

12
test/testisofs.sh Normal file → Executable file
View File

@ -43,13 +43,13 @@ done
writeisofs -s0x0 -l MINIX $testdir $fsimage >/dev/null 2>&1 writeisofs -s0x0 -l MINIX $testdir $fsimage >/dev/null 2>&1
# umount previous things # umount previous things
su root -c "umount $ramdev >/dev/null 2>&1 || true" umount $ramdev >/dev/null 2>&1 || true
su root -c "umount $mp >/dev/null 2>&1 || true" umount $mp >/dev/null 2>&1 || true
# Mount it on a RAM disk # Mount it on a RAM disk
su root -c "ramdisk 50000 $ramdev >/dev/null 2>&1" ramdisk 50000 $ramdev >/dev/null 2>&1
su root -c "cp $fsimage $ramdev" cp $fsimage $ramdev
su root -c "mount -t isofs $ramdev $mp >/dev/null 2>&1" mount -t isofs $ramdev $mp >/dev/null 2>&1
# compare contents # compare contents
(cd $testdir/$contents && sha1 * | sort) >$out1 (cd $testdir/$contents && sha1 * | sort) >$out1
@ -57,7 +57,7 @@ su root -c "mount -t isofs $ramdev $mp >/dev/null 2>&1"
diff -u $out1 $out2 diff -u $out1 $out2
su root -c "umount $ramdev >/dev/null 2>&1" umount $ramdev >/dev/null 2>&1
# cleanup # cleanup
rm -rf $testdir $fsimage $out1 $out2 rm -rf $testdir $fsimage $out1 $out2

View File

@ -20,9 +20,9 @@ OLDPWD=`pwd`
export OLDPWD export OLDPWD
# CC="exec cc -wo -F" # nonstandard flags for ACK :-( # CC="exec cc -wo -F" # nonstandard flags for ACK :-(
if which clang 2>/dev/null if which clang 2>/dev/null >/dev/null
then CC=clang then CC=clang
elif which gcc 2>/dev/null elif which gcc 2>/dev/null >/dev/null
then CC=gcc then CC=gcc
else echo "Can't find a compiler, skipping test" else echo "Can't find a compiler, skipping test"
exit 0 exit 0