Mercurial > hg > toybox
annotate scripts/test/testing.sh @ 226:6aac63925eff
Update web pages.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 05 Jan 2008 18:09:49 -0600 |
parents | ea8149345b78 |
children | 2e2529e298ee |
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. |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 # 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
|
11 # |
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 # 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
|
13 # $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
|
14 # $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
|
15 # $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
|
16 # $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
|
17 # $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
|
18 # |
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 # 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
|
20 # |
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 # 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
|
22 # 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
|
23 |
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 # 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
|
25 # 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
|
26 # |
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 # 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
|
28 # 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
|
29 # 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
|
30 # 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
|
31 |
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 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
|
33 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
|
34 |
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 # 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
|
36 |
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 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
|
38 { |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 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
|
40 # 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 } |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 # 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
|
50 |
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 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
|
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 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
|
54 [ -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
|
55 |
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 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
|
57 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
|
58 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
|
59 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
|
60 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
|
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 [ -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
|
63 |
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 if [ -n "$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
|
65 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
|
66 echo "SKIPPED: $NAME" |
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 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
|
68 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
|
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 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
|
71 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
|
72 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
|
73 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
|
74 |
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 cmp expected actual > /dev/null |
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 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
|
77 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
|
78 FAILCOUNT=$[$FAILCOUNT+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
|
79 echo "FAIL: $NAME" |
205
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
80 if [ -n "$VERBOSE" ] |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
81 then |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
82 echo "echo '$5' | $2" |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
83 diff -u expected actual |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
84 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
|
85 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
|
86 echo "PASS: $NAME" |
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 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
|
88 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
|
89 |
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 [ -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
|
91 |
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 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
|
93 } |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 # 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
|
96 # 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
|
97 # 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
|
98 # 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
|
99 |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 function mkchroot |
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 { |
417591818dcb
An old test suite wrapper I wrote, cleaned up a bit and checked for copyrights.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 [ $# -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
|
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
|
104 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
|
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 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
|
107 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
|
108 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
|
109 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
|
110 [ "${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
|
111 [ -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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 } |
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 |
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 # 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
|
126 # 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
|
127 # 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
|
128 |
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 function dochroot |
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 { |
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 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
|
132 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
|
133 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
|
134 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
|
135 |
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 # 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
|
137 |
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 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
|
139 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
|
140 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
|
141 |
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 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
|
143 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
|
144 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
|
145 |
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 # 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
|
147 |
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 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
|
149 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
|
150 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
|
151 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
|
152 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
|
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 |