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>
This commit is contained in:
@@ -32,6 +32,79 @@ fi
|
|||||||
|
|
||||||
. "${test_srcdir}/libtest-core.sh"
|
. "${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() {
|
extract_child_pid() {
|
||||||
grep child-pid "$1" | sed "s/^.*: \([0-9]*\).*/\1/"
|
grep child-pid "$1" | sed "s/^.*: \([0-9]*\).*/\1/"
|
||||||
}
|
}
|
||||||
|
@@ -2,83 +2,11 @@
|
|||||||
|
|
||||||
set -xeuo pipefail
|
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=$(cd $(dirname $0) && pwd)
|
||||||
|
|
||||||
. ${srcd}/libtest.sh
|
. ${srcd}/libtest.sh
|
||||||
|
|
||||||
bn=$(basename $0)
|
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"
|
echo "1..56"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user