From eca90a6fcec2ea1a6e37668e5d68a53e1ed0b574 Mon Sep 17 00:00:00 2001 From: Michal Domonkos Date: Fri, 27 Oct 2023 10:48:31 +0200 Subject: [PATCH] Move snapshot to atlocal --- tests/atlocal.in | 51 ++++++++++++++++++++++++++++++++++++++++++++- tests/mktree.common | 49 ------------------------------------------- tests/rpmtests.sh | 17 ++++----------- 3 files changed, 54 insertions(+), 63 deletions(-) diff --git a/tests/atlocal.in b/tests/atlocal.in index 227718feed..45973937de 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -51,6 +51,56 @@ if ! LD_PRELOAD=${MALLOC_DEBUG} /bin/true 2>&1 | grep -q ERROR; then export LD_PRELOAD GLIBC_TUNABLES fi +# Manage lightweight Bubblewrap containers on top of OverlayFS +snapshot() +{ + local cmd=$1 + shift + case $cmd in + mount) + # No argument means mount as read-only + local opts + if [ $# != 0 ]; then + mkdir -p $1/diff $1/work + opts="-o upperdir=$1/diff,workdir=$1/work" + fi + [ ${ROOTLESS:-1} == 1 ] && opts+=" -o userxattr" + mkdir -p ${RPMTEST} + mount -t overlay sandbox \ + -o lowerdir="${RPMTREE}" \ + ${opts} ${RPMTEST} + ;; + umount) + umount -ql $RPMTEST + ;; + prune) + local dir + for dir in "$@"; do + [ -d "$dir" ] && umount -ql $dir + done + return 0 + ;; + exec) + bwrap --unshare-pid --dev-bind $RPMTEST / --clearenv \ + --setenv PATH $(env -i sh -c 'echo $PATH') \ + --setenv HOME /root --chdir / --dev /dev --proc /proc \ + --die-with-parent "$@" + ;; + shell) + local source=$(findmnt -no SOURCE --mountpoint $RPMTEST) + local passwd=$RPMTEST/etc/passwd + if [ $# == 0 ]; then + if [ -f "$passwd" ]; then + set -- $(grep ^root: $passwd | cut -d: -f7) + else + set -- sh + fi + fi + snapshot exec --unshare-uts --hostname $source "$@" + ;; + esac +} + function setup_env() { if [ -d tree ]; then @@ -94,5 +144,4 @@ function runroot_other() snapshot exec "$@" } -source ./mktree.common snapshot prune rpmtests.dir/*/tree diff --git a/tests/mktree.common b/tests/mktree.common index 3bb8692547..12f2898c40 100644 --- a/tests/mktree.common +++ b/tests/mktree.common @@ -23,52 +23,3 @@ make_install() mkdir -p $DESTDIR/build ln -sf ../data/SOURCES $DESTDIR/build/ } - -snapshot() -{ - local cmd=$1 - shift - case $cmd in - mount) - # No argument means mount as read-only - local opts - if [ $# != 0 ]; then - mkdir -p $1/diff $1/work - opts="-o upperdir=$1/diff,workdir=$1/work" - fi - [ ${ROOTLESS:-1} == 1 ] && opts+=" -o userxattr" - mkdir -p ${RPMTEST} - mount -t overlay sandbox \ - -o lowerdir="${RPMTREE}" \ - ${opts} ${RPMTEST} - ;; - umount) - umount -ql $RPMTEST - ;; - prune) - local dir - for dir in "$@"; do - [ -d "$dir" ] && umount -ql $dir - done - return 0 - ;; - exec) - bwrap --unshare-pid --dev-bind $RPMTEST / --clearenv \ - --setenv PATH $(env -i sh -c 'echo $PATH') \ - --setenv HOME /root --chdir / --dev /dev --proc /proc \ - --die-with-parent "$@" - ;; - shell) - local source=$(findmnt -no SOURCE --mountpoint $RPMTEST) - local passwd=$RPMTEST/etc/passwd - if [ $# == 0 ]; then - if [ -f "$passwd" ]; then - set -- $(grep ^root: $passwd | cut -d: -f7) - else - set -- sh - fi - fi - snapshot exec --unshare-uts --hostname $source "$@" - ;; - esac -} diff --git a/tests/rpmtests.sh b/tests/rpmtests.sh index 68138406e1..b977867576 100755 --- a/tests/rpmtests.sh +++ b/tests/rpmtests.sh @@ -11,13 +11,10 @@ # delete the test created with --shell SCRIPT_DIR=$(dirname $(readlink -f $0)) -SCRIPT_FILES="atlocal mktree.common" - -PRINT_LOG=0 -RC=0 - SHELL_DIR=$PWD/rpmtests.dir/shell +PRINT_LOG=0 RUN_SHELL=0 +RC=0 fixperms() { @@ -47,10 +44,7 @@ while [ $# != 0 ]; do shift done -# Symlink script files into $PWD, prefer local versions though -for file in $SCRIPT_FILES; do - [ -f "$file" ] || ln -s $SCRIPT_DIR/$file . -done +[ -f atlocal ] || ln -s $SCRIPT_DIR/atlocal . # Run the test suite (or a shell) if [ $RUN_SHELL == 0 ]; then @@ -73,9 +67,6 @@ else fixperms $SHELL_DIR fi -# Clean up the symlinks -for file in $SCRIPT_FILES; do - [ -L "$file" ] && rm "$file" -done +[ -L atlocal ] && rm atlocal exit $RC