blob: c1b1ec2f4ce5e59be5c66a21fde8ec923005264a [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
7run_applet_testcase ()
8{
9 local applet=$1
10 local testcase=$2
11
12 local status=0
Eric Andersenc354f6e2004-04-06 00:41:39 +000013 local RES=
Matt Kraai38890782001-10-30 23:11:20 +000014
15 local uc_applet=$(echo $applet | tr a-z A-Z)
16 local testname=$(basename $testcase)
17
Eric Andersen7daa0762004-10-08 07:46:08 +000018 if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
Eric Andersen650fe632004-04-06 11:10:30 +000019 echo UNTESTED: $testname
Matt Kraai38890782001-10-30 23:11:20 +000020 return 0
21 fi
22
Matt Kraai6b140ea2002-02-19 23:43:08 +000023 if grep -q "^# FEATURE: " $testcase; then
24 local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
Matt Kraai38890782001-10-30 23:11:20 +000025
Eric Andersen7daa0762004-10-08 07:46:08 +000026 if grep -q "^# ${feature} is not set$" $bindir/.config; then
Eric Andersen650fe632004-04-06 11:10:30 +000027 echo UNTESTED: $testname
Matt Kraai38890782001-10-30 23:11:20 +000028 return 0
29 fi
30 fi
31
Eric Andersenc354f6e2004-04-06 00:41:39 +000032 rm -rf tmp
33 mkdir -p tmp
Matt Kraai38890782001-10-30 23:11:20 +000034 pushd tmp >/dev/null
35
Eric Andersen7daa0762004-10-08 07:46:08 +000036 d=$srcdir sh -x -e $testcase >.logfile.txt 2>&1
Eric Andersenc354f6e2004-04-06 00:41:39 +000037
38 if [ $? != 0 ] ; then
Eric Andersen650fe632004-04-06 11:10:30 +000039 echo FAIL: $testname
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000040 if [ $verbose -gt 0 ]; then
Eric Andersenc354f6e2004-04-06 00:41:39 +000041 cat .logfile.txt
Eric Andersen650fe632004-04-06 11:10:30 +000042 #exit 1;
Eric Andersenc354f6e2004-04-06 00:41:39 +000043 fi;
Matt Kraai35d60422002-03-27 17:33:31 +000044 status=$?
Matt Kraai38890782001-10-30 23:11:20 +000045 else
Eric Andersen650fe632004-04-06 11:10:30 +000046 echo PASS: $testname
Eric Andersenc354f6e2004-04-06 00:41:39 +000047 rm -f .logfile.txt
Matt Kraai35d60422002-03-27 17:33:31 +000048 status=$?
Matt Kraai38890782001-10-30 23:11:20 +000049 fi
50
51 popd >/dev/null
52 rm -rf tmp
53
54 return $status
55}
56
57run_applet_tests ()
58{
59 local applet=$1
60
61 local status=0
62
Eric Andersen7daa0762004-10-08 07:46:08 +000063 for testcase in $srcdir/$applet/*; do
64 if [ "$testcase" = "$srcdir/$applet/CVS" ]; then
Matt Kraai38890782001-10-30 23:11:20 +000065 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
79status=0
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000080verbose=0
Matt Kraai38890782001-10-30 23:11:20 +000081
Matt Kraai01d2ea92002-01-02 20:37:59 +000082if [ x"$1" = x"-v" ]; then
83 verbose=1
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000084 export VERBOSE=$verbose
Matt Kraai01d2ea92002-01-02 20:37:59 +000085 shift
86fi
87
Matt Kraai38890782001-10-30 23:11:20 +000088if [ $# -ne 0 ]; then
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000089 applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done)
Matt Kraai38890782001-10-30 23:11:20 +000090else
Eric Andersen7daa0762004-10-08 07:46:08 +000091 applets=$(ls $srcdir)
Matt Kraai38890782001-10-30 23:11:20 +000092fi
93
Rob Landley48c61572005-11-07 08:50:53 +000094# Set up option flags so tests can be selective.
95
96configfile=${bindir:-../../}/.config
97export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/')
98
Matt Kraai38890782001-10-30 23:11:20 +000099for applet in $applets; do
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000100 if [ "$applet" = "links" ]; then continue; fi
101 if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then
Matt Kraai38890782001-10-30 23:11:20 +0000102 if run_applet_tests $applet; then
103 :
104 else
105 status=1
106 fi
107 fi
Rob Landley48c61572005-11-07 08:50:53 +0000108
109 # Is this a new-style test?
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000110 applet=$(echo "$applet" | sed -n 's/\.tests$//p')
111 if [ ${#applet} -ne 0 ]
Rob Landley16890752005-09-02 00:41:53 +0000112 then
Rob Landley48c61572005-11-07 08:50:53 +0000113 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.
Bernhard Reutner-Fischer23bc6472005-09-23 17:42:33 +0000120 if [ -d links ]; then
121 rm -f links/"$applet"
122 else
123 mkdir links 2> /dev/null
124 fi
Rob Landley52d2f4b2005-09-20 18:19:34 +0000125 ln -s ${bindir:-../..}/busybox links/"$applet"
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000126 PATH="$srcdir:$PATH" COMMAND="links/$applet" \
127 "${srcdir:-.}/$applet".tests
Rob Landley16890752005-09-02 00:41:53 +0000128 if [ $? -ne 0 ]; then status=1; fi
129 fi
130
Matt Kraai38890782001-10-30 23:11:20 +0000131done
Bernhard Reutner-Fischer23bc6472005-09-23 17:42:33 +0000132rm -f links/*
133rmdir links
Matt Kraai38890782001-10-30 23:11:20 +0000134exit $status