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 uc_applet
=$
(echo "$applet" |
tr a-z A-Z
)
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" ||
{
79 total_failed
=$
((total_failed
+ 1))
88 [ x
"$tsdir" != x
"" ] || tsdir
="$lcwd"
89 [ x
"$bindir" != x
"" ] || bindir
="${lcwd%/*}" # one directory up from $lcwd
91 export bindir
# some tests need to look at $bindir/.config
93 if [ x
"$VERBOSE" = x
]; then
97 if [ x
"$1" = x
"-v" ]; then
103 printf "busybox " # always implemented
104 "$bindir/busybox" 2>&1 |
106 if [ x
"$line" = x
"Currently defined functions:" ]; then
113 applets
="$implemented"
114 if [ $# -ne 0 ]; then
118 # Populate a directory with links to all busybox applets
120 LINKSDIR
="$bindir/runtest-tempdir-links"
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:
124 rm -rf "$LINKSDIR" 2>/dev
/null
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,
131 ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev
/null
134 # Set up option flags so tests can be selective.
135 export OPTIONFLAGS
=:$
(
136 sed -nr 's/^CONFIG_//p' "$bindir/.config" |
137 sed 's/=.*//' |
xargs |
sed 's/ /:/g'
141 for applet
in $applets; do
142 # Any old-style tests for this applet?
143 if [ -d "$tsdir/$applet" ]; then
144 run_oldstyle_applet_tests
"$applet" || status
=1
147 # Is this a new-style test?
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)"
156 # echo "Running test $tsdir/$applet.tests"
157 PATH
="$LINKSDIR:$tsdir:$bindir:$PATH" \
158 "$tsdir/$applet.tests"
160 total_failed
=$
((total_failed
+ rc
))
161 test $rc -ne 0 && status
=1
165 # Leaving the dir makes it somewhat easier to run failed test by hand
168 if [ $status -ne 0 ] && [ x
"$VERBOSE" = x
]; then
169 echo "$total_failed failure(s) detected; running with -v (verbose) will give more info"