mirror of
https://github.com/systemd/systemd.git
synced 2025-01-03 05:18:09 +03:00
tests: build the image once and then copy/extend it
Building custom images for each test takes a lot of time. Build the default one, and if the test needs incompatible changes just copy it and extend it instead.
This commit is contained in:
parent
74eec54d66
commit
d9e606e89f
@ -7,19 +7,10 @@ TEST_REQUIRE_INSTALL_TESTS=0
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
setup_basic_environment
|
||||
mask_supporting_services
|
||||
|
||||
# install tests manually so the test is functional even when -Dinstall-tests=false
|
||||
mkdir -p $initdir/usr/lib/systemd/tests/testdata/units/
|
||||
cp -v $(dirname $0)/../units/{testsuite-01,end}.service $initdir/usr/lib/systemd/tests/testdata/units/
|
||||
)
|
||||
test_append_files() {
|
||||
# install tests manually so the test is functional even when -Dinstall-tests=false
|
||||
mkdir -p $1/usr/lib/systemd/tests/testdata/units/
|
||||
cp -v $(dirname $0)/../units/{testsuite-01,end}.service $1/usr/lib/systemd/tests/testdata/units/
|
||||
}
|
||||
|
||||
do_test "$@" 01
|
||||
|
@ -16,34 +16,27 @@ test -f /usr/share/selinux/devel/include/system/systemd.if || exit 0
|
||||
SETUP_SELINUX=yes
|
||||
KERNEL_APPEND="$KERNEL_APPEND selinux=1 security=selinux"
|
||||
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
test_append_files() {
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
|
||||
setup_basic_environment
|
||||
mask_supporting_services
|
||||
|
||||
setup_selinux
|
||||
local _modules_dir=/var/lib/selinux
|
||||
rm -rf $initdir/$_modules_dir
|
||||
if ! cp -ar $_modules_dir $initdir/$_modules_dir; then
|
||||
rm -rf $1/$_modules_dir
|
||||
if ! cp -ar $_modules_dir $1/$_modules_dir; then
|
||||
dfatal "Failed to copy $_modules_dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local _policy_headers_dir=/usr/share/selinux/devel
|
||||
rm -rf $initdir/$_policy_headers_dir
|
||||
rm -rf $1/$_policy_headers_dir
|
||||
inst_dir /usr/share/selinux
|
||||
if ! cp -ar $_policy_headers_dir $initdir/$_policy_headers_dir; then
|
||||
if ! cp -ar $_policy_headers_dir $1/$_policy_headers_dir; then
|
||||
dfatal "Failed to copy $_policy_headers_dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir $initdir/systemd-test-module
|
||||
cp systemd_test.te $initdir/systemd-test-module
|
||||
cp systemd_test.if $initdir/systemd-test-module
|
||||
mkdir $1/systemd-test-module
|
||||
cp systemd_test.te $1/systemd-test-module
|
||||
cp systemd_test.if $1/systemd-test-module
|
||||
dracut_install -o sesearch
|
||||
dracut_install runcon
|
||||
dracut_install checkmodule semodule semodule_package m4 make load_policy sefcontext_compile
|
||||
|
@ -7,16 +7,6 @@ TEST_NO_NSPAWN=1
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
QEMU_TIMEOUT=300
|
||||
FSTYPE=ext4
|
||||
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
setup_basic_environment
|
||||
)
|
||||
mask_supporting_services
|
||||
}
|
||||
TEST_FORCE_NEWIMAGE=1
|
||||
|
||||
do_test "$@" 08
|
||||
|
@ -6,17 +6,10 @@ TEST_NO_NSPAWN=1
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
test_append_files() {
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
setup_basic_environment
|
||||
mask_supporting_services
|
||||
|
||||
../create-busybox-container $initdir/testsuite-13.nc-container
|
||||
initdir="$initdir/testsuite-13.nc-container" dracut_install nc ip md5sum
|
||||
../create-busybox-container $1/testsuite-13.nc-container
|
||||
initdir="$1/testsuite-13.nc-container" dracut_install nc ip md5sum
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -6,16 +6,8 @@ TEST_NO_NSPAWN=1
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
setup_basic_environment
|
||||
mask_supporting_services
|
||||
printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id
|
||||
)
|
||||
test_append_files() {
|
||||
printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$1/etc/machine-id
|
||||
}
|
||||
|
||||
do_test "$@" 14
|
||||
|
@ -3,6 +3,7 @@ set -e
|
||||
TEST_DESCRIPTION="cryptsetup systemd setup"
|
||||
IMAGE_NAME="cryptsetup"
|
||||
TEST_NO_NSPAWN=1
|
||||
TEST_FORCE_NEWIMAGE=1
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
|
||||
|
@ -7,15 +7,8 @@ TEST_NO_NSPAWN=1
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
QEMU_TIMEOUT=300
|
||||
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
test_append_files() {
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
setup_basic_environment
|
||||
mask_supporting_services
|
||||
|
||||
instmods dummy
|
||||
generate_module_dependencies
|
||||
)
|
||||
|
@ -13,16 +13,8 @@ command -v veritysetup >/dev/null 2>&1 || exit 0
|
||||
command -v sfdisk >/dev/null 2>&1 || exit 0
|
||||
|
||||
# Need loop devices for systemd-dissect
|
||||
test_create_image() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
# Create what will eventually be our root filesystem onto an overlay
|
||||
# If some pieces are missing from the host, skip rather than fail
|
||||
test_append_files() {
|
||||
(
|
||||
LOG_LEVEL=5
|
||||
setup_basic_environment
|
||||
mask_supporting_services
|
||||
|
||||
instmods loop =block
|
||||
instmods squashfs =squashfs
|
||||
instmods dm_verity =md
|
||||
|
@ -17,6 +17,11 @@ TIMED_OUT= # will be 1 after run_* if *_TIMEOUT is set and test timed out
|
||||
UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
|
||||
EFI_MOUNT="${EFI_MOUNT:-$(bootctl -x 2>/dev/null || echo /boot)}"
|
||||
QEMU_MEM="${QEMU_MEM:-512M}"
|
||||
# Note that defining a different IMAGE_NAME in a test setup script will only result
|
||||
# in default.img being copied and renamed. It can then be extended by defining
|
||||
# a test_append_files() function. The $1 parameter will be the root directory.
|
||||
# To force creating a new image from scratch (eg: to encrypt it), also define
|
||||
# TEST_FORCE_NEWIMAGE=1 in the test setup script.
|
||||
IMAGE_NAME=${IMAGE_NAME:-default}
|
||||
TEST_REQUIRE_INSTALL_TESTS="${TEST_REQUIRE_INSTALL_TESTS:-1}"
|
||||
TEST_PARALLELIZE="${TEST_PARALLELIZE:-0}"
|
||||
@ -2065,24 +2070,43 @@ test_setup() {
|
||||
mount_initdir
|
||||
else
|
||||
if [ ! -e "$IMAGE_PUBLIC" ]; then
|
||||
# Create the backing public image, but then completely unmount
|
||||
# it and drop the loopback device responsible for it, since we're
|
||||
# going to symlink/copy the image and mount it again from
|
||||
# elsewhere.
|
||||
test_create_image
|
||||
test_setup_cleanup
|
||||
umount_loopback
|
||||
cleanup_loopdev
|
||||
# default.img is the base that every test uses and optionally appends to
|
||||
if [ ! -e "${IMAGESTATEDIR}/default.img" ] || [ -n "${TEST_FORCE_NEWIMAGE}" ]; then
|
||||
# Create the backing public image, but then completely unmount
|
||||
# it and drop the loopback device responsible for it, since we're
|
||||
# going to symlink/copy the image and mount it again from
|
||||
# elsewhere.
|
||||
local image_old=${IMAGE_PUBLIC}
|
||||
if [ -z "${TEST_FORCE_NEWIMAGE}" ]; then
|
||||
IMAGE_PUBLIC="${IMAGESTATEDIR}/default.img"
|
||||
fi
|
||||
test_create_image
|
||||
test_setup_cleanup
|
||||
umount_loopback
|
||||
cleanup_loopdev
|
||||
IMAGE_PUBLIC="${image_old}"
|
||||
fi
|
||||
if [ "${IMAGE_NAME}" != "default" ] && [ -z "${TEST_FORCE_NEWIMAGE}" ]; then
|
||||
cp -v "$(realpath "${IMAGESTATEDIR}/default.img")" "$IMAGE_PUBLIC"
|
||||
fi
|
||||
fi
|
||||
|
||||
local hook_defined=1
|
||||
if declare -f -F test_append_files > /dev/null; then
|
||||
hook_defined=$?
|
||||
fi
|
||||
|
||||
echo "Reusing existing cached image $IMAGE_PUBLIC → $(realpath $IMAGE_PUBLIC)"
|
||||
if [ ${TEST_PARALLELIZE} -ne 0 ]; then
|
||||
if [ ${TEST_PARALLELIZE} -ne 0 ] || [ ${hook_defined} -eq 0 ]; then
|
||||
cp -v "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE"
|
||||
else
|
||||
ln -sv "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE"
|
||||
fi
|
||||
|
||||
mount_initdir
|
||||
if [ ${hook_defined} -eq 0 ]; then
|
||||
test_append_files "$initdir"
|
||||
fi
|
||||
fi
|
||||
|
||||
setup_nspawn_root
|
||||
|
Loading…
Reference in New Issue
Block a user