Tomato 1.28
[tomato.git] / release / src / router / busybox / testsuite / runtest
blobcade871a2204b5bd45bea49f2b3d8624f2bd5445
1 #!/bin/sh
3 # Usage:
4 # runtest [applet1] [applet2...]
6 # Helper for helpers. Oh my...
7 test x"$ECHO" != x"" || {
8 ECHO="echo"
9 test x"`echo -ne`" = x"" || {
10 # Compile and use a replacement 'echo' which understands -e -n
11 ECHO="$PWD/echo-ne"
12 test -x "$ECHO" || {
13 gcc -Os -o "$ECHO" ../scripts/echo.c || exit 1
16 export ECHO
19 # Run one old-style test.
20 # Tests are stored in applet/testcase shell scripts.
21 # They are run using "sh -x -e applet/testcase".
22 # Option -e will make testcase stop on the first failed command.
23 run_applet_testcase()
25 local applet="$1"
26 local testcase="$2"
28 local status=0
29 local uc_applet=$(echo "$applet" | tr a-z A-Z)
30 local testname="$testcase"
32 testname="${testname##*/}" # take basename
33 if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then
34 echo "UNTESTED: $testname"
35 return 0
38 if grep "^# FEATURE: " "$testcase" >/dev/null; then
39 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
41 if grep "^# $feature is not set$" "$bindir/.config" >/dev/null; then
42 echo "UNTESTED: $testname"
43 return 0
47 rm -rf ".tmpdir.$applet"
48 mkdir -p ".tmpdir.$applet"
49 cd ".tmpdir.$applet" || return 1
51 # echo "Running testcase $testcase"
52 d="$tsdir" \
53 sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1 || status=$?
54 if [ $status -ne 0 ]; then
55 echo "FAIL: $testname"
56 if [ x"$VERBOSE" != x ]; then
57 cat "$testname.stdout.txt"
59 else
60 echo "PASS: $testname"
63 cd ..
64 rm -rf ".tmpdir.$applet"
66 return $status
69 # Run all old-style tests for given applet
70 run_oldstyle_applet_tests()
72 local applet="$1"
73 local status=0
75 for testcase in "$tsdir/$applet"/*; do
76 # switch on basename of $testcase
77 case "${testcase##*/}" in
78 .*) continue ;; # .svn, .git etc
79 *~) continue ;; # backup files
80 "CVS") continue ;;
81 \#*) continue ;; # CVS merge residues
82 *.mine) continue ;; # svn-produced junk
83 *.r[0-9]*) continue ;; # svn-produced junk
84 esac
85 run_applet_testcase "$applet" "$testcase" || status=1
86 done
87 return $status
92 lcwd=$(pwd)
93 [ x"$tsdir" != x ] || tsdir="$lcwd"
94 [ x"$bindir" != x ] || bindir="${lcwd%/*}" # one directory up from $lcwd
95 PATH="$bindir:$PATH"
97 if [ x"$VERBOSE" = x ]; then
98 export VERBOSE=
101 if [ x"$1" = x"-v" ]; then
102 export VERBOSE=1
103 shift
106 implemented=$(
107 "$bindir/busybox" 2>&1 |
108 while read line; do
109 if [ x"$line" = x"Currently defined functions:" ]; then
110 xargs | sed 's/,//g'
111 break
113 done
116 applets="$implemented"
117 if [ $# -ne 0 ]; then
118 applets="$@"
121 # Populate a directory with links to all busybox applets
123 LINKSDIR="$bindir/runtest-tempdir-links"
124 rm -rf "$LINKSDIR" 2>/dev/null
125 mkdir "$LINKSDIR"
126 for i in $implemented; do
127 ln -s "$bindir/busybox" "$LINKSDIR/$i"
128 done
130 # Set up option flags so tests can be selective.
131 export OPTIONFLAGS=:$(
132 sed -nr 's/^CONFIG_//p' "$bindir/.config" |
133 sed 's/=.*//' | xargs | sed 's/ /:/g'
136 status=0
137 for applet in $applets; do
138 # Any old-style tests for this applet?
139 if [ -d "$tsdir/$applet" ]; then
140 run_oldstyle_applet_tests "$applet" || status=1
143 # Is this a new-style test?
144 if [ -f "$applet.tests" ]; then
145 if [ ! -h "$LINKSDIR/$applet" ]; then
146 # (avoiding bash'ism "${applet:0:4}")
147 if ! echo "$applet" | grep "^all_" >/dev/null; then
148 echo "SKIPPED: $applet (not built)"
149 continue
152 # echo "Running test $tsdir/$applet.tests"
153 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" \
154 "$tsdir/$applet.tests" || status=1
156 done
158 # Leaving the dir makes it somewhat easier to run failed test by hand
159 #rm -rf "$LINKSDIR"
161 if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then
162 echo "Failures detected, running with -v (verbose) will give more info"
164 exit $status