Mercurial > hg > toybox
annotate scripts/test/testing.sh @ 587:82ffae226c40
Convert another realpath use to xrealpath().
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 01 Jun 2012 17:59:11 -0500 |
parents | 1ca548d46c8e |
children | 3d7526f6115b |
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 |
421 | 37 # Check config to see if option is enabled, set SKIP if not. |
38 | |
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
|
39 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
|
40 { |
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 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
|
42 # 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 } |
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 # 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
|
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 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
|
54 { |
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 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
|
56 [ -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
|
57 |
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 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
|
59 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
|
60 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
|
61 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
|
62 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
|
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 [ -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
|
65 |
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 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
|
67 then |
301
2e2529e298ee
Cosmetic tweak, only show skipped tests when VERBOSE set.
Rob Landley <rob@landley.net>
parents:
205
diff
changeset
|
68 [ ! -z "$VERBOSE" ] && echo "SKIPPED: $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
|
69 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
|
70 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
|
71 |
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 "$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
|
73 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
|
74 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
|
75 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
|
76 |
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 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
|
78 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
|
79 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
|
80 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
|
81 echo "FAIL: $NAME" |
205
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
82 if [ -n "$VERBOSE" ] |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
83 then |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
84 echo "echo '$5' | $2" |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
85 diff -u expected actual |
ea8149345b78
Tweak testing.sh so VERBOSE=1 is less noisy.
Rob Landley <rob@landley.net>
parents:
156
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
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 [ -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
|
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 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
|
95 } |
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 |
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 # 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
|
98 # 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
|
99 # 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
|
100 # 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
|
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 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
|
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 [ $# -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
|
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 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
|
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 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
|
109 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
|
110 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
|
111 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
|
112 [ "${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
|
113 [ -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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 } |
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 |
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 # 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
|
128 # 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
|
129 # 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
|
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 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
|
132 { |
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 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
|
134 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
|
135 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
|
136 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
|
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 # 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
|
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 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
|
141 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
|
142 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
|
143 |
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/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
|
145 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
|
146 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
|
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 # 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
|
149 |
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 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 } |
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 |