source: MondoRescue/branches/3.2/mindi-busybox/testsuite/runtest

Last change on this file was 3232, checked in by Bruno Cornec, 10 years ago
  • Update mindi-busybox to 1.21.1
  • Property svn:executable set to *
File size: 3.9 KB
Line 
1#!/bin/sh
2# Usage:
3# runtest [applet1] [applet2...]
4
5. ./testing.sh
6
7total_failed=0
8
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.
13run_applet_testcase()
14{
15 local applet="$1"
16 local testcase="$2"
17
18 local status=0
19 local uc_applet=$(echo "$applet" | tr a-z A-Z)
20 local testname="$testcase"
21
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
26 fi
27
28 if grep "^# FEATURE: " "$testcase" >/dev/null; then
29 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
30
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
35 fi
36 done
37 fi
38
39 rm -rf ".tmpdir.$applet"
40 mkdir -p ".tmpdir.$applet"
41 cd ".tmpdir.$applet" || return 1
42
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"
50 fi
51 else
52 echo "PASS: $testname"
53 fi
54
55 cd ..
56 rm -rf ".tmpdir.$applet"
57
58 return $status
59}
60
61# Run all old-style tests for given applet
62run_oldstyle_applet_tests()
63{
64 local applet="$1"
65 local status=0
66
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))
80 }
81 done
82 return $status
83}
84
85
86
87lcwd=$(pwd)
88[ x"$tsdir" != x"" ] || tsdir="$lcwd"
89[ x"$bindir" != x"" ] || bindir="${lcwd%/*}" # one directory up from $lcwd
90PATH="$bindir:$PATH"
91export bindir # some tests need to look at $bindir/.config
92
93if [ x"$VERBOSE" = x ]; then
94 export VERBOSE=
95fi
96
97if [ x"$1" = x"-v" ]; then
98 export VERBOSE=1
99 shift
100fi
101
102implemented=$(
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
109 fi
110 done
111 )
112
113applets="$implemented"
114if [ $# -ne 0 ]; then
115 applets="$@"
116fi
117
118# Populate a directory with links to all busybox applets
119
120LINKSDIR="$bindir/runtest-tempdir-links"
121
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:
124rm -rf "$LINKSDIR" 2>/dev/null
125
126mkdir "$LINKSDIR" 2>/dev/null
127for 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
132done
133
134# Set up option flags so tests can be selective.
135export OPTIONFLAGS=:$(
136 sed -nr 's/^CONFIG_//p' "$bindir/.config" |
137 sed 's/=.*//' | xargs | sed 's/ /:/g'
138 ):
139
140status=0
141for 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
145 fi
146
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
154 fi
155 fi
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
162 fi
163done
164
165# Leaving the dir makes it somewhat easier to run failed test by hand
166#rm -rf "$LINKSDIR"
167
168if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then
169 echo "$total_failed failure(s) detected; running with -v (verbose) will give more info"
170fi
171exit $status
Note: See TracBrowser for help on using the repository browser.