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