Skip to content

Commit

Permalink
Move snapshot to atlocal
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnks committed Oct 27, 2023
1 parent 1881ad9 commit eca90a6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 63 deletions.
51 changes: 50 additions & 1 deletion tests/atlocal.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,5 +144,4 @@ function runroot_other()
snapshot exec "$@"
}

source ./mktree.common
snapshot prune rpmtests.dir/*/tree
49 changes: 0 additions & 49 deletions tests/mktree.common
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 4 additions & 13 deletions tests/rpmtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit eca90a6

Please sign in to comment.