From bb64bec589c0f8aa03c1be99fbd9302ee695f196 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Tue, 22 Dec 2020 17:45:50 +0000 Subject: [PATCH 1/7] test: update test_create_image Run mask_supporting_services, which was missing, and remove setup_nspawn_root which is now already called outside test_create_image --- test/TEST-01-BASIC/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh index 58f6cd1414..58ad6f8fd2 100755 --- a/test/TEST-01-BASIC/test.sh +++ b/test/TEST-01-BASIC/test.sh @@ -14,12 +14,12 @@ test_create_image() { ( 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/ ) - setup_nspawn_root } do_test "$@" 01 From 53a1c944805bb213cf22df0f65013dbb400d7bf5 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Tue, 22 Dec 2020 17:47:39 +0000 Subject: [PATCH 2/7] test: use pkg-config to get user unit dir when installing dbus user socket Usually on Debian ROOTLIBDIR is /lib/, which is not the right place. Use pkg-config since we define it, and then fallback to /usr/lib/systemd/user which is the canonical location. On both Debian&friends and Fedora dbus/dbus-broker install the user socket/service under /usr/lib/systemd/user, not /lib/systemd/systemd/user. --- test/test-functions | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/test-functions b/test/test-functions index 482cb7b490..03685f8da4 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1058,8 +1058,14 @@ EOF } install_user_dbus() { - inst $ROOTLIBDIR/user/dbus.socket - inst_symlink /usr/lib/systemd/user/sockets.target.wants/dbus.socket || inst_symlink /etc/systemd/user/sockets.target.wants/dbus.socket + local userunitdir + if ! userunitdir=$(pkg-config --variable=systemduserunitdir systemd); then + echo "WARNING! Cannot determine userunitdir from pkg-config, assuming /usr/lib/systemd/user" >&2 + local userunitdir=/usr/lib/systemd/user + fi + + inst $userunitdir/dbus.socket + inst_symlink $userunitdir/sockets.target.wants/dbus.socket || inst_symlink /etc/systemd/user/sockets.target.wants/dbus.socket # Append the After= dependency on dbus in case it isn't already set up mkdir -p "$initdir/etc/systemd/system/user@.service.d/" @@ -1069,16 +1075,16 @@ After=dbus.service EOF # Newer Fedora versions use dbus-broker by default. Let's install it if it's available. - if [ -f $ROOTLIBDIR/user/dbus-broker.service ]; then - inst $ROOTLIBDIR/user/dbus-broker.service + if [ -f $userunitdir/dbus-broker.service ]; then + inst $userunitdir/dbus-broker.service inst_symlink /etc/systemd/user/dbus.service elif [ -f $ROOTLIBDIR/system/dbus-daemon.service ]; then # Fedora rawhide replaced dbus.service with dbus-daemon.service - inst $ROOTLIBDIR/user/dbus-daemon.service + inst $userunitdir/dbus-daemon.service # Alias symlink inst_symlink /etc/systemd/user/dbus.service else - inst $ROOTLIBDIR/user/dbus.service + inst $userunitdir/dbus.service fi } From 0515e4c17d50dcdd9d903f5ac8b6d9988cb149fa Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Tue, 22 Dec 2020 17:50:34 +0000 Subject: [PATCH 3/7] test: check for binariers in [usr/][s]bin The image build function greps for ExecStart lines in unit files, but some of them (eg: systemd-firstboot) do not use a full path. It then falls back to 'type -P' but that only works if you have the binary installed. For optional binaries like systemd-firstboot, the installation can then fail. Manually check if the binary already exists in /[usr/][s]bin. --- test/test-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-functions b/test/test-functions index 03685f8da4..1359156b17 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1575,7 +1575,7 @@ inst_binary() { # In such cases, let's check if the binary indeed exists in the image # before doing any other chcecks. If it does, immediately return with # success. - [[ $# -eq 1 && -e $initdir/$1 ]] && return 0 + [[ $# -eq 1 && -e $initdir/$1 || -e $initdir/bin/$1 || -e $initdir/sbin/$1 || -e $initdir/usr/bin/$1 || -e $initdir/usr/sbin/$1 ]] && return 0 _bin=$(find_binary "$1") || return 1 _target=${2:-$_bin} From aeac20fc69e3c0fa5c3f0a15ecff6b0864afa628 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Tue, 22 Dec 2020 17:51:40 +0000 Subject: [PATCH 4/7] test: shortcut skip if both TEST_NO_QEMU and TEST_NO_NSPAWN are set Allows to run all tests in bulk with TEST_NO_QEMU, skipping those where it is mandatory, without wasting time building the image. --- test/test-functions | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test-functions b/test/test-functions index 1359156b17..52331d7845 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2107,6 +2107,11 @@ do_test() { exit 0 fi + if [ -n "$TEST_NO_QEMU" ] && [ -n "$TEST_NO_NSPAWN" ]; then + echo "TEST: $TEST_DESCRIPTION [SKIPPED]: both QEMU and nspawn disabled" >&2 + exit 0 + fi + # Detect lib paths [[ $libdir ]] || for libdir in /lib64 /lib; do [[ -d $libdir ]] && libdirs+=" $libdir" && break From 84d93585861ed69fc55ae39349e82c0120c66e17 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Tue, 22 Dec 2020 17:53:14 +0000 Subject: [PATCH 5/7] Do not run ninja in run-integration-tests.sh It is typically ran as root, while builds are done as normal users. It is documented anyway to build beforehand. --- test/run-integration-tests.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index 3c01adfca3..e9307601ff 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -10,8 +10,6 @@ fi args_no_clean=$(sed -r 's/\bclean.*\b//g' <<<$args) do_clean=$( [ "$args" = "$args_no_clean" ]; echo $? ) -ninja -C "$BUILD_DIR" - declare -A results declare -A times From 51d56d3be07953d0cf090f3311a81f1d3ada1dcf Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 26 Dec 2020 20:11:55 +0000 Subject: [PATCH 6/7] tests: add TEST_QEMU_ONLY variable to run only tests where qemu is mandatory Allows to split the test run in two parts. Most tests can run under nspawn which is much faster, and they can be ran in one chunk with TEST_NO_QEMU=1. The qemu-only tests, which are just a handful, can be ran in another chunk with TEST_QEMU_ONLY=1. Allows autopkgtest to be split in two parts. --- test/README.testsuite | 3 +++ test/test-functions | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/test/README.testsuite b/test/README.testsuite index 5d9e498c51..45bd239f34 100644 --- a/test/README.testsuite +++ b/test/README.testsuite @@ -47,6 +47,9 @@ Configuration variables TEST_NO_QEMU=1 Don't run tests under QEMU +TEST_QEMU_ONLY=1 + Run only tests that require QEMU + TEST_NO_NSPAWN=1 Don't run tests under systemd-nspawn diff --git a/test/test-functions b/test/test-functions index 52331d7845..a88a8d2c04 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2112,6 +2112,11 @@ do_test() { exit 0 fi + if [ -n "$TEST_QEMU_ONLY" ] && [ -z "$TEST_NO_NSPAWN" ]; then + echo "TEST: $TEST_DESCRIPTION [SKIPPED]: QEMU-only tests requested" >&2 + exit 0 + fi + # Detect lib paths [[ $libdir ]] || for libdir in /lib64 /lib; do [[ -d $libdir ]] && libdirs+=" $libdir" && break From eb3785f36798a9b692824c3258fd653d0fe5a0ca Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 31 Dec 2020 17:29:58 +0000 Subject: [PATCH 7/7] tests: add TEST_PREFER_NSPAWN variable to run as many as possible under nspawn By default the test suite prefers qemu, and uses nspawn only if a test specifically says it doesn't support qemu. Add a variable to allow flipping the default, and run as many tests under nspawn as possible. --- test/README.testsuite | 3 +++ test/test-functions | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/test/README.testsuite b/test/README.testsuite index 45bd239f34..5dd559e365 100644 --- a/test/README.testsuite +++ b/test/README.testsuite @@ -53,6 +53,9 @@ TEST_QEMU_ONLY=1 TEST_NO_NSPAWN=1 Don't run tests under systemd-nspawn +TEST_PREFER_NSPAWN=1 + Run all tests that do not require qemu under systemd-nspawn + TEST_NO_KVM=1 Disable QEMU KVM auto-detection (may be necessary when you're trying to run the *vanilla* QEMU and have both qemu and qemu-kvm installed) diff --git a/test/test-functions b/test/test-functions index a88a8d2c04..06dea3c7be 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2117,6 +2117,10 @@ do_test() { exit 0 fi + if [ -n "$TEST_PREFER_NSPAWN" ] && [ -z "$TEST_NO_NSPAWN" ]; then + TEST_NO_QEMU=1 + fi + # Detect lib paths [[ $libdir ]] || for libdir in /lib64 /lib; do [[ -d $libdir ]] && libdirs+=" $libdir" && break