blob: 93d5ed6e1728baa2f6437cf2fcc1b32c5f66fa00 [file] [log] [blame]
Matt Kraai38890782001-10-30 23:11:20 +00001#!/bin/sh
2
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +00003# Run one old-style test.
4# Tests are stored in applet/testcase shell scripts.
5# They are run using "sh -x -e applet/testcase".
6# Option -e will make testcase stop on the first failed command.
Denis Vlasenko018e0852007-02-25 00:40:37 +00007run_applet_testcase()
Matt Kraai38890782001-10-30 23:11:20 +00008{
9 local applet=$1
10 local testcase=$2
11
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000012 local status
Matt Kraai38890782001-10-30 23:11:20 +000013 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
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +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
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000025 echo "UNTESTED: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000026 return 0
27 fi
28 fi
29
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000030 rm -rf ".tmpdir.$applet"
31 mkdir -p ".tmpdir.$applet"
32 cd ".tmpdir.$applet" || return 1
Matt Kraai38890782001-10-30 23:11:20 +000033
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000034# echo "Running testcase $testcase"
35 d="$tsdir" sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1
36 status=$?
37 if [ $status != 0 ]; then
38 echo "FAIL: $testname"
39 if [ x"$VERBOSE" != x ]; then
40 cat "$testname.stdout.txt"
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000041 fi
Matt Kraai38890782001-10-30 23:11:20 +000042 else
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000043 echo "PASS: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000044 fi
45
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000046 cd ..
47 rm -rf ".tmpdir.$applet"
Matt Kraai38890782001-10-30 23:11:20 +000048
49 return $status
50}
51
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000052# Run all old-style tests for given applet
Denis Vlasenko018e0852007-02-25 00:40:37 +000053run_applet_tests()
Matt Kraai38890782001-10-30 23:11:20 +000054{
55 local applet=$1
Matt Kraai38890782001-10-30 23:11:20 +000056 local status=0
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000057 for testcase in $tsdir/$applet/*; do
58 if [ "$testcase" = "$tsdir/$applet/CVS" ]; then
Matt Kraai38890782001-10-30 23:11:20 +000059 continue
60 fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000061 run_applet_testcase $applet $testcase
62 test $? = 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +000063 done
Matt Kraai38890782001-10-30 23:11:20 +000064 return $status
65}
66
67
Matt Kraai38890782001-10-30 23:11:20 +000068
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000069[ -n "$tsdir" ] || tsdir=$(pwd)
70[ -n "$bindir" ] || bindir=$(dirname $(pwd))
71PATH="$bindir:$PATH"
72
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000073if [ x"$VERBOSE" = x ]; then
74 export VERBOSE=
75fi
76
Matt Kraai01d2ea92002-01-02 20:37:59 +000077if [ x"$1" = x"-v" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000078 export VERBOSE=1
Matt Kraai01d2ea92002-01-02 20:37:59 +000079 shift
80fi
81
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000082implemented=$(
83 $bindir/busybox 2>&1 |
84 while read line; do
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000085 if [ x"$line" = x"Currently defined functions:" ]; then
Denis Vlasenko018e0852007-02-25 00:40:37 +000086 xargs | sed 's/,//g'
87 break
88 fi
89 done
90 )
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000091
92applets="$implemented"
93if [ $# -ne 0 ]; then
94 applets="$@"
95fi
96
97# Populate a directory with links to all busybox applets
98
99LINKSDIR="$bindir/runtest-tempdir-links"
Rob Landley2824ded2006-03-16 16:02:06 +0000100rm -rf "$LINKSDIR" 2>/dev/null
101mkdir "$LINKSDIR"
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000102for i in $implemented; do
Rob Landley2824ded2006-03-16 16:02:06 +0000103 ln -s $bindir/busybox "$LINKSDIR"/$i
104done
105
Rob Landley48c61572005-11-07 08:50:53 +0000106# Set up option flags so tests can be selective.
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000107export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_//p' $bindir/.config | sed 's/=.*//' | xargs | sed 's/ /:/g')
Rob Landley48c61572005-11-07 08:50:53 +0000108
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000109status=0
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
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000112
113 # Any old-style tests for this applet?
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000114 if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000115 run_applet_tests "$applet"
116 test $? = 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +0000117 fi
Rob Landley48c61572005-11-07 08:50:53 +0000118
119 # Is this a new-style test?
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000120 if [ -f "${applet}.tests" ]; then
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000121 if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]; then
Rob Landley2824ded2006-03-16 16:02:06 +0000122 echo "SKIPPED: $applet (not built)"
Rob Landley48c61572005-11-07 08:50:53 +0000123 continue
124 fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000125# echo "Running test ${tsdir:-.}/${applet}.tests"
126 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" "${tsdir:-.}/${applet}.tests"
127 test $? = 0 || status=1
Rob Landley16890752005-09-02 00:41:53 +0000128 fi
Matt Kraai38890782001-10-30 23:11:20 +0000129done
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000130
131# Leaving the dir makes it somewhat easier to run failed test by hand
132#rm -rf "$LINKSDIR"
133
134if [ $status != 0 -a x"$VERBOSE" = x ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000135 echo "Failures detected, running with -v (verbose) will give more info"
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000136fi
Matt Kraai38890782001-10-30 23:11:20 +0000137exit $status