Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/testsuite/testing.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1123 - (hide annotations) (download) (as text)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 3884 byte(s)
-updated to busybox-1.17.1
1 niro 532 # Simple test harness infrastructurei for BusyBox
2     #
3     # Copyright 2005 by Rob Landley
4     #
5     # License is GPLv2, see LICENSE in the busybox tarball for full license text.
6    
7 niro 816 # This file defines two functions, "testing" and "optional"
8     # and a couple more...
9 niro 532
10     # The following environment variables may be set to enable optional behavior
11     # in "testing":
12     # VERBOSE - Print the diff -u of each failed test case.
13     # DEBUG - Enable command tracing.
14 niro 816 # SKIP - do not perform this test (this is set by "optional")
15 niro 532 #
16     # The "testing" function takes five arguments:
17 niro 816 # $1) Test description
18     # $2) Command(s) to run. May have pipes, redirects, etc
19     # $3) Expected result on stdout
20     # $4) Data to be written to file "input"
21     # $5) Data to be written to stdin
22 niro 532 #
23 niro 816 # The exit value of testing is the exit value of $2 it ran.
24 niro 532 #
25     # The environment variable "FAILCOUNT" contains a cumulative total of the
26     # number of failed tests.
27    
28     # The "optional" function is used to skip certain tests, ala:
29 niro 816 # optional CONFIG_FEATURE_THINGY
30 niro 532 #
31     # The "optional" function checks the environment variable "OPTIONFLAGS",
32     # which is either empty (in which case it always clears SKIP) or
33     # else contains a colon-separated list of features (in which case the function
34     # clears SKIP if the flag was found, or sets it to 1 if the flag was not found).
35    
36     export FAILCOUNT=0
37     export SKIP=
38    
39 niro 984 # Helper for helpers. Oh my...
40    
41     test x"$ECHO" != x"" || {
42     ECHO="echo"
43     test x"`echo -ne`" = x"" || {
44     # Compile and use a replacement 'echo' which understands -e -n
45     ECHO="$PWD/echo-ne"
46     test -x "$ECHO" || {
47     gcc -Os -o "$ECHO" ../scripts/echo.c || exit 1
48     }
49     }
50     export ECHO
51     }
52    
53 niro 532 # Helper functions
54    
55     optional()
56     {
57 niro 1123 SKIP=
58     while test "$1"; do
59     if test x"${OPTIONFLAGS/*:$1:*/y}" != x"y"; then
60     SKIP=1
61     return
62     fi
63     shift
64     done
65 niro 532 }
66    
67     # The testing function
68    
69 niro 816 testing()
70 niro 532 {
71     NAME="$1"
72 niro 816 [ -n "$1" ] || NAME="$2"
73 niro 532
74     if [ $# -ne 5 ]
75     then
76 niro 1123 echo "Test $NAME has wrong number of arguments: $# (must be 5)" >&2
77 niro 816 exit 1
78 niro 532 fi
79    
80 niro 816 [ -z "$DEBUG" ] || set -x
81 niro 532
82     if [ -n "$SKIP" ]
83     then
84     echo "SKIPPED: $NAME"
85     return 0
86     fi
87    
88 niro 816 $ECHO -ne "$3" > expected
89     $ECHO -ne "$4" > input
90 niro 984 [ -z "$VERBOSE" ] || echo "echo -ne '$5' | $2"
91 niro 816 $ECHO -ne "$5" | eval "$2" > actual
92 niro 532 RETVAL=$?
93    
94 niro 816 if cmp expected actual >/dev/null 2>/dev/null
95 niro 532 then
96 niro 816 echo "PASS: $NAME"
97     else
98     FAILCOUNT=$(($FAILCOUNT + 1))
99 niro 532 echo "FAIL: $NAME"
100 niro 816 [ -z "$VERBOSE" ] || diff -u expected actual
101 niro 532 fi
102     rm -f input expected actual
103    
104 niro 816 [ -z "$DEBUG" ] || set +x
105 niro 532
106     return $RETVAL
107     }
108    
109     # Recursively grab an executable and all the libraries needed to run it.
110     # Source paths beginning with / will be copied into destpath, otherwise
111     # the file is assumed to already be there and only its library dependencies
112     # are copied.
113    
114 niro 816 mkchroot()
115 niro 532 {
116     [ $# -lt 2 ] && return
117    
118 niro 816 $ECHO -n .
119 niro 532
120     dest=$1
121     shift
122     for i in "$@"
123     do
124 niro 816 #bashism: [ "${i:0:1}" == "/" ] || i=$(which $i)
125     i=$(which $i) # no-op for /bin/prog
126 niro 532 [ -f "$dest/$i" ] && continue
127     if [ -e "$i" ]
128     then
129     d=`echo "$i" | grep -o '.*/'` &&
130     mkdir -p "$dest/$d" &&
131     cat "$i" > "$dest/$i" &&
132     chmod +x "$dest/$i"
133     else
134     echo "Not found: $i"
135     fi
136     mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ')
137     done
138     }
139    
140     # Set up a chroot environment and run commands within it.
141     # Needed commands listed on command line
142     # Script fed to stdin.
143    
144 niro 816 dochroot()
145 niro 532 {
146     mkdir tmpdir4chroot
147     mount -t ramfs tmpdir4chroot tmpdir4chroot
148     mkdir -p tmpdir4chroot/{etc,sys,proc,tmp,dev}
149     cp -L testing.sh tmpdir4chroot
150    
151     # Copy utilities from command line arguments
152    
153 niro 816 $ECHO -n "Setup chroot"
154 niro 532 mkchroot tmpdir4chroot $*
155     echo
156    
157     mknod tmpdir4chroot/dev/tty c 5 0
158     mknod tmpdir4chroot/dev/null c 1 3
159     mknod tmpdir4chroot/dev/zero c 1 5
160    
161     # Copy script from stdin
162    
163     cat > tmpdir4chroot/test.sh
164     chmod +x tmpdir4chroot/test.sh
165     chroot tmpdir4chroot /test.sh
166     umount -l tmpdir4chroot
167     rmdir tmpdir4chroot
168     }

Properties

Name Value
svn:executable *