summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-06-28 10:49:41 +0100
committerSimon McVittie <smcv@collabora.com>2021-06-28 11:11:29 +0100
commit4d03c2a727ee6b5a12f31e4d01bc52d80a26b51b (patch)
treeaa3c1cf6fa132d53e1c8dd04579e90cc90f5f5bc
parent0d88fe5e60f08b8afbd2f2546e5f436871aa5112 (diff)
downloadbubblewrap-4d03c2a727ee6b5a12f31e4d01bc52d80a26b51b.tar.gz
Extract some common test setup into libtest.sh
This will allow test-run.sh to be split up into more/smaller scripts. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--tests/libtest.sh73
-rwxr-xr-xtests/test-run.sh72
2 files changed, 73 insertions, 72 deletions
diff --git a/tests/libtest.sh b/tests/libtest.sh
index 41b209b..a0d6fbc 100644
--- a/tests/libtest.sh
+++ b/tests/libtest.sh
@@ -32,6 +32,79 @@ fi
. "${test_srcdir}/libtest-core.sh"
+# Make sure /sbin/getpcaps etc. are in our PATH even if non-root
+PATH="$PATH:/usr/sbin:/sbin"
+
+tempdir=$(mktemp -d /var/tmp/tap-test.XXXXXX)
+touch ${tempdir}/.testtmp
+function cleanup () {
+ if test -n "${TEST_SKIP_CLEANUP:-}"; then
+ echo "Skipping cleanup of ${test_tmpdir}"
+ else if test -f ${tempdir}/.test; then
+ rm "${tempdir}" -rf
+ fi
+ fi
+}
+trap cleanup EXIT
+cd ${tempdir}
+
+: "${BWRAP:=bwrap}"
+if test -u "$(type -p ${BWRAP})"; then
+ bwrap_is_suid=true
+fi
+
+FUSE_DIR=
+for mp in $(cat /proc/self/mounts | grep " fuse[. ]" | grep user_id=$(id -u) | awk '{print $2}'); do
+ if test -d $mp; then
+ echo "# Using $mp as test fuse mount"
+ FUSE_DIR=$mp
+ break
+ fi
+done
+
+if test "$(id -u)" = "0"; then
+ is_uidzero=true
+else
+ is_uidzero=false
+fi
+
+# This is supposed to be an otherwise readable file in an unreadable (by the user) dir
+UNREADABLE=/root/.bashrc
+if ${is_uidzero} || test -x `dirname $UNREADABLE`; then
+ UNREADABLE=
+fi
+
+# https://github.com/projectatomic/bubblewrap/issues/217
+# are we on a merged-/usr system?
+if [ /lib -ef /usr/lib ]; then
+ BWRAP_RO_HOST_ARGS="--ro-bind /usr /usr
+ --ro-bind /etc /etc
+ --dir /var/tmp
+ --symlink usr/lib /lib
+ --symlink usr/lib64 /lib64
+ --symlink usr/bin /bin
+ --symlink usr/sbin /sbin
+ --proc /proc
+ --dev /dev"
+else
+ BWRAP_RO_HOST_ARGS="--ro-bind /usr /usr
+ --ro-bind /etc /etc
+ --ro-bind /bin /bin
+ --ro-bind /lib /lib
+ --ro-bind-try /lib64 /lib64
+ --ro-bind /sbin /sbin
+ --dir /var/tmp
+ --proc /proc
+ --dev /dev"
+fi
+
+# Default arg, bind whole host fs to /, tmpfs on /tmp
+RUN="${BWRAP} --bind / / --tmpfs /tmp"
+
+if [ -z "${BWRAP_MUST_WORK-}" ] && ! $RUN true; then
+ skip Seems like bwrap is not working at all. Maybe setuid is not working
+fi
+
extract_child_pid() {
grep child-pid "$1" | sed "s/^.*: \([0-9]*\).*/\1/"
}
diff --git a/tests/test-run.sh b/tests/test-run.sh
index 852e65d..0688468 100755
--- a/tests/test-run.sh
+++ b/tests/test-run.sh
@@ -2,83 +2,11 @@
set -xeuo pipefail
-# Make sure /sbin/getpcaps etc. are in our PATH even if non-root
-PATH="$PATH:/usr/sbin:/sbin"
-
srcd=$(cd $(dirname $0) && pwd)
. ${srcd}/libtest.sh
bn=$(basename $0)
-tempdir=$(mktemp -d /var/tmp/tap-test.XXXXXX)
-touch ${tempdir}/.testtmp
-function cleanup () {
- if test -n "${TEST_SKIP_CLEANUP:-}"; then
- echo "Skipping cleanup of ${test_tmpdir}"
- else if test -f ${tempdir}/.test; then
- rm "${tempdir}" -rf
- fi
- fi
-}
-trap cleanup EXIT
-cd ${tempdir}
-
-: "${BWRAP:=bwrap}"
-if test -u "$(type -p ${BWRAP})"; then
- bwrap_is_suid=true
-fi
-
-FUSE_DIR=
-for mp in $(cat /proc/self/mounts | grep " fuse[. ]" | grep user_id=$(id -u) | awk '{print $2}'); do
- if test -d $mp; then
- echo "# Using $mp as test fuse mount"
- FUSE_DIR=$mp
- break
- fi
-done
-
-if test "$(id -u)" = "0"; then
- is_uidzero=true
-else
- is_uidzero=false
-fi
-
-# This is supposed to be an otherwise readable file in an unreadable (by the user) dir
-UNREADABLE=/root/.bashrc
-if ${is_uidzero} || test -x `dirname $UNREADABLE`; then
- UNREADABLE=
-fi
-
-# https://github.com/projectatomic/bubblewrap/issues/217
-# are we on a merged-/usr system?
-if [ /lib -ef /usr/lib ]; then
- BWRAP_RO_HOST_ARGS="--ro-bind /usr /usr
- --ro-bind /etc /etc
- --dir /var/tmp
- --symlink usr/lib /lib
- --symlink usr/lib64 /lib64
- --symlink usr/bin /bin
- --symlink usr/sbin /sbin
- --proc /proc
- --dev /dev"
-else
- BWRAP_RO_HOST_ARGS="--ro-bind /usr /usr
- --ro-bind /etc /etc
- --ro-bind /bin /bin
- --ro-bind /lib /lib
- --ro-bind-try /lib64 /lib64
- --ro-bind /sbin /sbin
- --dir /var/tmp
- --proc /proc
- --dev /dev"
-fi
-
-# Default arg, bind whole host fs to /, tmpfs on /tmp
-RUN="${BWRAP} --bind / / --tmpfs /tmp"
-
-if [ -z "${BWRAP_MUST_WORK-}" ] && ! $RUN true; then
- skip Seems like bwrap is not working at all. Maybe setuid is not working
-fi
echo "1..56"