From 1f317d315c8140c2bcdbff1953a6f645f4f6ef04 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 28 Nov 2013 09:52:15 +0000 Subject: [PATCH] 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 --- test/run | 38 +++++++++++++++++++++++++++++--------- test/testisofs.sh | 12 ++++++------ test/testsh2.sh | 4 ++-- 3 files changed, 37 insertions(+), 17 deletions(-) mode change 100644 => 100755 test/testisofs.sh diff --git a/test/run b/test/run index 5d5ef23d6..f922c3df4 100755 --- a/test/run +++ b/test/run @@ -17,11 +17,15 @@ 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 \ +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 \ 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 \ @@ -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.$$ diff --git a/test/testisofs.sh b/test/testisofs.sh old mode 100644 new mode 100755 index 0118f390a..84df95d43 --- a/test/testisofs.sh +++ b/test/testisofs.sh @@ -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 diff --git a/test/testsh2.sh b/test/testsh2.sh index 4673f4726..d75a11ef9 100755 --- a/test/testsh2.sh +++ b/test/testsh2.sh @@ -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 -- 2.44.0