Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 3 | # 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 Vlasenko | 018e085 | 2007-02-25 00:40:37 +0000 | [diff] [blame] | 7 | run_applet_testcase() |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 8 | { |
| 9 | local applet=$1 |
| 10 | local testcase=$2 |
| 11 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 12 | local status |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 13 | local uc_applet=$(echo $applet | tr a-z A-Z) |
| 14 | local testname=$(basename $testcase) |
| 15 | |
Eric Andersen | 7daa076 | 2004-10-08 07:46:08 +0000 | [diff] [blame] | 16 | if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 17 | echo "UNTESTED: $testname" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 18 | return 0 |
| 19 | fi |
| 20 | |
Matt Kraai | 6b140ea | 2002-02-19 23:43:08 +0000 | [diff] [blame] | 21 | if grep -q "^# FEATURE: " $testcase; then |
| 22 | local feature=`sed -ne 's/^# FEATURE: //p' $testcase` |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 23 | |
Eric Andersen | 7daa076 | 2004-10-08 07:46:08 +0000 | [diff] [blame] | 24 | if grep -q "^# ${feature} is not set$" $bindir/.config; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 25 | echo "UNTESTED: $testname" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 26 | return 0 |
| 27 | fi |
| 28 | fi |
| 29 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 30 | rm -rf ".tmpdir.$applet" |
| 31 | mkdir -p ".tmpdir.$applet" |
| 32 | cd ".tmpdir.$applet" || return 1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 33 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 34 | # 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-Fischer | 89a22ea | 2006-05-25 13:24:02 +0000 | [diff] [blame] | 41 | fi |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 42 | else |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 43 | echo "PASS: $testname" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 44 | fi |
| 45 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 46 | cd .. |
| 47 | rm -rf ".tmpdir.$applet" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 48 | |
| 49 | return $status |
| 50 | } |
| 51 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 52 | # Run all old-style tests for given applet |
Denis Vlasenko | 018e085 | 2007-02-25 00:40:37 +0000 | [diff] [blame] | 53 | run_applet_tests() |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 54 | { |
| 55 | local applet=$1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 56 | local status=0 |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 57 | for testcase in $tsdir/$applet/*; do |
| 58 | if [ "$testcase" = "$tsdir/$applet/CVS" ]; then |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 59 | continue |
| 60 | fi |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 61 | run_applet_testcase $applet $testcase |
| 62 | test $? = 0 || status=1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 63 | done |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 64 | return $status |
| 65 | } |
| 66 | |
| 67 | |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 68 | |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 69 | [ -n "$tsdir" ] || tsdir=$(pwd) |
| 70 | [ -n "$bindir" ] || bindir=$(dirname $(pwd)) |
| 71 | PATH="$bindir:$PATH" |
| 72 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 73 | if [ x"$VERBOSE" = x ]; then |
| 74 | export VERBOSE= |
| 75 | fi |
| 76 | |
Matt Kraai | 01d2ea9 | 2002-01-02 20:37:59 +0000 | [diff] [blame] | 77 | if [ x"$1" = x"-v" ]; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 78 | export VERBOSE=1 |
Matt Kraai | 01d2ea9 | 2002-01-02 20:37:59 +0000 | [diff] [blame] | 79 | shift |
| 80 | fi |
| 81 | |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 82 | implemented=$( |
| 83 | $bindir/busybox 2>&1 | |
| 84 | while read line; do |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 85 | if [ x"$line" = x"Currently defined functions:" ]; then |
Denis Vlasenko | 018e085 | 2007-02-25 00:40:37 +0000 | [diff] [blame] | 86 | xargs | sed 's/,//g' |
| 87 | break |
| 88 | fi |
| 89 | done |
| 90 | ) |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 91 | |
| 92 | applets="$implemented" |
| 93 | if [ $# -ne 0 ]; then |
| 94 | applets="$@" |
| 95 | fi |
| 96 | |
| 97 | # Populate a directory with links to all busybox applets |
| 98 | |
| 99 | LINKSDIR="$bindir/runtest-tempdir-links" |
Rob Landley | 2824ded | 2006-03-16 16:02:06 +0000 | [diff] [blame] | 100 | rm -rf "$LINKSDIR" 2>/dev/null |
| 101 | mkdir "$LINKSDIR" |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 102 | for i in $implemented; do |
Rob Landley | 2824ded | 2006-03-16 16:02:06 +0000 | [diff] [blame] | 103 | ln -s $bindir/busybox "$LINKSDIR"/$i |
| 104 | done |
| 105 | |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 106 | # Set up option flags so tests can be selective. |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 107 | export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_//p' $bindir/.config | sed 's/=.*//' | xargs | sed 's/ /:/g') |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 108 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 109 | status=0 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 110 | for applet in $applets; do |
Bernhard Reutner-Fischer | b47a74f | 2005-09-23 15:44:46 +0000 | [diff] [blame] | 111 | if [ "$applet" = "links" ]; then continue; fi |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 112 | |
| 113 | # Any old-style tests for this applet? |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 114 | if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 115 | run_applet_tests "$applet" |
| 116 | test $? = 0 || status=1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 117 | fi |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 118 | |
| 119 | # Is this a new-style test? |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 120 | if [ -f "${applet}.tests" ]; then |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 121 | if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]; then |
Rob Landley | 2824ded | 2006-03-16 16:02:06 +0000 | [diff] [blame] | 122 | echo "SKIPPED: $applet (not built)" |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 123 | continue |
| 124 | fi |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 125 | # echo "Running test ${tsdir:-.}/${applet}.tests" |
| 126 | PATH="$LINKSDIR:$tsdir:$bindir:$PATH" "${tsdir:-.}/${applet}.tests" |
| 127 | test $? = 0 || status=1 |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 128 | fi |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 129 | done |
Denis Vlasenko | 4e1e720 | 2007-11-26 05:38:20 +0000 | [diff] [blame] | 130 | |
| 131 | # Leaving the dir makes it somewhat easier to run failed test by hand |
| 132 | #rm -rf "$LINKSDIR" |
| 133 | |
| 134 | if [ $status != 0 -a x"$VERBOSE" = x ]; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 135 | echo "Failures detected, running with -v (verbose) will give more info" |
Denis Vlasenko | 4e1e720 | 2007-11-26 05:38:20 +0000 | [diff] [blame] | 136 | fi |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 137 | exit $status |