Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / testsuite / runtest
blob51575d9260b2e3935c837cd4da5d37468076010d
1 #!/bin/sh
2 # Usage:
3 # runtest [applet1] [applet2...]
5 . ./testing.sh
7 total_failed=0
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.
13 run_applet_testcase()
15 local applet="$1"
16 local testcase="$2"
18 local status=0
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"
25 return 0
28 if grep "^# FEATURE: " "$testcase" >/dev/null; then
29 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
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
36 done
39 rm -rf ".tmpdir.$applet"
40 mkdir -p ".tmpdir.$applet"
41 cd ".tmpdir.$applet" || return 1
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"
51 else
52 echo "PASS: $testname"
55 cd ..
56 rm -rf ".tmpdir.$applet"
58 return $status
61 # Run all old-style tests for given applet
62 run_oldstyle_applet_tests()
64 local applet="$1"
65 local status=0
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" || {
78 status=1
79 total_failed=$((total_failed + 1))
81 done
82 return $status
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
93 if [ x"$VERBOSE" = x ]; then
94 export VERBOSE=
97 if [ x"$1" = x"-v" ]; then
98 export VERBOSE=1
99 shift
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
110 done
113 applets="$implemented"
114 if [ $# -ne 0 ]; then
115 applets="$@"
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,
130 # not an applet.
131 ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null
132 done
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'
140 status=0
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)"
153 continue
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
163 done
165 # Leaving the dir makes it somewhat easier to run failed test by hand
166 #rm -rf "$LINKSDIR"
168 if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then
169 echo "$total_failed failure(s) detected; running with -v (verbose) will give more info"
171 exit $status