blob: fc8392ac537dacf9527e59f03d1fddf870be3c33 [file] [log] [blame]
Matt Kraai38890782001-10-30 23:11:20 +00001#!/bin/sh
2
Denis Vlasenko3b92eaa2008-02-13 14:30:33 +00003# Usage:
4# runtest [applet1] [applet2...]
5
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +00006# Run one old-style test.
7# Tests are stored in applet/testcase shell scripts.
8# They are run using "sh -x -e applet/testcase".
9# Option -e will make testcase stop on the first failed command.
Denis Vlasenko018e0852007-02-25 00:40:37 +000010run_applet_testcase()
Matt Kraai38890782001-10-30 23:11:20 +000011{
12 local applet=$1
13 local testcase=$2
14
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000015 local status
Matt Kraai38890782001-10-30 23:11:20 +000016 local uc_applet=$(echo $applet | tr a-z A-Z)
17 local testname=$(basename $testcase)
18
Eric Andersen7daa0762004-10-08 07:46:08 +000019 if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000020 echo "UNTESTED: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000021 return 0
22 fi
23
Matt Kraai6b140ea2002-02-19 23:43:08 +000024 if grep -q "^# FEATURE: " $testcase; then
25 local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
Matt Kraai38890782001-10-30 23:11:20 +000026
Eric Andersen7daa0762004-10-08 07:46:08 +000027 if grep -q "^# ${feature} is not set$" $bindir/.config; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000028 echo "UNTESTED: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000029 return 0
30 fi
31 fi
32
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000033 rm -rf ".tmpdir.$applet"
34 mkdir -p ".tmpdir.$applet"
35 cd ".tmpdir.$applet" || return 1
Matt Kraai38890782001-10-30 23:11:20 +000036
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000037# echo "Running testcase $testcase"
38 d="$tsdir" sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1
39 status=$?
40 if [ $status != 0 ]; then
41 echo "FAIL: $testname"
42 if [ x"$VERBOSE" != x ]; then
43 cat "$testname.stdout.txt"
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000044 fi
Matt Kraai38890782001-10-30 23:11:20 +000045 else
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000046 echo "PASS: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000047 fi
48
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000049 cd ..
50 rm -rf ".tmpdir.$applet"
Matt Kraai38890782001-10-30 23:11:20 +000051
52 return $status
53}
54
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000055# Run all old-style tests for given applet
Denis Vlasenko018e0852007-02-25 00:40:37 +000056run_applet_tests()
Matt Kraai38890782001-10-30 23:11:20 +000057{
58 local applet=$1
Matt Kraai38890782001-10-30 23:11:20 +000059 local status=0
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000060 for testcase in $tsdir/$applet/*; do
61 if [ "$testcase" = "$tsdir/$applet/CVS" ]; then
Matt Kraai38890782001-10-30 23:11:20 +000062 continue
63 fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000064 run_applet_testcase $applet $testcase
65 test $? = 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +000066 done
Matt Kraai38890782001-10-30 23:11:20 +000067 return $status
68}
69
70
Matt Kraai38890782001-10-30 23:11:20 +000071
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000072[ -n "$tsdir" ] || tsdir=$(pwd)
73[ -n "$bindir" ] || bindir=$(dirname $(pwd))
74PATH="$bindir:$PATH"
75
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000076if [ x"$VERBOSE" = x ]; then
77 export VERBOSE=
78fi
79
Matt Kraai01d2ea92002-01-02 20:37:59 +000080if [ x"$1" = x"-v" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000081 export VERBOSE=1
Matt Kraai01d2ea92002-01-02 20:37:59 +000082 shift
83fi
84
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000085implemented=$(
86 $bindir/busybox 2>&1 |
87 while read line; do
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000088 if [ x"$line" = x"Currently defined functions:" ]; then
Denis Vlasenko018e0852007-02-25 00:40:37 +000089 xargs | sed 's/,//g'
90 break
91 fi
92 done
93 )
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000094
95applets="$implemented"
96if [ $# -ne 0 ]; then
97 applets="$@"
98fi
99
100# Populate a directory with links to all busybox applets
101
102LINKSDIR="$bindir/runtest-tempdir-links"
Rob Landley2824ded2006-03-16 16:02:06 +0000103rm -rf "$LINKSDIR" 2>/dev/null
104mkdir "$LINKSDIR"
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000105for i in $implemented; do
Rob Landley2824ded2006-03-16 16:02:06 +0000106 ln -s $bindir/busybox "$LINKSDIR"/$i
107done
108
Rob Landley48c61572005-11-07 08:50:53 +0000109# Set up option flags so tests can be selective.
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000110export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_//p' $bindir/.config | sed 's/=.*//' | xargs | sed 's/ /:/g')
Rob Landley48c61572005-11-07 08:50:53 +0000111
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000112status=0
Matt Kraai38890782001-10-30 23:11:20 +0000113for applet in $applets; do
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000114 if [ "$applet" = "links" ]; then continue; fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000115
116 # Any old-style tests for this applet?
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000117 if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000118 run_applet_tests "$applet"
119 test $? = 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +0000120 fi
Rob Landley48c61572005-11-07 08:50:53 +0000121
122 # Is this a new-style test?
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000123 if [ -f "${applet}.tests" ]; then
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000124 if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]; then
Rob Landley2824ded2006-03-16 16:02:06 +0000125 echo "SKIPPED: $applet (not built)"
Rob Landley48c61572005-11-07 08:50:53 +0000126 continue
127 fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000128# echo "Running test ${tsdir:-.}/${applet}.tests"
129 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" "${tsdir:-.}/${applet}.tests"
130 test $? = 0 || status=1
Rob Landley16890752005-09-02 00:41:53 +0000131 fi
Matt Kraai38890782001-10-30 23:11:20 +0000132done
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000133
134# Leaving the dir makes it somewhat easier to run failed test by hand
135#rm -rf "$LINKSDIR"
136
137if [ $status != 0 -a x"$VERBOSE" = x ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000138 echo "Failures detected, running with -v (verbose) will give more info"
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000139fi
Matt Kraai38890782001-10-30 23:11:20 +0000140exit $status