From ff40235b9bd2a944131c36b1c7ccfd88f49a194e Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 19 May 2023 10:48:15 +0200 Subject: [PATCH 1/3] test: make the stress test slightly less stressful on slower machines Without acceleration this part of the test takes over 10 minutes (!), which feels quite unnecessary. Let's cut down the number of stuff we dump to the journal in such case, but keep the original value if we run with acceleration (since in that case it takes less than 10 seconds). --- test/units/testsuite-04.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh index 7c1565bf15..3c4c8afd53 100755 --- a/test/units/testsuite-04.sh +++ b/test/units/testsuite-04.sh @@ -8,7 +8,8 @@ trap "journalctl --rotate --vacuum-size=16M" EXIT # Rotation/flush test, see https://github.com/systemd/systemd/issues/19895 journalctl --relinquish-var -for _ in {0..50}; do +[[ "$(systemd-detect-virt -v)" == "qemu" ]] && ITERATIONS=10 || ITERATIONS=50 +for ((i = 0; i < ITERATIONS; i++)); do dd if=/dev/urandom bs=1M count=1 | base64 | systemd-cat done journalctl --rotate From daeb95a1d8c638027edd20ab76a6facfa33fcfe9 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 19 May 2023 11:07:07 +0200 Subject: [PATCH 2/3] test: drop generated stuff from the final coverage report Let's drop stuff from the current $BUILD_DIR from the final coverage report, as it's all generated files (mostly gperf) which we don't really care about and it makes the Coveralls report confusing, since it reports "source not available" for all such files. --- test/test-functions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test-functions b/test/test-functions index 057b748f81..3a2a59758f 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1513,8 +1513,8 @@ check_coverage_reports() { return 1 fi - # Create a coverage report that will later be uploaded. Remove info about - # system libraries/headers, as we don't really care about them. + # Create a coverage report that will later be uploaded. Remove info about system + # libraries/headers and generated files, as we don't really care about them. lcov --directory "${root}/${BUILD_DIR:?}" --capture --output-file "${dest}.new" if [[ -f "$dest" ]]; then # If the destination report file already exists, don't overwrite it, but @@ -1526,7 +1526,7 @@ check_coverage_reports() { # report we did during the setup phase (see test_setup()). lcov --add-tracefile "${TESTDIR:?}/coverage-base" --add-tracefile "${dest}.new" -o "${dest}" fi - lcov --remove "$dest" -o "$dest" '/usr/include/*' '/usr/lib/*' + lcov --remove "$dest" -o "$dest" '/usr/include/*' '/usr/lib/*' "${BUILD_DIR:?}/*" rm -f "${dest}.new" # If the test logs contain lines like: From 038efe6df154b04a4c2a1d9da7263e5f49d2a1b0 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 19 May 2023 11:45:11 +0200 Subject: [PATCH 3/3] test: build the SELinux test module on the host Let's save some time and build the SELinux test module on the host instead of a possibly unaccelerated VM. This brings the runtime of TEST-06-SELINUX from ~12 minutes down to a ~1 minute. --- test/TEST-06-SELINUX/test.sh | 58 ++++++++++--------- .../load-systemd-test-module.service | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/test/TEST-06-SELINUX/test.sh b/test/TEST-06-SELINUX/test.sh index a867dea4b7..5d72638ec6 100755 --- a/test/TEST-06-SELINUX/test.sh +++ b/test/TEST-06-SELINUX/test.sh @@ -7,7 +7,6 @@ IMAGE_NAME="selinux" TEST_NO_NSPAWN=1 # Requirements: -# Fedora 23 # selinux-policy-targeted # selinux-policy-devel @@ -21,38 +20,41 @@ SETUP_SELINUX=yes KERNEL_APPEND="${KERNEL_APPEND:=} selinux=1 security=selinux" test_append_files() { - ( - local workspace="${1:?}" - local policy_headers_dir=/usr/share/selinux/devel - local modules_dir=/var/lib/selinux + local workspace="${1:?}" + local policy_headers_dir=/usr/share/selinux/devel + local modules_dir=/var/lib/selinux - setup_selinux - # Make sure we never expand this to "/..." - rm -rf "${workspace:?}/$modules_dir" + setup_selinux + # Make sure we never expand this to "/..." + rm -rf "${workspace:?}/$modules_dir" - if ! cp -ar "$modules_dir" "$workspace/$modules_dir"; then - dfatal "Failed to copy $modules_dir" - exit 1 - fi + if ! cp -ar "$modules_dir" "$workspace/$modules_dir"; then + dfatal "Failed to copy $modules_dir" + exit 1 + fi - rm -rf "${workspace:?}/$policy_headers_dir" - inst_dir /usr/share/selinux + rm -rf "${workspace:?}/$policy_headers_dir" + inst_dir /usr/share/selinux - if ! cp -ar "$policy_headers_dir" "$workspace/$policy_headers_dir"; then - dfatal "Failed to copy $policy_headers_dir" - exit 1 - fi + if ! cp -ar "$policy_headers_dir" "$workspace/$policy_headers_dir"; then + dfatal "Failed to copy $policy_headers_dir" + exit 1 + fi - mkdir "$workspace/systemd-test-module" - cp systemd_test.te "$workspace/systemd-test-module" - cp systemd_test.if "$workspace/systemd-test-module" - cp systemd_test.fc "$workspace/systemd-test-module" - image_install -o sesearch - image_install runcon - image_install checkmodule semodule semodule_package m4 make load_policy sefcontext_compile - image_install -o /usr/libexec/selinux/hll/pp # Fedora/RHEL/... - image_install -o /usr/lib/selinux/hll/pp # Debian/Ubuntu/... - ) + mkdir "$workspace/systemd-test-module" + cp systemd_test.te "$workspace/systemd-test-module" + cp systemd_test.if "$workspace/systemd-test-module" + cp systemd_test.fc "$workspace/systemd-test-module" + image_install -o sesearch + image_install runcon + image_install checkmodule semodule semodule_package m4 make load_policy sefcontext_compile + image_install -o /usr/libexec/selinux/hll/pp # Fedora/RHEL/... + image_install -o /usr/lib/selinux/hll/pp # Debian/Ubuntu/... + + if ! chroot "$workspace" make -C /systemd-test-module -f /usr/share/selinux/devel/Makefile clean systemd_test.pp; then + dfatal "Failed to build the systemd test module" + exit 1 + fi } do_test "$@" diff --git a/test/testsuite-06.units/load-systemd-test-module.service b/test/testsuite-06.units/load-systemd-test-module.service index 3a22c15b25..2d15a62715 100644 --- a/test/testsuite-06.units/load-systemd-test-module.service +++ b/test/testsuite-06.units/load-systemd-test-module.service @@ -9,7 +9,7 @@ Before=sysinit.target shutdown.target autorelabel.service ConditionSecurity=selinux [Service] -ExecStart=sh -x -c 'echo 0 >/sys/fs/selinux/enforce && cd /systemd-test-module && make -f /usr/share/selinux/devel/Makefile clean load' +ExecStart=sh -x -c 'echo 0 >/sys/fs/selinux/enforce && make -C /systemd-test-module -f /usr/share/selinux/devel/Makefile load' Type=oneshot TimeoutSec=0 RemainAfterExit=yes