diff options
| author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-03-09 22:04:33 +0000 |
|---|---|---|
| committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-03-09 22:04:33 +0000 |
| commit | 47fe8d364ca68aef1ba972f1624ded711dc9cd92 (patch) | |
| tree | 890ec06c87f5577738213a8ed474cfe69fe73030 | |
| parent | 39c648ec812d7f4adaf3fb95c05c3d23d54922eb (diff) | |
| download | busybox-w32-47fe8d364ca68aef1ba972f1624ded711dc9cd92.tar.gz busybox-w32-47fe8d364ca68aef1ba972f1624ded711dc9cd92.tar.bz2 busybox-w32-47fe8d364ca68aef1ba972f1624ded711dc9cd92.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.
git-svn-id: svn://busybox.net/trunk/busybox@14496 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rwxr-xr-x | testsuite/testing.sh | 31 |
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 | |||
| 107 | function 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 | } | ||
