From bdee55672a8c936c97214ca13ae996b4d9015f72 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Wed, 7 Jun 2023 13:51:02 +0200 Subject: [PATCH 1/4] test: merge TEST-61-UNITTESTS-QEMU with TEST-02-UNITTESTS The test was originally introduced for Ubuntu CI, as it uses PREFER_NSPAWN=1, but it was subsequently disabled two years ago [0], so it was pretty much useless. Let's merge it into TEST-02 and tweak it a bit to run only certain tests under QEMU when $TEST_PREFER_NSPAWN is set. [0] b152adbfa9b708dade8559b9962241902bf2eb7c --- test/TEST-02-UNITTESTS/test.sh | 15 +++++++--- test/TEST-61-UNITTESTS-QEMU/Makefile | 1 - .../deny-list-ubuntu-ci | 0 test/TEST-61-UNITTESTS-QEMU/test.sh | 28 ------------------- test/units/testsuite-02.sh | 10 ++++++- test/units/testsuite-61.service | 8 ------ test/units/testsuite-61.sh | 11 -------- 7 files changed, 20 insertions(+), 53 deletions(-) delete mode 120000 test/TEST-61-UNITTESTS-QEMU/Makefile delete mode 100644 test/TEST-61-UNITTESTS-QEMU/deny-list-ubuntu-ci delete mode 100755 test/TEST-61-UNITTESTS-QEMU/test.sh delete mode 100644 test/units/testsuite-61.service delete mode 100755 test/units/testsuite-61.sh diff --git a/test/TEST-02-UNITTESTS/test.sh b/test/TEST-02-UNITTESTS/test.sh index 3646aa678e..f165c99368 100755 --- a/test/TEST-02-UNITTESTS/test.sh +++ b/test/TEST-02-UNITTESTS/test.sh @@ -2,6 +2,9 @@ # SPDX-License-Identifier: LGPL-2.1-or-later set -e +# shellcheck source=test/test-functions +. "${TEST_BASE_DIR:?}/test-functions" + TEST_DESCRIPTION="Run unit tests under containers" RUN_IN_UNPRIVILEGED_CONTAINER=yes # Some tests make collecting coverage impossible (like test-mount-util, which @@ -9,8 +12,12 @@ RUN_IN_UNPRIVILEGED_CONTAINER=yes # case IGNORE_MISSING_COVERAGE=yes -# embed some newlines in the kernel command line to stress our test suite +# Embed some newlines in the kernel command line to stress our test suite +# Also, pass $TEST_PREFER_NSPAWN to the VM/container if set +# +# shellcheck disable=SC2015 KERNEL_APPEND=" +$(get_bool "${TEST_PREFER_NSPAWN:-0}" && echo "systemd.setenv=TEST_PREFER_NSPAWN=1" || :) frobnicate! @@ -19,9 +26,9 @@ systemd.setenv=TEST_CMDLINE_NEWLINE=bar $KERNEL_APPEND " - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" +# Override $TEST_PREFER_NSPAWN if it was set to always run both the QEMU and +# the nspawn part of the test +TEST_PREFER_NSPAWN=no test_append_files() { if get_bool "$LOOKS_LIKE_SUSE"; then diff --git a/test/TEST-61-UNITTESTS-QEMU/Makefile b/test/TEST-61-UNITTESTS-QEMU/Makefile deleted file mode 120000 index e9f93b1104..0000000000 --- a/test/TEST-61-UNITTESTS-QEMU/Makefile +++ /dev/null @@ -1 +0,0 @@ -../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-61-UNITTESTS-QEMU/deny-list-ubuntu-ci b/test/TEST-61-UNITTESTS-QEMU/deny-list-ubuntu-ci deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/TEST-61-UNITTESTS-QEMU/test.sh b/test/TEST-61-UNITTESTS-QEMU/test.sh deleted file mode 100755 index 45c5f71bfe..0000000000 --- a/test/TEST-61-UNITTESTS-QEMU/test.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -set -e - -TEST_DESCRIPTION="Run unit tests under qemu" -# this subset of unit tests requires qemu, so they are ran here to avoid slowing down TEST-02 -TEST_NO_NSPAWN=1 - -# embed some newlines in the kernel command line to stress our test suite -KERNEL_APPEND=" - -frobnicate! - -$KERNEL_APPEND -" - -# shellcheck source=test/test-functions -. "${TEST_BASE_DIR:?}/test-functions" - -check_result_nspawn() { - check_result_nspawn_unittests "${1}" -} - -check_result_qemu() { - check_result_qemu_unittests -} - -do_test "$@" diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index ca54fc4018..f0e0f091fd 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -9,9 +9,17 @@ if ! systemd-detect-virt -qc && [[ "${TEST_CMDLINE_NEWLINE:-}" != bar ]]; then exit 1 fi +# If we're running with TEST_PREFER_NSPAWN=1 limit the set of tests we run +# in QEMU to only those that can't run in a container to avoid running +# the same tests again in a, most likely, very slow environment +if ! systemd-detect-virt -qc && [[ "${TEST_PREFER_NSPAWN:-0}" -ne 0 ]]; then + TESTS_GLOB="test-loop-block" +else + TESTS_GLOB=${TESTS_GLOB:-test-*} +fi + NPROC=$(nproc) MAX_QUEUE_SIZE=${NPROC:-2} -TESTS_GLOB=${TESTS_GLOB:-test-*} mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/unit-tests/ -maxdepth 1 -type f -name "${TESTS_GLOB}") # reset state diff --git a/test/units/testsuite-61.service b/test/units/testsuite-61.service deleted file mode 100644 index 568960c21d..0000000000 --- a/test/units/testsuite-61.service +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Unit] -Description=TEST-61-UNITTESTS-QEMU - -[Service] -ExecStartPre=rm -f /failed /testok -ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh -Type=oneshot diff --git a/test/units/testsuite-61.sh b/test/units/testsuite-61.sh deleted file mode 100755 index 0b7b0116d3..0000000000 --- a/test/units/testsuite-61.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later -# shellcheck disable=SC2317 -set -eux -set -o pipefail - -TESTS_GLOB="test-loop-block" -# shellcheck source=test/units/testsuite-02.sh -. "$(dirname "$0")/testsuite-02.sh" - -exit 0 From a6695a431fec4291c956bbbecda19c468ccccb1d Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 12 Jun 2023 13:21:11 +0200 Subject: [PATCH 2/4] test: copy file xattrs (if any) as well --- test/test-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-functions b/test/test-functions index 8baf16d335..0c20e60ad3 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2590,7 +2590,7 @@ inst_simple() { inst "${src%/*}/.${src##*/}.hmac" "${target%/*}/.${target##*/}.hmac" fi ddebug "Installing $src" - cp --sparse=always -pfL "$src" "${initdir}/$target" + cp --sparse=always --force --dereference --preserve=all "$src" "${initdir}/$target" } # find symlinks linked to given library file From f087837c46d77745425fd9b84f1de9e5703836af Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 12 Jun 2023 14:13:25 +0200 Subject: [PATCH 3/4] test: make sure ping works for unprivileged users --- test/units/testsuite-02.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/units/testsuite-02.sh b/test/units/testsuite-02.sh index f0e0f091fd..4c4479287f 100755 --- a/test/units/testsuite-02.sh +++ b/test/units/testsuite-02.sh @@ -22,9 +22,14 @@ NPROC=$(nproc) MAX_QUEUE_SIZE=${NPROC:-2} mapfile -t TEST_LIST < <(find /usr/lib/systemd/tests/unit-tests/ -maxdepth 1 -type f -name "${TESTS_GLOB}") -# reset state +# Reset state rm -fv /failed-tests /skipped-tests /skipped +if ! systemd-detect-virt -qc; then + # Make sure ping works for unprivileged users (for test-bpf-firewall) + sysctl net.ipv4.ping_group_range="0 2147483647" +fi + # Check & report test results # Arguments: # $1: test path From fb310ba9ebb1a4f2b6fc76c75b3bb9a99f1a2a9a Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 12 Jun 2023 15:43:54 +0200 Subject: [PATCH 4/4] test: re-enable TEST-02 on ppc64le --- test/TEST-02-UNITTESTS/deny-list-ubuntu-ci-ppc64el | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/TEST-02-UNITTESTS/deny-list-ubuntu-ci-ppc64el diff --git a/test/TEST-02-UNITTESTS/deny-list-ubuntu-ci-ppc64el b/test/TEST-02-UNITTESTS/deny-list-ubuntu-ci-ppc64el deleted file mode 100644 index e69de29bb2..0000000000