blob: 84cd6a7f3f879afef9798dd66ae474a0c174bd05 [file] [log] [blame]
Matt Kraai38890782001-10-30 23:11:20 +00001#!/bin/sh
2
Eric Andersen7daa0762004-10-08 07:46:08 +00003[ -n "$srcdir" ] || srcdir=$(pwd)
4[ -n "$bindir" ] || bindir=$(dirname $(pwd))
5PATH=$bindir:$PATH
Matt Kraai38890782001-10-30 23:11:20 +00006
Rob Landley2824ded2006-03-16 16:02:06 +00007# Run old-style test.
8
9function run_applet_testcase
Matt Kraai38890782001-10-30 23:11:20 +000010{
11 local applet=$1
12 local testcase=$2
13
14 local status=0
Eric Andersenc354f6e2004-04-06 00:41:39 +000015 local RES=
Matt Kraai38890782001-10-30 23:11:20 +000016
17 local uc_applet=$(echo $applet | tr a-z A-Z)
18 local testname=$(basename $testcase)
19
Eric Andersen7daa0762004-10-08 07:46:08 +000020 if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
Eric Andersen650fe632004-04-06 11:10:30 +000021 echo UNTESTED: $testname
Matt Kraai38890782001-10-30 23:11:20 +000022 return 0
23 fi
24
Matt Kraai6b140ea2002-02-19 23:43:08 +000025 if grep -q "^# FEATURE: " $testcase; then
26 local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
Matt Kraai38890782001-10-30 23:11:20 +000027
Eric Andersen7daa0762004-10-08 07:46:08 +000028 if grep -q "^# ${feature} is not set$" $bindir/.config; then
Eric Andersen650fe632004-04-06 11:10:30 +000029 echo UNTESTED: $testname
Matt Kraai38890782001-10-30 23:11:20 +000030 return 0
31 fi
32 fi
33
Eric Andersenc354f6e2004-04-06 00:41:39 +000034 rm -rf tmp
35 mkdir -p tmp
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000036 pushd tmp > /dev/null
Matt Kraai38890782001-10-30 23:11:20 +000037
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000038 d=$srcdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$?
Eric Andersenc354f6e2004-04-06 00:41:39 +000039
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000040 if [ $status -ne 0 ] ; then
Eric Andersen650fe632004-04-06 11:10:30 +000041 echo FAIL: $testname
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000042 if [ $verbose -gt 0 ]; then
Eric Andersenc354f6e2004-04-06 00:41:39 +000043 cat .logfile.txt
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000044 fi
Matt Kraai35d60422002-03-27 17:33:31 +000045 status=$?
Matt Kraai38890782001-10-30 23:11:20 +000046 else
Eric Andersen650fe632004-04-06 11:10:30 +000047 echo PASS: $testname
Eric Andersenc354f6e2004-04-06 00:41:39 +000048 rm -f .logfile.txt
Matt Kraai35d60422002-03-27 17:33:31 +000049 status=$?
Matt Kraai38890782001-10-30 23:11:20 +000050 fi
51
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000052 popd > /dev/null
Matt Kraai38890782001-10-30 23:11:20 +000053 rm -rf tmp
54
55 return $status
56}
57
58run_applet_tests ()
59{
60 local applet=$1
61
62 local status=0
63
Eric Andersen7daa0762004-10-08 07:46:08 +000064 for testcase in $srcdir/$applet/*; do
65 if [ "$testcase" = "$srcdir/$applet/CVS" ]; then
Matt Kraai38890782001-10-30 23:11:20 +000066 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
80status=0
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000081verbose=0
Matt Kraai38890782001-10-30 23:11:20 +000082
Matt Kraai01d2ea92002-01-02 20:37:59 +000083if [ x"$1" = x"-v" ]; then
84 verbose=1
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000085 export VERBOSE=$verbose
Matt Kraai01d2ea92002-01-02 20:37:59 +000086 shift
87fi
88
Matt Kraai38890782001-10-30 23:11:20 +000089if [ $# -ne 0 ]; then
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000090 applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done)
Matt Kraai38890782001-10-30 23:11:20 +000091else
Eric Andersen7daa0762004-10-08 07:46:08 +000092 applets=$(ls $srcdir)
Matt Kraai38890782001-10-30 23:11:20 +000093fi
94
Rob Landley2824ded2006-03-16 16:02:06 +000095# Populate a directory with links to all busybox applets
96
97LINKSDIR="${bindir}/runtest-tempdir-links"
98rm -rf "$LINKSDIR" 2>/dev/null
99mkdir "$LINKSDIR"
Mike Frysinger2cf38522006-04-01 01:35:33 +0000100for i in $(sed 's@/[a-z0-9/\[]*/@@' $bindir/busybox.links 2>/dev/null)
Rob Landley2824ded2006-03-16 16:02:06 +0000101do
102 ln -s $bindir/busybox "$LINKSDIR"/$i
103done
104
Rob Landley48c61572005-11-07 08:50:53 +0000105# Set up option flags so tests can be selective.
106
107configfile=${bindir:-../../}/.config
Rob Landley5c1cd5f2006-02-16 09:25:31 +0000108export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g')
Rob Landley48c61572005-11-07 08:50:53 +0000109
Matt Kraai38890782001-10-30 23:11:20 +0000110for applet in $applets; do
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000111 if [ "$applet" = "links" ]; then continue; fi
112 if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then
Matt Kraai38890782001-10-30 23:11:20 +0000113 if run_applet_tests $applet; then
114 :
115 else
116 status=1
117 fi
118 fi
Rob Landley48c61572005-11-07 08:50:53 +0000119
120 # Is this a new-style test?
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000121 applet=$(echo "$applet" | sed -n 's/\.tests$//p')
122 if [ ${#applet} -ne 0 ]
Rob Landley16890752005-09-02 00:41:53 +0000123 then
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +0000124 if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]
Rob Landley48c61572005-11-07 08:50:53 +0000125 then
Rob Landley2824ded2006-03-16 16:02:06 +0000126 echo "SKIPPED: $applet (not built)"
Rob Landley48c61572005-11-07 08:50:53 +0000127 continue
128 fi
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +0000129 if PATH="$LINKSDIR":$srcdir:$bindir:$PATH \
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000130 "${srcdir:-.}/$applet".tests
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +0000131 then
132 :
133 else
134 status=1
135 fi
Rob Landley16890752005-09-02 00:41:53 +0000136 fi
137
Matt Kraai38890782001-10-30 23:11:20 +0000138done
Rob Landley2824ded2006-03-16 16:02:06 +0000139rm -rf "$LINKSDIR"
Matt Kraai38890782001-10-30 23:11:20 +0000140exit $status