Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Denis Vlasenko | 3b92eaa | 2008-02-13 14:30:33 +0000 | [diff] [blame] | 2 | # Usage: |
| 3 | # runtest [applet1] [applet2...] |
| 4 | |
Denys Vlasenko | 875f782 | 2009-07-18 16:34:01 +0200 | [diff] [blame] | 5 | . ./testing.sh |
Denis Vlasenko | abe49fa | 2008-07-11 21:41:14 +0000 | [diff] [blame] | 6 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 7 | # Run one old-style test. |
| 8 | # Tests are stored in applet/testcase shell scripts. |
| 9 | # They are run using "sh -x -e applet/testcase". |
| 10 | # Option -e will make testcase stop on the first failed command. |
Denis Vlasenko | 018e085 | 2007-02-25 00:40:37 +0000 | [diff] [blame] | 11 | run_applet_testcase() |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 12 | { |
Denis Vlasenko | 95842fb | 2008-04-25 08:43:01 +0000 | [diff] [blame] | 13 | local applet="$1" |
Denis Vlasenko | 58dc274 | 2008-04-23 06:45:11 +0000 | [diff] [blame] | 14 | local testcase="$2" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 15 | |
Denis Vlasenko | 81e97a1 | 2008-05-15 22:43:48 +0000 | [diff] [blame] | 16 | local status=0 |
Denis Vlasenko | 92a6f87 | 2008-04-27 03:33:29 +0000 | [diff] [blame] | 17 | local uc_applet=$(echo "$applet" | tr a-z A-Z) |
| 18 | local testname="$testcase" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 19 | |
Denis Vlasenko | 5d0f4aa | 2008-04-27 13:34:43 +0000 | [diff] [blame] | 20 | testname="${testname##*/}" # take basename |
| 21 | if grep "^# CONFIG_$uc_applet is not set$" "$bindir/.config" >/dev/null; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 22 | echo "UNTESTED: $testname" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 23 | return 0 |
| 24 | fi |
| 25 | |
Denis Vlasenko | 5d0f4aa | 2008-04-27 13:34:43 +0000 | [diff] [blame] | 26 | if grep "^# FEATURE: " "$testcase" >/dev/null; then |
Denis Vlasenko | 95842fb | 2008-04-25 08:43:01 +0000 | [diff] [blame] | 27 | local feature=$(sed -ne 's/^# FEATURE: //p' "$testcase") |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | 5d0f4aa | 2008-04-27 13:34:43 +0000 | [diff] [blame] | 29 | if grep "^# $feature is not set$" "$bindir/.config" >/dev/null; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 30 | echo "UNTESTED: $testname" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 31 | return 0 |
| 32 | fi |
| 33 | fi |
| 34 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 35 | rm -rf ".tmpdir.$applet" |
| 36 | mkdir -p ".tmpdir.$applet" |
| 37 | cd ".tmpdir.$applet" || return 1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 38 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 39 | # echo "Running testcase $testcase" |
Denis Vlasenko | 81e97a1 | 2008-05-15 22:43:48 +0000 | [diff] [blame] | 40 | d="$tsdir" \ |
| 41 | sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1 || status=$? |
Denis Vlasenko | 64d5bfd | 2008-04-26 10:14:25 +0000 | [diff] [blame] | 42 | if [ $status -ne 0 ]; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 43 | echo "FAIL: $testname" |
| 44 | if [ x"$VERBOSE" != x ]; then |
| 45 | cat "$testname.stdout.txt" |
Bernhard Reutner-Fischer | 89a22ea | 2006-05-25 13:24:02 +0000 | [diff] [blame] | 46 | fi |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 47 | else |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 48 | echo "PASS: $testname" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 49 | fi |
| 50 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 51 | cd .. |
| 52 | rm -rf ".tmpdir.$applet" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 53 | |
| 54 | return $status |
| 55 | } |
| 56 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 57 | # Run all old-style tests for given applet |
Denis Vlasenko | 3c07e4b | 2008-04-29 14:11:57 +0000 | [diff] [blame] | 58 | run_oldstyle_applet_tests() |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 59 | { |
Denis Vlasenko | 5d0f4aa | 2008-04-27 13:34:43 +0000 | [diff] [blame] | 60 | local applet="$1" |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 61 | local status=0 |
Denis Vlasenko | 92a6f87 | 2008-04-27 03:33:29 +0000 | [diff] [blame] | 62 | |
| 63 | for testcase in "$tsdir/$applet"/*; do |
| 64 | # switch on basename of $testcase |
| 65 | case "${testcase##*/}" in |
Denis Vlasenko | 57be4ab | 2008-05-02 09:19:29 +0000 | [diff] [blame] | 66 | .*) continue ;; # .svn, .git etc |
| 67 | *~) continue ;; # backup files |
| 68 | "CVS") continue ;; |
| 69 | \#*) continue ;; # CVS merge residues |
| 70 | *.mine) continue ;; # svn-produced junk |
| 71 | *.r[0-9]*) continue ;; # svn-produced junk |
Denis Vlasenko | 58dc274 | 2008-04-23 06:45:11 +0000 | [diff] [blame] | 72 | esac |
Denis Vlasenko | 81e97a1 | 2008-05-15 22:43:48 +0000 | [diff] [blame] | 73 | run_applet_testcase "$applet" "$testcase" || status=1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 74 | done |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 75 | return $status |
| 76 | } |
| 77 | |
| 78 | |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 79 | |
Denis Vlasenko | 92a6f87 | 2008-04-27 03:33:29 +0000 | [diff] [blame] | 80 | lcwd=$(pwd) |
Denis Vlasenko | 7dff433 | 2008-04-27 20:48:49 +0000 | [diff] [blame] | 81 | [ x"$tsdir" != x ] || tsdir="$lcwd" |
| 82 | [ x"$bindir" != x ] || bindir="${lcwd%/*}" # one directory up from $lcwd |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 83 | PATH="$bindir:$PATH" |
| 84 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 85 | if [ x"$VERBOSE" = x ]; then |
| 86 | export VERBOSE= |
| 87 | fi |
| 88 | |
Matt Kraai | 01d2ea9 | 2002-01-02 20:37:59 +0000 | [diff] [blame] | 89 | if [ x"$1" = x"-v" ]; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 90 | export VERBOSE=1 |
Matt Kraai | 01d2ea9 | 2002-01-02 20:37:59 +0000 | [diff] [blame] | 91 | shift |
| 92 | fi |
| 93 | |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 94 | implemented=$( |
Denis Vlasenko | 92a6f87 | 2008-04-27 03:33:29 +0000 | [diff] [blame] | 95 | "$bindir/busybox" 2>&1 | |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 96 | while read line; do |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 97 | if [ x"$line" = x"Currently defined functions:" ]; then |
Denis Vlasenko | 018e085 | 2007-02-25 00:40:37 +0000 | [diff] [blame] | 98 | xargs | sed 's/,//g' |
| 99 | break |
| 100 | fi |
| 101 | done |
| 102 | ) |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 103 | |
| 104 | applets="$implemented" |
| 105 | if [ $# -ne 0 ]; then |
| 106 | applets="$@" |
| 107 | fi |
| 108 | |
| 109 | # Populate a directory with links to all busybox applets |
| 110 | |
| 111 | LINKSDIR="$bindir/runtest-tempdir-links" |
Denys Vlasenko | 7aca89a | 2009-07-18 03:41:29 +0200 | [diff] [blame] | 112 | |
| 113 | # Comment this line out if you have put a different binary in $LINKSDIR |
| 114 | # (say, a "standard" tool's binary) in order to run tests against it: |
| 115 | rm -rf "$LINKSDIR" 2>/dev/null |
| 116 | |
Denys Vlasenko | cd3dd42 | 2009-06-15 09:16:27 +0200 | [diff] [blame] | 117 | mkdir "$LINKSDIR" 2>/dev/null |
Denis Vlasenko | 8d0a734 | 2007-11-13 22:23:57 +0000 | [diff] [blame] | 118 | for i in $implemented; do |
Denys Vlasenko | 7aca89a | 2009-07-18 03:41:29 +0200 | [diff] [blame] | 119 | # Note: if $LINKSDIR/applet exists, we do not overwrite it. |
| 120 | # Useful if one wants to run tests against a standard utility, |
| 121 | # not an applet. |
Denys Vlasenko | cd3dd42 | 2009-06-15 09:16:27 +0200 | [diff] [blame] | 122 | ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null |
Rob Landley | 2824ded | 2006-03-16 16:02:06 +0000 | [diff] [blame] | 123 | done |
| 124 | |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 125 | # Set up option flags so tests can be selective. |
Denis Vlasenko | 57be4ab | 2008-05-02 09:19:29 +0000 | [diff] [blame] | 126 | export OPTIONFLAGS=:$( |
| 127 | sed -nr 's/^CONFIG_//p' "$bindir/.config" | |
| 128 | sed 's/=.*//' | xargs | sed 's/ /:/g' |
| 129 | ) |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 130 | |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 131 | status=0 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 132 | for applet in $applets; do |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 133 | # Any old-style tests for this applet? |
Denis Vlasenko | 3c07e4b | 2008-04-29 14:11:57 +0000 | [diff] [blame] | 134 | if [ -d "$tsdir/$applet" ]; then |
Denis Vlasenko | 81e97a1 | 2008-05-15 22:43:48 +0000 | [diff] [blame] | 135 | run_oldstyle_applet_tests "$applet" || status=1 |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 136 | fi |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 137 | |
| 138 | # Is this a new-style test? |
Denis Vlasenko | 5d0f4aa | 2008-04-27 13:34:43 +0000 | [diff] [blame] | 139 | if [ -f "$applet.tests" ]; then |
Denys Vlasenko | cd3dd42 | 2009-06-15 09:16:27 +0200 | [diff] [blame] | 140 | if [ ! -e "$LINKSDIR/$applet" ]; then |
Denis Vlasenko | 95842fb | 2008-04-25 08:43:01 +0000 | [diff] [blame] | 141 | # (avoiding bash'ism "${applet:0:4}") |
| 142 | if ! echo "$applet" | grep "^all_" >/dev/null; then |
| 143 | echo "SKIPPED: $applet (not built)" |
| 144 | continue |
| 145 | fi |
Rob Landley | 48c6157 | 2005-11-07 08:50:53 +0000 | [diff] [blame] | 146 | fi |
Denis Vlasenko | 3c07e4b | 2008-04-29 14:11:57 +0000 | [diff] [blame] | 147 | # echo "Running test $tsdir/$applet.tests" |
Denis Vlasenko | 81e97a1 | 2008-05-15 22:43:48 +0000 | [diff] [blame] | 148 | PATH="$LINKSDIR:$tsdir:$bindir:$PATH" \ |
| 149 | "$tsdir/$applet.tests" || status=1 |
Rob Landley | 1689075 | 2005-09-02 00:41:53 +0000 | [diff] [blame] | 150 | fi |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 151 | done |
Denis Vlasenko | 4e1e720 | 2007-11-26 05:38:20 +0000 | [diff] [blame] | 152 | |
| 153 | # Leaving the dir makes it somewhat easier to run failed test by hand |
| 154 | #rm -rf "$LINKSDIR" |
| 155 | |
Denis Vlasenko | 57be4ab | 2008-05-02 09:19:29 +0000 | [diff] [blame] | 156 | if [ $status -ne 0 ] && [ x"$VERBOSE" = x ]; then |
Denis Vlasenko | e2532ab | 2007-12-02 01:44:42 +0000 | [diff] [blame] | 157 | echo "Failures detected, running with -v (verbose) will give more info" |
Denis Vlasenko | 4e1e720 | 2007-11-26 05:38:20 +0000 | [diff] [blame] | 158 | fi |
Matt Kraai | 3889078 | 2001-10-30 23:11:20 +0000 | [diff] [blame] | 159 | exit $status |