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