[821] | 1 | #!/bin/sh
|
---|
[2725] | 2 | # Usage:
|
---|
| 3 | # runtest [applet1] [applet2...]
|
---|
[821] | 4 |
|
---|
[2725] | 5 | . ./testing.sh
|
---|
[821] | 6 |
|
---|
[2725] | 7 | total_failed=0
|
---|
[821] | 8 |
|
---|
[2725] | 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.
|
---|
[1765] | 13 | run_applet_testcase()
|
---|
[821] | 14 | {
|
---|
[2725] | 15 | local applet="$1"
|
---|
| 16 | local testcase="$2"
|
---|
[821] | 17 |
|
---|
| 18 | local status=0
|
---|
[2725] | 19 | local uc_applet=$(echo "$applet" | tr a-z A-Z)
|
---|
| 20 | local testname="$testcase"
|
---|
[821] | 21 |
|
---|
[2725] | 22 | testname="${testname##*/}" # take basename
|
---|
| 23 | if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then
|
---|
| 24 | echo "UNTESTED: $testname"
|
---|
[821] | 25 | return 0
|
---|
| 26 | fi
|
---|
| 27 |
|
---|
[2725] | 28 | if grep "^# FEATURE: " "$testcase" >/dev/null; then
|
---|
| 29 | local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
|
---|
[821] | 30 |
|
---|
[2725] | 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
|
---|
[821] | 37 | fi
|
---|
| 38 |
|
---|
[2725] | 39 | rm -rf ".tmpdir.$applet"
|
---|
| 40 | mkdir -p ".tmpdir.$applet"
|
---|
| 41 | cd ".tmpdir.$applet" || return 1
|
---|
[821] | 42 |
|
---|
[2725] | 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"
|
---|
[821] | 50 | fi
|
---|
| 51 | else
|
---|
[2725] | 52 | echo "PASS: $testname"
|
---|
[821] | 53 | fi
|
---|
| 54 |
|
---|
[2725] | 55 | cd ..
|
---|
| 56 | rm -rf ".tmpdir.$applet"
|
---|
[821] | 57 |
|
---|
| 58 | return $status
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[2725] | 61 | # Run all old-style tests for given applet
|
---|
| 62 | run_oldstyle_applet_tests()
|
---|
[821] | 63 | {
|
---|
[2725] | 64 | local applet="$1"
|
---|
[821] | 65 | local status=0
|
---|
| 66 |
|
---|
[2725] | 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
|
---|
[3232] | 77 | run_applet_testcase "$applet" "$testcase" || {
|
---|
| 78 | status=1
|
---|
| 79 | total_failed=$((total_failed + 1))
|
---|
| 80 | }
|
---|
[821] | 81 | done
|
---|
| 82 | return $status
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
[2725] | 87 | lcwd=$(pwd)
|
---|
| 88 | [ x"$tsdir" != x"" ] || tsdir="$lcwd"
|
---|
| 89 | [ x"$bindir" != x"" ] || bindir="${lcwd%/*}" # one directory up from $lcwd
|
---|
| 90 | PATH="$bindir:$PATH"
|
---|
| 91 | export bindir # some tests need to look at $bindir/.config
|
---|
| 92 |
|
---|
| 93 | if [ x"$VERBOSE" = x ]; then
|
---|
| 94 | export VERBOSE=
|
---|
| 95 | fi
|
---|
| 96 |
|
---|
[821] | 97 | if [ x"$1" = x"-v" ]; then
|
---|
[2725] | 98 | export VERBOSE=1
|
---|
[821] | 99 | shift
|
---|
| 100 | fi
|
---|
| 101 |
|
---|
[2725] | 102 | implemented=$(
|
---|
| 103 | printf "busybox " # always implemented
|
---|
| 104 | "$bindir/busybox" 2>&1 |
|
---|
| 105 | while read line; do
|
---|
| 106 | if [ x"$line" = x"Currently defined functions:" ]; then
|
---|
| 107 | xargs | sed 's/,//g'
|
---|
| 108 | break
|
---|
| 109 | fi
|
---|
| 110 | done
|
---|
| 111 | )
|
---|
| 112 |
|
---|
| 113 | applets="$implemented"
|
---|
[821] | 114 | if [ $# -ne 0 ]; then
|
---|
[2725] | 115 | applets="$@"
|
---|
[821] | 116 | fi
|
---|
| 117 |
|
---|
| 118 | # Populate a directory with links to all busybox applets
|
---|
| 119 |
|
---|
[1765] | 120 | LINKSDIR="$bindir/runtest-tempdir-links"
|
---|
[2725] | 121 |
|
---|
| 122 | # Comment this line out if you have put a different binary in $LINKSDIR
|
---|
| 123 | # (say, a "standard" tool's binary) in order to run tests against it:
|
---|
[821] | 124 | rm -rf "$LINKSDIR" 2>/dev/null
|
---|
[2725] | 125 |
|
---|
| 126 | mkdir "$LINKSDIR" 2>/dev/null
|
---|
| 127 | for i in $implemented; do
|
---|
| 128 | # Note: if $LINKSDIR/applet exists, we do not overwrite it.
|
---|
| 129 | # Useful if one wants to run tests against a standard utility,
|
---|
| 130 | # not an applet.
|
---|
| 131 | ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null
|
---|
[821] | 132 | done
|
---|
| 133 |
|
---|
| 134 | # Set up option flags so tests can be selective.
|
---|
[2725] | 135 | export OPTIONFLAGS=:$(
|
---|
| 136 | sed -nr 's/^CONFIG_//p' "$bindir/.config" |
|
---|
| 137 | sed 's/=.*//' | xargs | sed 's/ /:/g'
|
---|
| 138 | ):
|
---|
[821] | 139 |
|
---|
[2725] | 140 | status=0
|
---|
[821] | 141 | for applet in $applets; do
|
---|
[2725] | 142 | # Any old-style tests for this applet?
|
---|
| 143 | if [ -d "$tsdir/$applet" ]; then
|
---|
| 144 | run_oldstyle_applet_tests "$applet" || status=1
|
---|
[821] | 145 | fi
|
---|
| 146 |
|
---|
| 147 | # Is this a new-style test?
|
---|
[2725] | 148 | if [ -f "$applet.tests" ]; then
|
---|
| 149 | if [ ! -e "$LINKSDIR/$applet" ]; then
|
---|
| 150 | # (avoiding bash'ism "${applet:0:4}")
|
---|
| 151 | if ! echo "$applet" | grep "^all_" >/dev/null; then
|
---|
| 152 | echo "SKIPPED: $applet (not built)"
|
---|
| 153 | continue
|
---|
| 154 | fi
|
---|
[821] | 155 | fi
|
---|
[2725] | 156 | # echo "Running test $tsdir/$applet.tests"
|
---|
| 157 | PATH="$LINKSDIR:$tsdir:$bindir:$PATH" \
|
---|
| 158 | "$tsdir/$applet.tests"
|
---|
| 159 | rc=$?
|
---|
| 160 | total_failed=$((total_failed + rc))
|
---|
| 161 | test $rc -ne 0 && status=1
|
---|
[821] | 162 | fi
|
---|
[2725] | 163 | done
|
---|
[821] | 164 |
|
---|
[2725] | 165 | # Leaving the dir makes it somewhat easier to run failed test by hand
|
---|
| 166 | #rm -rf "$LINKSDIR"
|
---|
| 167 |
|
---|
| 168 | if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then
|
---|
| 169 | echo "$total_failed failure(s) detected; running with -v (verbose) will give more info"
|
---|
| 170 | fi
|
---|
[821] | 171 | exit $status
|
---|