blob: 478764801a30dc93c458e33c2dd9a99f56a4e528 [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
Matt Kraai38890782001-10-30 23:11:20 +000016 local uc_applet=$(echo $applet | tr a-z A-Z)
Denis Vlasenko95842fb2008-04-25 08:43:01 +000017 local testname=$(basename "$testcase")
Matt Kraai38890782001-10-30 23:11:20 +000018
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
Denis Vlasenko58dc2742008-04-23 06:45:11 +000024 if grep -q "^# FEATURE: " "$testcase"; then
Denis Vlasenko95842fb2008-04-25 08:43:01 +000025 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
Denis Vlasenko95842fb2008-04-25 08:43:01 +000061 case $(basename "$testcase") in
Denis Vlasenko58dc2742008-04-23 06:45:11 +000062 \#*)
63 continue
64 ;;
65 *\~)
66 continue
67 ;;
68 esac
69 if [ "$testcase" = "$tsdir/$applet/CVS" ] ||
70 [ "$testcase" = "$tsdir/$applet/.svn" ]; then
Matt Kraai38890782001-10-30 23:11:20 +000071 continue
72 fi
Denis Vlasenko58dc2742008-04-23 06:45:11 +000073 run_applet_testcase "$applet" "$testcase"
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000074 test $? = 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +000075 done
Matt Kraai38890782001-10-30 23:11:20 +000076 return $status
77}
78
79
Matt Kraai38890782001-10-30 23:11:20 +000080
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000081[ -n "$tsdir" ] || tsdir=$(pwd)
82[ -n "$bindir" ] || bindir=$(dirname $(pwd))
83PATH="$bindir:$PATH"
84
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000085if [ x"$VERBOSE" = x ]; then
86 export VERBOSE=
87fi
88
Matt Kraai01d2ea92002-01-02 20:37:59 +000089if [ x"$1" = x"-v" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000090 export VERBOSE=1
Matt Kraai01d2ea92002-01-02 20:37:59 +000091 shift
92fi
93
Denis Vlasenko8d0a7342007-11-13 22:23:57 +000094implemented=$(
95 $bindir/busybox 2>&1 |
96 while read line; do
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +000097 if [ x"$line" = x"Currently defined functions:" ]; then
Denis Vlasenko018e0852007-02-25 00:40:37 +000098 xargs | sed 's/,//g'
99 break
100 fi
101 done
102 )
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000103
104applets="$implemented"
105if [ $# -ne 0 ]; then
106 applets="$@"
107fi
108
109# Populate a directory with links to all busybox applets
110
111LINKSDIR="$bindir/runtest-tempdir-links"
Rob Landley2824ded2006-03-16 16:02:06 +0000112rm -rf "$LINKSDIR" 2>/dev/null
113mkdir "$LINKSDIR"
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000114for i in $implemented; do
Rob Landley2824ded2006-03-16 16:02:06 +0000115 ln -s $bindir/busybox "$LINKSDIR"/$i
116done
117
Rob Landley48c61572005-11-07 08:50:53 +0000118# Set up option flags so tests can be selective.
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000119export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_//p' $bindir/.config | sed 's/=.*//' | xargs | sed 's/ /:/g')
Rob Landley48c61572005-11-07 08:50:53 +0000120
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000121status=0
Matt Kraai38890782001-10-30 23:11:20 +0000122for applet in $applets; do
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +0000123 if [ "$applet" = "links" ]; then continue; fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000124
125 # Any old-style tests for this applet?
Denis Vlasenko8d0a7342007-11-13 22:23:57 +0000126 if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000127 run_applet_tests "$applet"
128 test $? = 0 || status=1
Matt Kraai38890782001-10-30 23:11:20 +0000129 fi
Rob Landley48c61572005-11-07 08:50:53 +0000130
131 # Is this a new-style test?
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000132 if [ -f "${applet}.tests" ]; then
Denis Vlasenko95842fb2008-04-25 08:43:01 +0000133 if [ ! -h "$LINKSDIR/$applet" ]; then
134 # (avoiding bash'ism "${applet:0:4}")
135 if ! echo "$applet" | grep "^all_" >/dev/null; then
136 echo "SKIPPED: $applet (not built)"
137 continue
138 fi
Rob Landley48c61572005-11-07 08:50:53 +0000139 fi
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000140# echo "Running test ${tsdir:-.}/${applet}.tests"
141 PATH="$LINKSDIR:$tsdir:$bindir:$PATH" "${tsdir:-.}/${applet}.tests"
142 test $? = 0 || status=1
Rob Landley16890752005-09-02 00:41:53 +0000143 fi
Matt Kraai38890782001-10-30 23:11:20 +0000144done
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000145
146# Leaving the dir makes it somewhat easier to run failed test by hand
147#rm -rf "$LINKSDIR"
148
149if [ $status != 0 -a x"$VERBOSE" = x ]; then
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000150 echo "Failures detected, running with -v (verbose) will give more info"
Denis Vlasenko4e1e7202007-11-26 05:38:20 +0000151fi
Matt Kraai38890782001-10-30 23:11:20 +0000152exit $status