blob: 0f081f9a5fd0ec3acd5eb74edc6b873683fd0e23 [file] [log] [blame]
Matt Kraai38890782001-10-30 23:11:20 +00001#!/bin/sh
2
Rob Landley2824ded2006-03-16 16:02:06 +00003# Run old-style test.
4
Denis Vlasenko018e0852007-02-25 00:40:37 +00005run_applet_testcase()
Matt Kraai38890782001-10-30 23:11:20 +00006{
7 local applet=$1
8 local testcase=$2
9
10 local status=0
Eric Andersenc354f6e2004-04-06 00:41:39 +000011 local RES=
Matt Kraai38890782001-10-30 23:11:20 +000012
13 local uc_applet=$(echo $applet | tr a-z A-Z)
14 local testname=$(basename $testcase)
15
Eric Andersen7daa0762004-10-08 07:46:08 +000016 if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
Eric Andersen650fe632004-04-06 11:10:30 +000017 echo UNTESTED: $testname
Matt Kraai38890782001-10-30 23:11:20 +000018 return 0
19 fi
20
Matt Kraai6b140ea2002-02-19 23:43:08 +000021 if grep -q "^# FEATURE: " $testcase; then
22 local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
Matt Kraai38890782001-10-30 23:11:20 +000023
Eric Andersen7daa0762004-10-08 07:46:08 +000024 if grep -q "^# ${feature} is not set$" $bindir/.config; then
Eric Andersen650fe632004-04-06 11:10:30 +000025 echo UNTESTED: $testname
Matt Kraai38890782001-10-30 23:11:20 +000026 return 0
27 fi
28 fi
29
Eric Andersenc354f6e2004-04-06 00:41:39 +000030 rm -rf tmp
31 mkdir -p tmp
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000032 pushd tmp > /dev/null
Matt Kraai38890782001-10-30 23:11:20 +000033
Denis Vlasenko6446c2d2007-11-25 04:54:13 +000034# echo Running testcase $testcase
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000035 d=$tsdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$?
Eric Andersenc354f6e2004-04-06 00:41:39 +000036
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000037 if [ $status -ne 0 ]; then
Eric Andersen650fe632004-04-06 11:10:30 +000038 echo FAIL: $testname
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000039 if [ $verbose -gt 0 ]; then
Eric Andersenc354f6e2004-04-06 00:41:39 +000040 cat .logfile.txt
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000041 fi
Matt Kraai35d60422002-03-27 17:33:31 +000042 status=$?
Matt Kraai38890782001-10-30 23:11:20 +000043 else
Eric Andersen650fe632004-04-06 11:10:30 +000044 echo PASS: $testname
Eric Andersenc354f6e2004-04-06 00:41:39 +000045 rm -f .logfile.txt
Matt Kraai35d60422002-03-27 17:33:31 +000046 status=$?
Matt Kraai38890782001-10-30 23:11:20 +000047 fi
48
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000049 popd > /dev/null
Matt Kraai38890782001-10-30 23:11:20 +000050 rm -rf tmp
51
52 return $status
53}
54
Denis Vlasenko018e0852007-02-25 00:40:37 +000055run_applet_tests()
Matt Kraai38890782001-10-30 23:11:20 +000056{
57 local applet=$1
58
59 local status=0
60
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000061 for testcase in $tsdir/$applet/*; do
62 if [ "$testcase" = "$tsdir/$applet/CVS" ]; then
Matt Kraai38890782001-10-30 23:11:20 +000063 continue
64 fi
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000065 if ! run_applet_testcase $applet $testcase; then
Matt Kraai38890782001-10-30 23:11:20 +000066 status=1
67 fi
68 done
69
70 return $status
71}
72
73
74status=0
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000075verbose=0
Matt Kraai38890782001-10-30 23:11:20 +000076
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000077[ -n "$tsdir" ] || tsdir=$(pwd)
78[ -n "$bindir" ] || bindir=$(dirname $(pwd))
79PATH="$bindir:$PATH"
80
Matt Kraai01d2ea92002-01-02 20:37:59 +000081if [ x"$1" = x"-v" ]; then
82 verbose=1
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000083 export VERBOSE=$verbose
Matt Kraai01d2ea92002-01-02 20:37:59 +000084 shift
85fi
86
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000087implemented=$(
88 $bindir/busybox 2>&1 |
89 while read line; do
90 if test x"$line" = x"Currently defined functions:"; then
Denis Vlasenko018e0852007-02-25 00:40:37 +000091 xargs | sed 's/,//g'
92 break
93 fi
94 done
95 )
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000096
97applets="$implemented"
98if [ $# -ne 0 ]; then
99 applets="$@"
100fi
101
102# Populate a directory with links to all busybox applets
103
104LINKSDIR="$bindir/runtest-tempdir-links"
Rob Landley2824ded2006-03-16 16:02:06 +0000105rm -rf "$LINKSDIR" 2>/dev/null
106mkdir "$LINKSDIR"
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000107for i in $implemented; do
Rob Landley2824ded2006-03-16 16:02:06 +0000108 ln -s $bindir/busybox "$LINKSDIR"/$i
109done
110
Rob Landley48c61572005-11-07 08:50:53 +0000111# Set up option flags so tests can be selective.
112
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000113configfile=${bindir}/.config
114export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile | xargs | sed 's/ /:/g')
Rob Landley48c61572005-11-07 08:50:53 +0000115
Matt Kraai38890782001-10-30 23:11:20 +0000116for applet in $applets; do
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000117 if [ "$applet" = "links" ]; then continue; fi
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000118 if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then
119 if ! run_applet_tests $applet; then
Matt Kraai38890782001-10-30 23:11:20 +0000120 status=1
121 fi
122 fi
Rob Landley48c61572005-11-07 08:50:53 +0000123
124 # Is this a new-style test?
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000125 if [ -f ${applet}.tests ]; then
126 if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]; then
Rob Landley2824ded2006-03-16 16:02:06 +0000127 echo "SKIPPED: $applet (not built)"
Rob Landley48c61572005-11-07 08:50:53 +0000128 continue
129 fi
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000130 if PATH="$LINKSDIR":$tsdir:$bindir:$PATH \
131 "${tsdir:-.}/$applet".tests
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +0000132 then
Denis Vlasenko018e0852007-02-25 00:40:37 +0000133 :
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +0000134 else
Denis Vlasenko018e0852007-02-25 00:40:37 +0000135 status=1
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +0000136 fi
Rob Landley16890752005-09-02 00:41:53 +0000137 fi
138
Matt Kraai38890782001-10-30 23:11:20 +0000139done
Rob Landley2824ded2006-03-16 16:02:06 +0000140rm -rf "$LINKSDIR"
Matt Kraai38890782001-10-30 23:11:20 +0000141exit $status