Mercurial > hg > toybox
annotate scripts/runtest.sh @ 1566:62a7d617e1ce draft 0.5.1
Make md5sum and sha1sum work on big endian systems.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 19 Nov 2014 21:38:00 -0600 |
parents | e6a4ed6fc873 |
children | 071d152c356d |
rev | line source |
---|---|
156
1e8f4b05cb65
Remove trailing whitespace (thanks to Charlie Shepherd), and a couple comment
Rob Landley <rob@landley.net>
parents:
103
diff
changeset
|
1 # Simple test harness infrastructure |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 # |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 # Copyright 2005 by Rob Landley |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 # This file defines two functions, "testing" and "optionflag" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 # The following environment variables enable optional behavior in "testing": |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 # DEBUG - Show every command run by test script. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 # VERBOSE - Print the diff -u of each failed test case. |
1449
0de09d7f503d
Add VERBOSE=fail to "make tests", based on suggestion from Johan Bergstr?m.
Rob Landley <rob@landley.net>
parents:
782
diff
changeset
|
10 # If equal to "fail", stop after first failed test. |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 # SKIP - do not perform this test (this is set by "optionflag") |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 # |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 # The "testing" function takes five arguments: |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 # $1) Description to display when running command |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 # $2) Command line arguments to command |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 # $3) Expected result (on stdout) |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 # $4) Data written to file "input" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 # $5) Data written to stdin |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 # |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 # The exit value of testing is the exit value of the command it ran. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 # |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 # The environment variable "FAILCOUNT" contains a cumulative total of the |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 # number of failed tests. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 # The "optional" function is used to skip certain tests, ala: |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 # optionflag CFG_THINGY |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 # |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 # The "optional" function checks the environment variable "OPTIONFLAGS", |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 # which is either empty (in which case it always clears SKIP) or |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 # else contains a colon-separated list of features (in which case the function |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 # clears SKIP if the flag was found, or sets it to 1 if the flag was not found). |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 export FAILCOUNT=0 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 export SKIP= |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 # Helper functions |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 |
421 | 38 # Check config to see if option is enabled, set SKIP if not. |
39 | |
1554
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
40 SHOWPASS=PASS |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
41 SHOWFAIL=FAIL |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
42 SHOWSKIP=SKIP |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
43 |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
44 if tty -s <&1 |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
45 then |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
46 SHOWPASS="$(echo -e "\033[1m\033[32m${SHOWPASS}\033[0m")" |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
47 SHOWFAIL="$(echo -e "\033[1m\033[31m${SHOWFAIL}\033[0m")" |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
48 SHOWSKIP="$(echo -e "\033[1m\033[33m${SHOWSKIP}\033[0m")" |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
49 fi |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
50 |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 optional() |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 { |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 option=`echo "$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"` |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 # Not set? |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ] |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 then |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 SKIP="" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 return |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 fi |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 SKIP=1 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 } |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 # The testing function |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 |
1485
8700cbe1cb29
Move testsuite out of scripts/test into its own top level tests directory, and make ctrl-c kill "make test" more reliably.
Rob Landley <rob@landley.net>
parents:
1449
diff
changeset
|
65 testing() |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 { |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 NAME="$1" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 [ -z "$1" ] && NAME=$2 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 if [ $# -ne 5 ] |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 then |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 echo "Test $NAME has the wrong number of arguments ($# $*)" >&2 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 exit |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 fi |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 [ -n "$DEBUG" ] && set -x |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 |
1554
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
78 if [ -n "$SKIP" ] || ( [ -n "$SKIP_HOST" ] && [ -n "$TEST_HOST" ]) |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 then |
1554
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
80 [ ! -z "$VERBOSE" ] && echo "$SHOWSKIP: $NAME" |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 return 0 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 fi |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 echo -ne "$3" > expected |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 echo -ne "$4" > input |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 echo -ne "$5" | eval "$2" > actual |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 RETVAL=$? |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 |
782
3d7526f6115b
Use basename() where appropriate.
Rob Landley <rob@landley.net>
parents:
421
diff
changeset
|
89 cmp expected actual > /dev/null 2>&1 |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 if [ $? -ne 0 ] |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 then |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 FAILCOUNT=$[$FAILCOUNT+1] |
1554
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
93 echo "$SHOWFAIL: $NAME" |
205
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
94 if [ -n "$VERBOSE" ] |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
95 then |
1554
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
96 [ ! -z "$4" ] && echo "echo -ne \"$4\" > input" |
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
97 echo "echo -ne '$5' | $2" |
205
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
98 diff -u expected actual |
1449
0de09d7f503d
Add VERBOSE=fail to "make tests", based on suggestion from Johan Bergstr?m.
Rob Landley <rob@landley.net>
parents:
782
diff
changeset
|
99 [ "$VERBOSE" == fail ] && exit 1 |
205
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
100 fi |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 else |
1554
e6a4ed6fc873
Add color support for scripts/test.sh and new SKIP_HOST for tests expected to fail on non-toybox implementations.
Rob Landley <rob@landley.net>
parents:
1485
diff
changeset
|
102 echo "$SHOWPASS: $NAME" |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 fi |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 rm -f input expected actual |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 [ -n "$DEBUG" ] && set +x |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 return $RETVAL |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 } |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 # Recursively grab an executable and all the libraries needed to run it. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 # Source paths beginning with / will be copied into destpath, otherwise |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 # the file is assumed to already be there and only its library dependencies |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 # are copied. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 |
1485
8700cbe1cb29
Move testsuite out of scripts/test into its own top level tests directory, and make ctrl-c kill "make test" more reliably.
Rob Landley <rob@landley.net>
parents:
1449
diff
changeset
|
116 mkchroot() |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 { |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
118 [ $# -lt 2 ] && return |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 echo -n . |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 dest=$1 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 shift |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 for i in "$@" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 do |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 [ "${i:0:1}" == "/" ] || i=$(which $i) |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 [ -f "$dest/$i" ] && continue |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 if [ -e "$i" ] |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 then |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 d=`echo "$i" | grep -o '.*/'` && |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 mkdir -p "$dest/$d" && |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 cat "$i" > "$dest/$i" && |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 chmod +x "$dest/$i" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 else |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 echo "Not found: $i" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 fi |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ') |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 done |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 } |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 # Set up a chroot environment and run commands within it. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 # Needed commands listed on command line |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 # Script fed to stdin. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 |
1485
8700cbe1cb29
Move testsuite out of scripts/test into its own top level tests directory, and make ctrl-c kill "make test" more reliably.
Rob Landley <rob@landley.net>
parents:
1449
diff
changeset
|
145 dochroot() |
103
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
146 { |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 mkdir tmpdir4chroot |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 mount -t ramfs tmpdir4chroot tmpdir4chroot |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 mkdir -p tmpdir4chroot/{etc,sys,proc,tmp,dev} |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 cp -L testing.sh tmpdir4chroot |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 # Copy utilities from command line arguments |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
153 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 echo -n "Setup chroot" |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 mkchroot tmpdir4chroot $* |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 echo |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 mknod tmpdir4chroot/dev/tty c 5 0 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 mknod tmpdir4chroot/dev/null c 1 3 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 mknod tmpdir4chroot/dev/zero c 1 5 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 # Copy script from stdin |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 cat > tmpdir4chroot/test.sh |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 chmod +x tmpdir4chroot/test.sh |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 chroot tmpdir4chroot /test.sh |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 umount -l tmpdir4chroot |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 rmdir tmpdir4chroot |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 } |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 |