Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/testsuite/runtest
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/testsuite/runtest
r1765 r2725 1 1 #!/bin/sh 2 # Usage: 3 # runtest [applet1] [applet2...] 2 4 3 [ -n "$srcdir" ] || srcdir=$(pwd) 4 [ -n "$bindir" ] || bindir=$(dirname $(pwd)) 5 PATH=$bindir:$PATH 5 . ./testing.sh 6 6 7 # Run old-style test. 7 total_failed=0 8 8 9 # Run one old-style test. 10 # Tests are stored in applet/testcase shell scripts. 11 # They are run using "sh -x -e applet/testcase". 12 # Option -e will make testcase stop on the first failed command. 9 13 run_applet_testcase() 10 14 { 11 local applet= $112 local testcase= $215 local applet="$1" 16 local testcase="$2" 13 17 14 18 local status=0 15 local RES= 19 local uc_applet=$(echo "$applet" | tr a-z A-Z) 20 local testname="$testcase" 16 21 17 local uc_applet=$(echo $applet | tr a-z A-Z) 18 local testname=$(basename $testcase) 19 20 if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then 21 echo UNTESTED: $testname 22 testname="${testname##*/}" # take basename 23 if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then 24 echo "UNTESTED: $testname" 22 25 return 0 23 26 fi 24 27 25 if grep -q "^# FEATURE: " $testcase; then26 local feature= `sed -ne 's/^# FEATURE: //p' $testcase`28 if grep "^# FEATURE: " "$testcase" >/dev/null; then 29 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase") 27 30 28 if grep -q "^# ${feature} is not set$" $bindir/.config; then 29 echo UNTESTED: $testname 30 return 0 31 fi 31 for f in $feature; do 32 if grep "^# $f is not set$" "$bindir/.config" >/dev/null; then 33 echo "UNTESTED: $testname" 34 return 0 35 fi 36 done 32 37 fi 33 38 34 rm -rf tmp35 mkdir -p tmp36 pushd tmp > /dev/null39 rm -rf ".tmpdir.$applet" 40 mkdir -p ".tmpdir.$applet" 41 cd ".tmpdir.$applet" || return 1 37 42 38 d=$srcdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$? 39 40 if [ $status -ne 0 ] ; then 41 echo FAIL: $testname 42 if [ $verbose -gt 0 ]; then 43 cat .logfile.txt 43 # echo "Running testcase $testcase" 44 d="$tsdir" \ 45 sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1 || status=$? 46 if [ $status -ne 0 ]; then 47 echo "FAIL: $testname" 48 if [ x"$VERBOSE" != x ]; then 49 cat "$testname.stdout.txt" 44 50 fi 45 status=$?46 51 else 47 echo PASS: $testname 48 rm -f .logfile.txt 49 status=$? 52 echo "PASS: $testname" 50 53 fi 51 54 52 popd > /dev/null53 rm -rf tmp55 cd .. 56 rm -rf ".tmpdir.$applet" 54 57 55 58 return $status 56 59 } 57 60 58 run_applet_tests() 61 # Run all old-style tests for given applet 62 run_oldstyle_applet_tests() 59 63 { 60 local applet=$1 61 64 local applet="$1" 62 65 local status=0 63 66 64 for testcase in $srcdir/$applet/*; do 65 if [ "$testcase" = "$srcdir/$applet/CVS" ]; then 66 continue 67 fi 68 69 if run_applet_testcase $applet $testcase; then 70 : 71 else 72 status=1 73 fi 67 for testcase in "$tsdir/$applet"/*; do 68 # switch on basename of $testcase 69 case "${testcase##*/}" in 70 .*) continue ;; # .svn, .git etc 71 *~) continue ;; # backup files 72 "CVS") continue ;; 73 \#*) continue ;; # CVS merge residues 74 *.mine) continue ;; # svn-produced junk 75 *.r[0-9]*) continue ;; # svn-produced junk 76 esac 77 run_applet_testcase "$applet" "$testcase" || status=1 78 total_failed=$((total_failed + status)) 74 79 done 75 76 80 return $status 77 81 } 78 82 79 83 80 status=0 81 verbose=0 84 85 lcwd=$(pwd) 86 [ x"$tsdir" != x"" ] || tsdir="$lcwd" 87 [ x"$bindir" != x"" ] || bindir="${lcwd%/*}" # one directory up from $lcwd 88 PATH="$bindir:$PATH" 89 export bindir # some tests need to look at $bindir/.config 90 91 if [ x"$VERBOSE" = x ]; then 92 export VERBOSE= 93 fi 82 94 83 95 if [ x"$1" = x"-v" ]; then 84 verbose=1 85 export VERBOSE=$verbose 96 export VERBOSE=1 86 97 shift 87 98 fi 88 99 100 implemented=$( 101 printf "busybox " # always implemented 102 "$bindir/busybox" 2>&1 | 103 while read line; do 104 if [ x"$line" = x"Currently defined functions:" ]; then 105 xargs | sed 's/,//g' 106 break 107 fi 108 done 109 ) 110 111 applets="$implemented" 89 112 if [ $# -ne 0 ]; then 90 applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done) 91 else 92 applets=$(ls $srcdir) 113 applets="$@" 93 114 fi 94 115 … … 96 117 97 118 LINKSDIR="$bindir/runtest-tempdir-links" 98 implemented=$($bindir/busybox 2>&1 | 99 while read line 100 do 101 if test x"$line" = x"Currently defined functions:" 102 then 103 xargs | sed 's/,//g' 104 break 105 fi 106 done 107 ) 119 120 # Comment this line out if you have put a different binary in $LINKSDIR 121 # (say, a "standard" tool's binary) in order to run tests against it: 108 122 rm -rf "$LINKSDIR" 2>/dev/null 109 mkdir "$LINKSDIR" 110 for i in $implemented 111 do 112 ln -s $bindir/busybox "$LINKSDIR"/$i 123 124 mkdir "$LINKSDIR" 2>/dev/null 125 for i in $implemented; do 126 # Note: if $LINKSDIR/applet exists, we do not overwrite it. 127 # Useful if one wants to run tests against a standard utility, 128 # not an applet. 129 ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null 113 130 done 114 131 115 132 # Set up option flags so tests can be selective. 133 export OPTIONFLAGS=:$( 134 sed -nr 's/^CONFIG_//p' "$bindir/.config" | 135 sed 's/=.*//' | xargs | sed 's/ /:/g' 136 ): 116 137 117 configfile=${bindir:-../../}/.config 118 export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g') 119 138 status=0 120 139 for applet in $applets; do 121 if [ "$applet" = "links" ]; then continue; fi 122 if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then 123 if run_applet_tests $applet; then 124 : 125 else 126 status=1 127 fi 140 # Any old-style tests for this applet? 141 if [ -d "$tsdir/$applet" ]; then 142 run_oldstyle_applet_tests "$applet" || status=1 128 143 fi 129 144 130 145 # Is this a new-style test? 131 applet=$(echo "$applet" | sed -n 's/\.tests$//p')132 if [ ${#applet} -ne 0 ]133 then134 if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]135 then136 echo "SKIPPED: $applet (not built)"137 continue146 if [ -f "$applet.tests" ]; then 147 if [ ! -e "$LINKSDIR/$applet" ]; then 148 # (avoiding bash'ism "${applet:0:4}") 149 if ! echo "$applet" | grep "^all_" >/dev/null; then 150 echo "SKIPPED: $applet (not built)" 151 continue 152 fi 138 153 fi 139 if PATH="$LINKSDIR":$srcdir:$bindir:$PATH \ 140 "${srcdir:-.}/$applet".tests 141 then 142 : 143 else 144 status=1 145 fi 154 # echo "Running test $tsdir/$applet.tests" 155 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" \ 156 "$tsdir/$applet.tests" 157 rc=$? 158 total_failed=$((total_failed + rc)) 159 test $rc -ne 0 && status=1 146 160 fi 161 done 147 162 148 done 149 rm -rf "$LINKSDIR" 163 # Leaving the dir makes it somewhat easier to run failed test by hand 164 #rm -rf "$LINKSDIR" 165 166 if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then 167 echo "$total_failed failure(s) detected; running with -v (verbose) will give more info" 168 fi 150 169 exit $status
Note:
See TracChangeset
for help on using the changeset viewer.