1 | #!/bin/sh |
---|
2 | |
---|
3 | [ -n "$srcdir" ] || srcdir=$(pwd) |
---|
4 | [ -n "$bindir" ] || bindir=$(dirname $(pwd)) |
---|
5 | PATH=$bindir:$PATH |
---|
6 | |
---|
7 | # Run old-style test. |
---|
8 | |
---|
9 | run_applet_testcase() |
---|
10 | { |
---|
11 | local applet=$1 |
---|
12 | local testcase=$2 |
---|
13 | |
---|
14 | local status=0 |
---|
15 | local RES= |
---|
16 | |
---|
17 | local uc_applet=$(echo $applet | tr a-z A-Z) |
---|
18 | local testname=$(basename $testcase) |
---|
19 | |
---|
20 | if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then |
---|
21 | echo UNTESTED: $testname |
---|
22 | return 0 |
---|
23 | fi |
---|
24 | |
---|
25 | if grep -q "^# FEATURE: " $testcase; then |
---|
26 | local feature=`sed -ne 's/^# FEATURE: //p' $testcase` |
---|
27 | |
---|
28 | if grep -q "^# ${feature} is not set$" $bindir/.config; then |
---|
29 | echo UNTESTED: $testname |
---|
30 | return 0 |
---|
31 | fi |
---|
32 | fi |
---|
33 | |
---|
34 | rm -rf tmp |
---|
35 | mkdir -p tmp |
---|
36 | pushd tmp > /dev/null |
---|
37 | |
---|
38 | d=$srcdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$? |
---|
39 | |
---|
40 | if [ $status -ne 0 ] ; then |
---|
41 | echo FAIL: $testname |
---|
42 | if [ $verbose -gt 0 ]; then |
---|
43 | cat .logfile.txt |
---|
44 | fi |
---|
45 | status=$? |
---|
46 | else |
---|
47 | echo PASS: $testname |
---|
48 | rm -f .logfile.txt |
---|
49 | status=$? |
---|
50 | fi |
---|
51 | |
---|
52 | popd > /dev/null |
---|
53 | rm -rf tmp |
---|
54 | |
---|
55 | return $status |
---|
56 | } |
---|
57 | |
---|
58 | run_applet_tests() |
---|
59 | { |
---|
60 | local applet=$1 |
---|
61 | |
---|
62 | local status=0 |
---|
63 | |
---|
64 | for testcase in $srcdir/$applet/*; do |
---|
65 | if [ "$testcase" = "$srcdir/$applet/CVS" ]; then |
---|
66 | continue |
---|
67 | fi |
---|
68 | |
---|
69 | if run_applet_testcase $applet $testcase; then |
---|
70 | : |
---|
71 | else |
---|
72 | status=1 |
---|
73 | fi |
---|
74 | done |
---|
75 | |
---|
76 | return $status |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | status=0 |
---|
81 | verbose=0 |
---|
82 | |
---|
83 | if [ x"$1" = x"-v" ]; then |
---|
84 | verbose=1 |
---|
85 | export VERBOSE=$verbose |
---|
86 | shift |
---|
87 | fi |
---|
88 | |
---|
89 | if [ $# -ne 0 ]; then |
---|
90 | applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done) |
---|
91 | else |
---|
92 | applets=$(ls $srcdir) |
---|
93 | fi |
---|
94 | |
---|
95 | # Populate a directory with links to all busybox applets |
---|
96 | |
---|
97 | LINKSDIR="$bindir/runtest-tempdir-links" |
---|
98 | implemented=$($bindir/busybox 2>&1 | |
---|
99 | while read line |
---|
100 | do |
---|
101 | if test x"$line" = x"Currently defined functions:" |
---|
102 | then |
---|
103 | xargs | sed 's/,//g' |
---|
104 | break |
---|
105 | fi |
---|
106 | done |
---|
107 | ) |
---|
108 | rm -rf "$LINKSDIR" 2>/dev/null |
---|
109 | mkdir "$LINKSDIR" |
---|
110 | for i in $implemented |
---|
111 | do |
---|
112 | ln -s $bindir/busybox "$LINKSDIR"/$i |
---|
113 | done |
---|
114 | |
---|
115 | # Set up option flags so tests can be selective. |
---|
116 | |
---|
117 | configfile=${bindir:-../../}/.config |
---|
118 | export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g') |
---|
119 | |
---|
120 | for applet in $applets; do |
---|
121 | if [ "$applet" = "links" ]; then continue; fi |
---|
122 | if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then |
---|
123 | if run_applet_tests $applet; then |
---|
124 | : |
---|
125 | else |
---|
126 | status=1 |
---|
127 | fi |
---|
128 | fi |
---|
129 | |
---|
130 | # Is this a new-style test? |
---|
131 | applet=$(echo "$applet" | sed -n 's/\.tests$//p') |
---|
132 | if [ ${#applet} -ne 0 ] |
---|
133 | then |
---|
134 | if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ] |
---|
135 | then |
---|
136 | echo "SKIPPED: $applet (not built)" |
---|
137 | continue |
---|
138 | fi |
---|
139 | if PATH="$LINKSDIR":$srcdir:$bindir:$PATH \ |
---|
140 | "${srcdir:-.}/$applet".tests |
---|
141 | then |
---|
142 | : |
---|
143 | else |
---|
144 | status=1 |
---|
145 | fi |
---|
146 | fi |
---|
147 | |
---|
148 | done |
---|
149 | rm -rf "$LINKSDIR" |
---|
150 | exit $status |
---|