3 # runtest [applet1] [applet2...]
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.
19 local uc_applet=$(echo "$applet" | tr a-z A-Z)
20 local testname="$testcase"
22 testname="${testname##*/}" # take basename
23 if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then
24 echo "UNTESTED: $testname"
28 if grep "^# FEATURE: " "$testcase" >/dev/null; then
29 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
32 if grep "^# $f is not set$" "$bindir/.config" >/dev/null; then
33 echo "UNTESTED: $testname"
39 rm -rf ".tmpdir.$applet"
40 mkdir -p ".tmpdir.$applet"
41 cd ".tmpdir.$applet" || return 1
43 # echo "Running testcase $testcase"
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"
52 echo "PASS: $testname"
56 rm -rf ".tmpdir.$applet"
61 # Run all old-style tests for given applet
62 run_oldstyle_applet_tests()
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
73 \#*) continue ;; # CVS merge residues
74 *.mine) continue ;; # svn-produced junk
75 *.r[0-9]*) continue ;; # svn-produced junk
77 run_applet_testcase "$applet" "$testcase" || status=1
78 total_failed=$((total_failed + status))
86 [ x"$tsdir" != x"" ] || tsdir="$lcwd"
87 [ x"$bindir" != x"" ] || bindir="${lcwd%/*}" # one directory up from $lcwd
89 export bindir # some tests need to look at $bindir/.config
91 if [ x"$VERBOSE" = x ]; then
95 if [ x"$1" = x"-v" ]; then
101 printf "busybox " # always implemented
102 "$bindir/busybox" 2>&1 |
104 if [ x"$line" = x"Currently defined functions:" ]; then
111 applets="$implemented"
112 if [ $# -ne 0 ]; then
116 # Populate a directory with links to all busybox applets
118 LINKSDIR="$bindir/runtest-tempdir-links"
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:
122 rm -rf "$LINKSDIR" 2>/dev/null
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,
129 ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null
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'
139 for applet in $applets; do
140 # Any old-style tests for this applet?
141 if [ -d "$tsdir/$applet" ]; then
142 run_oldstyle_applet_tests "$applet" || status=1
145 # Is this a new-style test?
146 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)"
154 # echo "Running test $tsdir/$applet.tests"
155 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" \
156 "$tsdir/$applet.tests"
158 total_failed=$((total_failed + rc))
159 test $rc -ne 0 && status=1
163 # Leaving the dir makes it somewhat easier to run failed test by hand
166 if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then
167 echo "$total_failed failure(s) detected; running with -v (verbose) will give more info"