aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-03-09 22:04:33 +0000
committerRob Landley <rob@landley.net>2006-03-09 22:04:33 +0000
commit3a324754f88b913091eca8970c686f2e998028a9 (patch)
tree890ec06c87f5577738213a8ed474cfe69fe73030
parent31e3610c4b71594c3b141a249ab2e5812c92980a (diff)
downloadbusybox-w32-3a324754f88b913091eca8970c686f2e998028a9.tar.gz
busybox-w32-3a324754f88b913091eca8970c686f2e998028a9.tar.bz2
busybox-w32-3a324754f88b913091eca8970c686f2e998028a9.zip
I'm about to introduce tests that need to run as root (like mount.tests),
meaning we want to run them in a chroot environment. To help with this, I worked out a utility function that makes it really easy to set up a chroot environment.
-rwxr-xr-xtestsuite/testing.sh31
1 files changed, 29 insertions, 2 deletions
diff --git a/testsuite/testing.sh b/testsuite/testing.sh
index f16f4c7e8..08f4200c5 100755
--- a/testsuite/testing.sh
+++ b/testsuite/testing.sh
@@ -58,7 +58,7 @@ testing ()
58{ 58{
59 if [ $# -ne 5 ] 59 if [ $# -ne 5 ]
60 then 60 then
61 echo "Test $1 has the wrong number of arguments" >&2 61 echo "Test $1 has the wrong number of arguments ($# $*)" >&2
62 exit 62 exit
63 fi 63 fi
64 64
@@ -74,7 +74,7 @@ testing ()
74 74
75 echo -ne "$3" > expected 75 echo -ne "$3" > expected
76 echo -ne "$4" > input 76 echo -ne "$4" > input
77 echo -n -e "$5" | eval "$COMMAND $2" > actual 77 echo -ne "$5" | eval "$COMMAND $2" > actual
78 RETVAL=$? 78 RETVAL=$?
79 79
80 cmp expected actual > /dev/null 80 cmp expected actual > /dev/null
@@ -98,3 +98,30 @@ testing ()
98 98
99 return $RETVAL 99 return $RETVAL
100} 100}
101
102# Recursively grab an executable and all the libraries needed to run it.
103# Source paths beginning with / will be copied into destpath, otherwise
104# the file is assumed to already be there and only its library dependencies
105# are copied.
106
107function mkchroot
108{
109 [ $# -lt 2 ] && return
110
111 dest=$1
112 shift
113 for i in "$@"
114 do
115 if [ "${i:0:1}" == "/" ]
116 then
117 [ -f "$dest/$i" ] && continue
118 d=`echo "$i" | grep -o '.*/'` &&
119 mkdir -p "$dest/$d" &&
120 cat "$i" > "$dest/$i" &&
121 chmod +x "$dest/$i"
122 else
123 i="$dest/$i"
124 fi
125 mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ')
126 done
127}