- use proper macros to print intmax_t.
[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 old-style test.
8
9 function 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
39
40         if [ $? != 0 ] ; then
41                 echo FAIL: $testname
42                 if [ $verbose -gt 0 ]; then
43                         cat .logfile.txt
44                         #exit 1;
45                 fi;
46                 status=$?
47         else
48                 echo PASS: $testname
49                 rm -f .logfile.txt
50                 status=$?
51         fi
52
53         popd >/dev/null
54         rm -rf tmp
55
56         return $status
57 }
58
59 run_applet_tests ()
60 {
61         local applet=$1
62
63         local status=0
64
65         for testcase in $srcdir/$applet/*; do
66                 if [ "$testcase" = "$srcdir/$applet/CVS" ]; then
67                         continue
68                 fi
69
70                 if run_applet_testcase $applet $testcase; then
71                         :
72                 else
73                         status=1
74                 fi
75         done
76
77         return $status
78 }
79
80
81 status=0
82 verbose=0
83
84 if [ x"$1" = x"-v" ]; then
85         verbose=1
86         export VERBOSE=$verbose
87         shift
88 fi
89
90 if [ $# -ne 0 ]; then
91         applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done)
92 else
93         applets=$(ls $srcdir)
94 fi
95
96 # Populate a directory with links to all busybox applets
97
98 LINKSDIR="${bindir}/runtest-tempdir-links"
99 rm -rf "$LINKSDIR" 2>/dev/null
100 mkdir "$LINKSDIR"
101 for i in $(sed 's@/[a-z0-9/\[]*/@@' $bindir/busybox.links 2>/dev/null)
102 do
103         ln -s $bindir/busybox "$LINKSDIR"/$i
104 done
105
106 # Set up option flags so tests can be selective.
107
108 configfile=${bindir:-../../}/.config
109 export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g')
110
111 for applet in $applets; do
112         if [ "$applet" = "links" ]; then continue; fi
113         if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then
114                 if run_applet_tests $applet; then
115                         :
116                 else
117                         status=1
118                 fi
119         fi
120
121         # Is this a new-style test?
122         applet=$(echo "$applet" | sed -n 's/\.tests$//p')
123         if [ ${#applet} -ne 0 ]
124         then
125                 if [ ! -h "$LINKSDIR/$applet" ] && [ ${applet:0:4} != "all_" ]
126                 then
127                         echo "SKIPPED: $applet (not built)"
128                         continue
129                 fi
130                 PATH="$LINKSDIR":$srcdir:$bindir:$PATH \
131                         "${srcdir:-.}/$applet".tests
132                 if [ $? -ne 0 ]; then status=1; fi
133         fi
134
135 done
136 rm -rf "$LINKSDIR"
137 exit $status