3 # runtest [applet1] [applet2...]
7 # Run one old-style test.
8 # Tests are stored in applet/testcase shell scripts.
9 # They are run using "sh -x -e applet/testcase".
10 # Option -e will make testcase stop on the first failed command.
17 local uc_applet=$(echo "$applet" | tr a-z A-Z)
18 local testname="$testcase"
20 testname="${testname##*/}" # take basename
21 if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then
22 echo "UNTESTED: $testname"
26 if grep "^# FEATURE: " "$testcase" >/dev/null; then
27 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
29 if grep "^# $feature is not set$" "$bindir/.config" >/dev/null; then
30 echo "UNTESTED: $testname"
35 rm -rf ".tmpdir.$applet"
36 mkdir -p ".tmpdir.$applet"
37 cd ".tmpdir.$applet" || return 1
39 # echo "Running testcase $testcase"
41 sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1 || status=$?
42 if [ $status -ne 0 ]; then
43 echo "FAIL: $testname"
44 if [ x"$VERBOSE" != x ]; then
45 cat "$testname.stdout.txt"
48 echo "PASS: $testname"
52 rm -rf ".tmpdir.$applet"
57 # Run all old-style tests for given applet
58 run_oldstyle_applet_tests()
63 for testcase in "$tsdir/$applet"/*; do
64 # switch on basename of $testcase
65 case "${testcase##*/}" in
66 .*) continue ;; # .svn, .git etc
67 *~) continue ;; # backup files
69 \#*) continue ;; # CVS merge residues
70 *.mine) continue ;; # svn-produced junk
71 *.r[0-9]*) continue ;; # svn-produced junk
73 run_applet_testcase "$applet" "$testcase" || status=1
81 [ x"$tsdir" != x"" ] || tsdir="$lcwd"
82 [ x"$bindir" != x"" ] || bindir="${lcwd%/*}" # one directory up from $lcwd
84 export bindir # some tests need to look at $bindir/.config
86 if [ x"$VERBOSE" = x ]; then
90 if [ x"$1" = x"-v" ]; then
96 printf "busybox " # always implemented
97 "$bindir/busybox" 2>&1 |
99 if [ x"$line" = x"Currently defined functions:" ]; then
106 applets="$implemented"
107 if [ $# -ne 0 ]; then
111 # Populate a directory with links to all busybox applets
113 LINKSDIR="$bindir/runtest-tempdir-links"
115 # Comment this line out if you have put a different binary in $LINKSDIR
116 # (say, a "standard" tool's binary) in order to run tests against it:
117 rm -rf "$LINKSDIR" 2>/dev/null
119 mkdir "$LINKSDIR" 2>/dev/null
120 for i in $implemented; do
121 # Note: if $LINKSDIR/applet exists, we do not overwrite it.
122 # Useful if one wants to run tests against a standard utility,
124 ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null
127 # Set up option flags so tests can be selective.
128 export OPTIONFLAGS=:$(
129 sed -nr 's/^CONFIG_//p' "$bindir/.config" |
130 sed 's/=.*//' | xargs | sed 's/ /:/g'
134 for applet in $applets; do
135 # Any old-style tests for this applet?
136 if [ -d "$tsdir/$applet" ]; then
137 run_oldstyle_applet_tests "$applet" || status=1
140 # Is this a new-style test?
141 if [ -f "$applet.tests" ]; then
142 if [ ! -e "$LINKSDIR/$applet" ]; then
143 # (avoiding bash'ism "${applet:0:4}")
144 if ! echo "$applet" | grep "^all_" >/dev/null; then
145 echo "SKIPPED: $applet (not built)"
149 # echo "Running test $tsdir/$applet.tests"
150 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" \
151 "$tsdir/$applet.tests" || status=1
155 # Leaving the dir makes it somewhat easier to run failed test by hand
158 if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then
159 echo "Failures detected, running with -v (verbose) will give more info"