blob: 7e0c771e728081622db62e1f1027a3ca7e240001 [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{
Denis Vlasenko95842fb2008-04-25 08:43:01 +000012 local applet="$1"
Denis Vlasenko58dc2742008-04-23 06:45:11 +000013 local testcase="$2"
Matt Kraai38890782001-10-30 23:11:20 +000014
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000015 local status
Denis Vlasenko92a6f872008-04-27 03:33:29 +000016 local uc_applet=$(echo "$applet" | tr a-z A-Z)
17 local testname="$testcase"
Matt Kraai38890782001-10-30 23:11:20 +000018
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +000019 testname="${testname##*/}" # take basename
20 if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000021 echo "UNTESTED: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000022 return 0
23 fi
24
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +000025 if grep "^# FEATURE: " "$testcase" >/dev/null; then
Denis Vlasenko95842fb2008-04-25 08:43:01 +000026 local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase")
Matt Kraai38890782001-10-30 23:11:20 +000027
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +000028 if grep "^# $feature is not set$" "$bindir/.config" >/dev/null; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000029 echo "UNTESTED: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000030 return 0
31 fi
32 fi
33
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000034 rm -rf ".tmpdir.$applet"
35 mkdir -p ".tmpdir.$applet"
36 cd ".tmpdir.$applet" || return 1
Matt Kraai38890782001-10-30 23:11:20 +000037
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000038# echo "Running testcase $testcase"
39 d="$tsdir" sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1
40 status=$?
Denis Vlasenko64d5bfd2008-04-26 10:14:25 +000041 if [ $status -ne 0 ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000042 echo "FAIL: $testname"
43 if [ x"$VERBOSE" != x ]; then
44 cat "$testname.stdout.txt"
Bernhard Reutner-Fischer89a22ea2006-05-25 13:24:02 +000045 fi
Matt Kraai38890782001-10-30 23:11:20 +000046 else
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000047 echo "PASS: $testname"
Matt Kraai38890782001-10-30 23:11:20 +000048 fi
49
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000050 cd ..
51 rm -rf ".tmpdir.$applet"
Matt Kraai38890782001-10-30 23:11:20 +000052
53 return $status
54}
55
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000056# Run all old-style tests for given applet
Denis Vlasenko3c07e4b2008-04-29 14:11:57 +000057run_oldstyle_applet_tests()
Matt Kraai38890782001-10-30 23:11:20 +000058{
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +000059 local applet="$1"
Matt Kraai38890782001-10-30 23:11:20 +000060 local status=0
Denis Vlasenko92a6f872008-04-27 03:33:29 +000061
62 for testcase in "$tsdir/$applet"/*; do
63 # switch on basename of $testcase
64 case "${testcase##*/}" in
Denis Vlasenko58dc2742008-04-23 06:45:11 +000065 \#*)
66 continue
67 ;;
68 *\~)
69 continue
70 ;;
Denis Vlasenko3c07e4b2008-04-29 14:11:57 +000071 "CVS")
72 continue
73 ;;
74 .*)
75 continue
76 ;;
Denis Vlasenko58dc2742008-04-23 06:45:11 +000077 esac
Denis Vlasenko58dc2742008-04-23 06:45:11 +000078 run_applet_testcase "$applet" "$testcase"
Denis Vlasenko64d5bfd2008-04-26 10:14:25 +000079 test $? -eq 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +000080 done
Matt Kraai38890782001-10-30 23:11:20 +000081 return $status
82}
83
84
Matt Kraai38890782001-10-30 23:11:20 +000085
Denis Vlasenko92a6f872008-04-27 03:33:29 +000086lcwd=$(pwd)
Denis Vlasenko7dff4332008-04-27 20:48:49 +000087[ x"$tsdir" != x ] || tsdir="$lcwd"
88[ x"$bindir" != x ] || bindir="${lcwd%/*}" # one directory up from $lcwd
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000089PATH="$bindir:$PATH"
90
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000091if [ x"$VERBOSE" = x ]; then
92 export VERBOSE=
93fi
94
Matt Kraai01d2ea92002-01-02 20:37:59 +000095if [ x"$1" = x"-v" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000096 export VERBOSE=1
Matt Kraai01d2ea92002-01-02 20:37:59 +000097 shift
98fi
99
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000100implemented=$(
Denis Vlasenko92a6f872008-04-27 03:33:29 +0000101 "$bindir/busybox" 2>&1 |
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000102 while read line; do
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000103 if [ x"$line" = x"Currently defined functions:" ]; then
Denis Vlasenko018e0852007-02-25 00:40:37 +0000104 xargs | sed 's/,//g'
105 break
106 fi
107 done
108 )
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000109
110applets="$implemented"
111if [ $# -ne 0 ]; then
112 applets="$@"
113fi
114
115# Populate a directory with links to all busybox applets
116
117LINKSDIR="$bindir/runtest-tempdir-links"
Rob Landley2824ded2006-03-16 16:02:06 +0000118rm -rf "$LINKSDIR" 2>/dev/null
119mkdir "$LINKSDIR"
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000120for i in $implemented; do
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +0000121 ln -s "$bindir/busybox" "$LINKSDIR/$i"
Rob Landley2824ded2006-03-16 16:02:06 +0000122done
123
Rob Landley48c61572005-11-07 08:50:53 +0000124# Set up option flags so tests can be selective.
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +0000125export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_//p' "$bindir/.config" | sed 's/=.*//' | xargs | sed 's/ /:/g')
Rob Landley48c61572005-11-07 08:50:53 +0000126
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000127status=0
Matt Kraai38890782001-10-30 23:11:20 +0000128for applet in $applets; do
Denis Vlasenko3c07e4b2008-04-29 14:11:57 +0000129 case "$applet" in
130 "links")
131 continue
132 ;;
133 "CVS")
134 continue
135 ;;
136 .*)
137 continue
138 ;;
139 esac
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000140
141 # Any old-style tests for this applet?
Denis Vlasenko3c07e4b2008-04-29 14:11:57 +0000142 if [ -d "$tsdir/$applet" ]; then
143 run_oldstyle_applet_tests "$applet"
Denis Vlasenko64d5bfd2008-04-26 10:14:25 +0000144 test $? -eq 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +0000145 fi
Rob Landley48c61572005-11-07 08:50:53 +0000146
147 # Is this a new-style test?
Denis Vlasenko5d0f4aa2008-04-27 13:34:43 +0000148 if [ -f "$applet.tests" ]; then
Denis Vlasenko95842fb2008-04-25 08:43:01 +0000149 if [ ! -h "$LINKSDIR/$applet" ]; then
150 # (avoiding bash'ism "${applet:0:4}")
151 if ! echo "$applet" | grep "^all_" >/dev/null; then
152 echo "SKIPPED: $applet (not built)"
153 continue
154 fi
Rob Landley48c61572005-11-07 08:50:53 +0000155 fi
Denis Vlasenko3c07e4b2008-04-29 14:11:57 +0000156# echo "Running test $tsdir/$applet.tests"
157 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" "$tsdir/$applet.tests"
Denis Vlasenko64d5bfd2008-04-26 10:14:25 +0000158 test $? -eq 0 || status=1
Rob Landley16890752005-09-02 00:41:53 +0000159 fi
Matt Kraai38890782001-10-30 23:11:20 +0000160done
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000161
162# Leaving the dir makes it somewhat easier to run failed test by hand
163#rm -rf "$LINKSDIR"
164
Denis Vlasenko64d5bfd2008-04-26 10:14:25 +0000165if [ $status -ne 0 -a x"$VERBOSE" = x ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000166 echo "Failures detected, running with -v (verbose) will give more info"
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000167fi
Matt Kraai38890782001-10-30 23:11:20 +0000168exit $status