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,9 +17,13 @@ skipped=`expr 0` # count number of tests that were skipped
total=`expr 0` # total number of tests tried
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 \
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 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
@ -71,7 +75,7 @@ done
# Count tests
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`
fi
done
@ -103,9 +107,27 @@ ARGS_63=`pwd`/mod
runtest() {
i=$1
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" ]
then su - bin -c "cd `pwd`; ./test$i $ARG" || return 1
else ./test$i $ARG || return 1
then
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
return 0
}
@ -113,13 +135,11 @@ runtest() {
# Run all the tests, keeping track of who failed.
for i in `echo $tests`
do
if [ -x ./test$i ]
if [ -x ./test$i -o -x ./test${i}.sh ]
then
total=`expr $total + 1`
FAIL=0
unset ARG
testid="`echo $i | sed 's/\..*//'`"
ARG=`eval echo "\\${ARGS_$testid}"`
ARG=`eval echo "\\${ARGS_$i}"`
if [ "$tapmode" ]
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
# umount previous things
su root -c "umount $ramdev >/dev/null 2>&1 || true"
su root -c "umount $mp >/dev/null 2>&1 || true"
umount $ramdev >/dev/null 2>&1 || true
umount $mp >/dev/null 2>&1 || true
# Mount it on a RAM disk
su root -c "ramdisk 50000 $ramdev >/dev/null 2>&1"
su root -c "cp $fsimage $ramdev"
su root -c "mount -t isofs $ramdev $mp >/dev/null 2>&1"
ramdisk 50000 $ramdev >/dev/null 2>&1
cp $fsimage $ramdev
mount -t isofs $ramdev $mp >/dev/null 2>&1
# compare contents
(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
su root -c "umount $ramdev >/dev/null 2>&1"
umount $ramdev >/dev/null 2>&1
# cleanup
rm -rf $testdir $fsimage $out1 $out2

View file

@ -20,9 +20,9 @@ OLDPWD=`pwd`
export OLDPWD
# 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
elif which gcc 2>/dev/null
elif which gcc 2>/dev/null >/dev/null
then CC=gcc
else echo "Can't find a compiler, skipping test"
exit 0