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