aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-02 21:46:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-02 21:46:30 +0000
commit687a26fe0dcf10f227cb0541882d1daa8a21991d (patch)
tree2bc145dfd405a157cc1448d9f5889373ef773a67
parent4e79049e109a9651b462c5dcf9559f9fef2b0cc8 (diff)
downloadbusybox-w32-687a26fe0dcf10f227cb0541882d1daa8a21991d.tar.gz
busybox-w32-687a26fe0dcf10f227cb0541882d1daa8a21991d.tar.bz2
busybox-w32-687a26fe0dcf10f227cb0541882d1daa8a21991d.zip
more fixes to testsuite by Cristian and vda
-rw-r--r--scripts/echo.c230
-rwxr-xr-xtestsuite/cpio.tests14
-rwxr-xr-xtestsuite/testing.sh49
3 files changed, 273 insertions, 20 deletions
diff --git a/scripts/echo.c b/scripts/echo.c
new file mode 100644
index 000000000..9e591c4d5
--- /dev/null
+++ b/scripts/echo.c
@@ -0,0 +1,230 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * echo implementation for busybox - used as a helper for testsuite/*
4 * on systems lacking "echo -en"
5 *
6 * Copyright (c) 1991, 1993
7 * The Regents of the University of California. All rights reserved.
8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 *
11 * Original copyright notice is retained at the end of this file.
12 */
13
14/* BB_AUDIT SUSv3 compliant -- unless configured as fancy echo. */
15/* http://www.opengroup.org/onlinepubs/007904975/utilities/echo.html */
16
17/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
18 *
19 * Because of behavioral differences, implemented configurable SUSv3
20 * or 'fancy' gnu-ish behaviors. Also, reduced size and fixed bugs.
21 * 1) In handling '\c' escape, the previous version only suppressed the
22 * trailing newline. SUSv3 specifies _no_ output after '\c'.
23 * 2) SUSv3 specifies that octal escapes are of the form \0{#{#{#}}}.
24 * The previous version did not allow 4-digit octals.
25 */
26
27#include <stdio.h>
28#include <string.h>
29#include <limits.h>
30
31#define WANT_HEX_ESCAPES 1
32
33/* Usual "this only works for ascii compatible encodings" disclaimer. */
34#undef _tolower
35#define _tolower(X) ((X)|((char) 0x20))
36
37static char bb_process_escape_sequence(const char **ptr)
38{
39 static const char charmap[] = {
40 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0,
41 '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
42
43 const char *p;
44 const char *q;
45 unsigned int num_digits;
46 unsigned int r;
47 unsigned int n;
48 unsigned int d;
49 unsigned int base;
50
51 num_digits = n = 0;
52 base = 8;
53 q = *ptr;
54
55#ifdef WANT_HEX_ESCAPES
56 if (*q == 'x') {
57 ++q;
58 base = 16;
59 ++num_digits;
60 }
61#endif
62
63 do {
64 d = (unsigned char)(*q) - '0';
65#ifdef WANT_HEX_ESCAPES
66 if (d >= 10) {
67 d = (unsigned char)(_tolower(*q)) - 'a' + 10;
68 }
69#endif
70
71 if (d >= base) {
72#ifdef WANT_HEX_ESCAPES
73 if ((base == 16) && (!--num_digits)) {
74/* return '\\'; */
75 --q;
76 }
77#endif
78 break;
79 }
80
81 r = n * base + d;
82 if (r > UCHAR_MAX) {
83 break;
84 }
85
86 n = r;
87 ++q;
88 } while (++num_digits < 3);
89
90 if (num_digits == 0) { /* mnemonic escape sequence? */
91 p = charmap;
92 do {
93 if (*p == *q) {
94 q++;
95 break;
96 }
97 } while (*++p);
98 n = *(p + (sizeof(charmap)/2));
99 }
100
101 *ptr = q;
102
103 return (char) n;
104}
105
106
107int main(int argc, char **argv)
108{
109 const char *arg;
110 const char *p;
111 char nflag = 1;
112 char eflag = 0;
113
114 /* We must check that stdout is not closed. */
115 if (dup2(1, 1) != 1)
116 return -1;
117
118 while (1) {
119 arg = *++argv;
120 if (!arg)
121 goto newline_ret;
122 if (*arg != '-')
123 break;
124
125 /* If it appears that we are handling options, then make sure
126 * that all of the options specified are actually valid.
127 * Otherwise, the string should just be echoed.
128 */
129 p = arg + 1;
130 if (!*p) /* A single '-', so echo it. */
131 goto just_echo;
132
133 do {
134 if (!strrchr("neE", *p))
135 goto just_echo;
136 } while (*++p);
137
138 /* All of the options in this arg are valid, so handle them. */
139 p = arg + 1;
140 do {
141 if (*p == 'n')
142 nflag = 0;
143 if (*p == 'e')
144 eflag = '\\';
145 } while (*++p);
146 }
147 just_echo:
148 while (1) {
149 /* arg is already == *argv and isn't NULL */
150 int c;
151
152 if (!eflag) {
153 /* optimization for very common case */
154 fputs(arg, stdout);
155 } else while ((c = *arg++)) {
156 if (c == eflag) { /* Check for escape seq. */
157 if (*arg == 'c') {
158 /* '\c' means cancel newline and
159 * ignore all subsequent chars. */
160 goto ret;
161 }
162 {
163 /* Since SUSv3 mandates a first digit of 0, 4-digit octals
164 * of the form \0### are accepted. */
165 if (*arg == '0') {
166 /* NB: don't turn "...\0" into "...\" */
167 if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) {
168 arg++;
169 }
170 }
171 /* bb_process_escape_sequence handles NUL correctly
172 * ("...\" case. */
173 c = bb_process_escape_sequence(&arg);
174 }
175 }
176 putchar(c);
177 }
178
179 arg = *++argv;
180 if (!arg)
181 break;
182 putchar(' ');
183 }
184
185 newline_ret:
186 if (nflag) {
187 putchar('\n');
188 }
189 ret:
190 return fflush(stdout);
191}
192
193/*-
194 * Copyright (c) 1991, 1993
195 * The Regents of the University of California. All rights reserved.
196 *
197 * This code is derived from software contributed to Berkeley by
198 * Kenneth Almquist.
199 *
200 * Redistribution and use in source and binary forms, with or without
201 * modification, are permitted provided that the following conditions
202 * are met:
203 * 1. Redistributions of source code must retain the above copyright
204 * notice, this list of conditions and the following disclaimer.
205 * 2. Redistributions in binary form must reproduce the above copyright
206 * notice, this list of conditions and the following disclaimer in the
207 * documentation and/or other materials provided with the distribution.
208 *
209 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
210 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
211 *
212 * California, Berkeley and its contributors.
213 * 4. Neither the name of the University nor the names of its contributors
214 * may be used to endorse or promote products derived from this software
215 * without specific prior written permission.
216 *
217 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
218 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
221 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
224 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
225 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
226 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
227 * SUCH DAMAGE.
228 *
229 * @(#)echo.c 8.1 (Berkeley) 5/31/93
230 */
diff --git a/testsuite/cpio.tests b/testsuite/cpio.tests
index 408a3fbcf..d42e5145f 100755
--- a/testsuite/cpio.tests
+++ b/testsuite/cpio.tests
@@ -4,6 +4,13 @@
4 4
5. testing.sh 5. testing.sh
6 6
7# check if hexdump supports the '-R' option
8hexdump -R </dev/null >/dev/null 2>&1 || {
9 echo "'hexdump -R' is not available" >&2
10 SKIP=1
11 exit 1
12}
13
7# ls -ln is showing date. Need to remove that, it's variable 14# ls -ln is showing date. Need to remove that, it's variable
8# sed: coalesce spaces 15# sed: coalesce spaces
9# cut: remove date 16# cut: remove date
@@ -24,6 +31,9 @@ hexdump="\
2400000090 14 24 19 07 a4 63 00 3100000090 14 24 19 07 a4 63 00
25" 32"
26 33
34user=$(id -u)
35group=$(id -g)
36
27rm -rf cpio.testdir 37rm -rf cpio.testdir
28 38
29# testing "test name" "options" "expected result" "file input" "stdin" 39# testing "test name" "options" "expected result" "file input" "stdin"
@@ -34,8 +44,8 @@ testing "cpio extracts zero-sized hardlinks" \
34"\ 44"\
351 blocks 451 blocks
360 460
37-rw-r--r-- 2 0 0 0 x 47-rw-r--r-- 2 $user $group 0 x
38-rw-r--r-- 2 0 0 0 y 48-rw-r--r-- 2 $user $group 0 y
39" \ 49" \
40 "" "" 50 "" ""
41 51
diff --git a/testsuite/testing.sh b/testsuite/testing.sh
index e9338dbc1..028d09a28 100755
--- a/testsuite/testing.sh
+++ b/testsuite/testing.sh
@@ -4,28 +4,29 @@
4# 4#
5# License is GPLv2, see LICENSE in the busybox tarball for full license text. 5# License is GPLv2, see LICENSE in the busybox tarball for full license text.
6 6
7# This file defines two functions, "testing" and "optionflag" 7# This file defines two functions, "testing" and "optional"
8# and a couple more...
8 9
9# The following environment variables may be set to enable optional behavior 10# The following environment variables may be set to enable optional behavior
10# in "testing": 11# in "testing":
11# VERBOSE - Print the diff -u of each failed test case. 12# VERBOSE - Print the diff -u of each failed test case.
12# DEBUG - Enable command tracing. 13# DEBUG - Enable command tracing.
13# SKIP - do not perform this test (this is set by "optionflag") 14# SKIP - do not perform this test (this is set by "optional")
14# 15#
15# The "testing" function takes five arguments: 16# The "testing" function takes five arguments:
16# $1) Description to display when running command 17# $1) Test description
17# $2) Command line arguments to command 18# $2) Command(s) to run. May have pipes, redirects, etc
18# $3) Expected result (on stdout) 19# $3) Expected result on stdout
19# $4) Data written to file "input" 20# $4) Data to be written to file "input"
20# $5) Data written to stdin 21# $5) Data to be written to stdin
21# 22#
22# The exit value of testing is the exit value of the command it ran. 23# The exit value of testing is the exit value of $2 it ran.
23# 24#
24# The environment variable "FAILCOUNT" contains a cumulative total of the 25# The environment variable "FAILCOUNT" contains a cumulative total of the
25# number of failed tests. 26# number of failed tests.
26 27
27# The "optional" function is used to skip certain tests, ala: 28# The "optional" function is used to skip certain tests, ala:
28# optionflag CONFIG_FEATURE_THINGY 29# optional CONFIG_FEATURE_THINGY
29# 30#
30# The "optional" function checks the environment variable "OPTIONFLAGS", 31# The "optional" function checks the environment variable "OPTIONFLAGS",
31# which is either empty (in which case it always clears SKIP) or 32# which is either empty (in which case it always clears SKIP) or
@@ -35,15 +36,28 @@
35export FAILCOUNT=0 36export FAILCOUNT=0
36export SKIP= 37export SKIP=
37 38
39# Helper for helpers. Oh my...
40test x"$ECHO" = x"" && {
41 ECHO="echo"
42 test x"`echo -ne`" = x"" || {
43 # Compile and use a replacement 'echo' which understands -e -n
44 ECHO="$PWD/echo-ne"
45 test -x "$ECHO" || {
46 gcc -Os -o "$ECHO" ../scripts/echo.c || exit 1
47 }
48 }
49 export ECHO
50}
51
38# Helper functions 52# Helper functions
39 53
40optional() 54optional()
41{ 55{
42 option=`echo "$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"` 56 option=`echo ":$OPTIONFLAGS:" | grep ":$1:"`
43 # Not set? 57 # Not set?
44 if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ] 58 if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ]
45 then 59 then
46 SKIP="" 60 SKIP=
47 return 61 return
48 fi 62 fi
49 SKIP=1 63 SKIP=1
@@ -54,7 +68,7 @@ optional()
54testing() 68testing()
55{ 69{
56 NAME="$1" 70 NAME="$1"
57 [ -z "$1" ] && NAME=$2 71 [ -z "$1" ] && NAME="$2"
58 72
59 if [ $# -ne 5 ] 73 if [ $# -ne 5 ]
60 then 74 then
@@ -70,10 +84,10 @@ testing()
70 return 0 84 return 0
71 fi 85 fi
72 86
73 echo -ne "$3" > expected 87 $ECHO -ne "$3" > expected
74 echo -ne "$4" > input 88 $ECHO -ne "$4" > input
75 [ -z "$VERBOSE" ] || echo "echo '$5' | $2" 89 [ -z "$VERBOSE" ] || echo "echo '$5' | $2"
76 echo -ne "$5" | eval "$2" > actual 90 $ECHO -ne "$5" | eval "$2" > actual
77 RETVAL=$? 91 RETVAL=$?
78 92
79 cmp expected actual >/dev/null 2>/dev/null 93 cmp expected actual >/dev/null 2>/dev/null
@@ -101,7 +115,7 @@ mkchroot()
101{ 115{
102 [ $# -lt 2 ] && return 116 [ $# -lt 2 ] && return
103 117
104 echo -n . 118 $ECHO -n .
105 119
106 dest=$1 120 dest=$1
107 shift 121 shift
@@ -136,7 +150,7 @@ dochroot()
136 150
137 # Copy utilities from command line arguments 151 # Copy utilities from command line arguments
138 152
139 echo -n "Setup chroot" 153 $ECHO -n "Setup chroot"
140 mkchroot tmpdir4chroot $* 154 mkchroot tmpdir4chroot $*
141 echo 155 echo
142 156
@@ -152,4 +166,3 @@ dochroot()
152 umount -l tmpdir4chroot 166 umount -l tmpdir4chroot
153 rmdir tmpdir4chroot 167 rmdir tmpdir4chroot
154} 168}
155