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