f57f464ee789384a1a9dffd450d0c2171b569019
[oweals/busybox.git] / testsuite / runtest
1 #!/bin/sh
2
3 PATH=$(dirname $(pwd)):$PATH
4
5 show_result ()
6 {
7         local resolution=$1
8         local testcase=$2
9         local status=0
10
11         if [ $resolution = XPASS -o $resolution = FAIL ]; then
12                 status=1
13         fi
14
15         if [ "$verbose" -o $status -eq 1 ]; then
16                 echo "$resolution: $testcase"
17         fi
18
19         return $status
20 }
21
22 run_applet_testcase ()
23 {
24         local applet=$1
25         local testcase=$2
26
27         local status=0
28         local X=
29         local RES=
30
31         local uc_applet=$(echo $applet | tr a-z A-Z)
32         local testname=$(basename $testcase)
33
34         if grep -q "^# CONFIG_${uc_applet} is not set$" ../.config; then
35                 show_result UNTESTED $testname
36                 return 0
37         fi
38
39         if grep -q "^# FEATURE: " $testcase; then
40                 local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
41
42                 if grep -q "^# ${feature} is not set$" ../.config; then
43                         show_result UNTESTED $testname
44                         return 0
45                 fi
46         fi
47
48         if grep -q "^# XFAIL$" $testcase; then
49                 X=X
50         fi
51
52         rm -rf tmp
53         mkdir -p tmp
54         pushd tmp >/dev/null
55
56         sh -x -e ../$testcase >.logfile.txt 2>&1
57
58         if [ $? != 0 ] ; then
59                 show_result ${X}FAIL $testname
60                 if [ "$verbose" == 1 ]; then
61                         cat .logfile.txt
62                         exit 1;
63                 fi;
64                 status=$?
65         else
66                 show_result ${X}PASS $testname
67                 rm -f .logfile.txt
68                 status=$?
69         fi
70
71         popd >/dev/null
72         rm -rf tmp
73
74         return $status
75 }
76
77 run_applet_tests ()
78 {
79         local applet=$1
80
81         local status=0
82
83         for testcase in $applet/*; do
84                 if [ "$testcase" = "$applet/CVS" ]; then
85                         continue
86                 fi
87
88                 if run_applet_testcase $applet $testcase; then
89                         :
90                 else
91                         status=1
92                 fi
93         done
94
95         return $status
96 }
97
98
99 status=0
100
101 if [ x"$1" = x"-v" ]; then
102         verbose=1
103         shift
104 fi
105
106 if [ $# -ne 0 ]; then
107         applets="$@"
108 else
109         applets="*"
110 fi
111
112 for applet in $applets; do
113         if [ "$applet" != CVS -a -d "$applet" ]; then
114                 if run_applet_tests $applet; then
115                         :
116                 else
117                         status=1
118                 fi
119         fi
120 done
121
122 exit $status