From c049acb22e6af24fdb1afff867daa8bed37a86a2 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 22 Nov 2021 20:51:15 +0100 Subject: [PATCH 1/3] test: fix a couple of "new" shellcheck-related issues related to https://github.com/koalaman/shellcheck/wiki/SC2295 --- test/test-functions | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test-functions b/test/test-functions index 00a808bf28..d3705653ae 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2083,7 +2083,7 @@ dfatal() { # Generic substring function. If $2 is in $1, return 0. -strstr() { [ "${1#*$2*}" != "$1" ]; } +strstr() { [ "${1#*"$2"*}" != "$1" ]; } # normalize_path # Prints the normalized path, where it removes any duplicated @@ -2498,12 +2498,12 @@ image_install() { install_kmod_with_fw() { local module="${1:?}" # no need to go further if the module is already installed - [[ -e "${initdir:?}/lib/modules/${KERNEL_VER:?}/${module##*/lib/modules/$KERNEL_VER/}" ]] && return 0 + [[ -e "${initdir:?}/lib/modules/${KERNEL_VER:?}/${module##*"/lib/modules/$KERNEL_VER/"}" ]] && return 0 [[ -e "$initdir/.kernelmodseen/${module##*/}" ]] && return 0 [ -d "$initdir/.kernelmodseen" ] && : >"$initdir/.kernelmodseen/${module##*/}" - inst_simple "$module" "/lib/modules/$KERNEL_VER/${module##*/lib/modules/$KERNEL_VER/}" || return $? + inst_simple "$module" "/lib/modules/$KERNEL_VER/${module##*"/lib/modules/$KERNEL_VER/"}" || return $? local modname="${module##*/}" local fwdir found fw From f201f3447796a5424372d32b338bc3b907516c28 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 22 Nov 2021 20:13:51 +0100 Subject: [PATCH 2/3] test: suppress certain leaks reported by LSan so we can run TEST-46 under sanitizers once again. `systemd-homed` runs fsck on home directories, which reports a memory leak we're not interested in. Let's introduce an LSan suppression file to get around this. Since the patterns in the suppression file are matched using basic substring match[0], they're a bit cumbersome, but should get the work one. [0] https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions Example leaks (as reported by TEST-46): ``` systemd-homed[1333]: ================================================================= systemd-homed[1333]: ==1333==ERROR: LeakSanitizer: detected memory leaks systemd-homed[1333]: Direct leak of 24 byte(s) in 1 object(s) allocated from: systemd-homed[1333]: #0 0x7f0c8facccd1 in calloc (/usr/lib/clang/12.0.1/lib/linux/libclang_rt.asan-x86_64.so+0xf4cd1) systemd-homed[1333]: #1 0x558d9494ff67 (/usr/bin/fsck+0x3f67) systemd-homed[1333]: Direct leak of 6 byte(s) in 1 object(s) allocated from: systemd-homed[1333]: #0 0x7f0c8fa906c1 in strdup (/usr/lib/clang/12.0.1/lib/linux/libclang_rt.asan-x86_64.so+0xb86c1) systemd-homed[1333]: #1 0x558d949518fd (/usr/bin/fsck+0x58fd) systemd-homed[1333]: SUMMARY: AddressSanitizer: 30 byte(s) leaked in 2 allocation(s). systemd-homed[1337]: ==1337==WARNING: Symbolizer was blocked from starting itself! systemd-homed[1337]: ================================================================= systemd-homed[1337]: ==1337==ERROR: LeakSanitizer: detected memory leaks systemd-homed[1337]: Direct leak of 67584 byte(s) in 1 object(s) allocated from: systemd-homed[1337]: #0 0x7f01edb84b19 (/usr/lib/clang/12.0.1/lib/linux/libclang_rt.asan-x86_64.so+0xf4b19) systemd-homed[1337]: #1 0x7f01e8326829 (/usr/bin/../lib/libLLVM-12.so+0xb46829) systemd-homed[1337]: SUMMARY: AddressSanitizer: 67584 byte(s) leaked in 1 allocation(s). ``` With the suppression file: ``` systemd-homed[1339]: ----------------------------------------------------- systemd-homed[1339]: Suppressions used: systemd-homed[1339]: count bytes template systemd-homed[1339]: 2 30 /bin/fsck$ systemd-homed[1339]: ----------------------------------------------------- systemd-homed[1343]: ==1343==WARNING: Symbolizer was blocked from starting itself! systemd-homed[1343]: ----------------------------------------------------- systemd-homed[1343]: Suppressions used: systemd-homed[1343]: count bytes template systemd-homed[1343]: 1 67584 /lib/libLLVM systemd-homed[1343]: ----------------------------------------------------- ``` --- test/test-functions | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test-functions b/test/test-functions index d3705653ae..a4b7efb5ec 100644 --- a/test/test-functions +++ b/test/test-functions @@ -778,9 +778,23 @@ if [[ ! -e "$ASAN_RT_PATH" ]]; then exit 1 fi +# Suppress certain leaks reported by LSan (either in external tools or bogus +# ones) +# Docs: # https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer#suppressions +# +# - fsck is called by systemd-homed and is reporting a leak we're not interested +# in +# - libLLVM is a "side effect" caused by the previous fsck leak +cat >/systemd-lsan.supp < not found" issues in the future From c83f126a41cfc964f43a30f1089a73e61908868a Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 22 Nov 2021 22:12:09 +0100 Subject: [PATCH 3/3] test: drop the `su` wrapper and use `systemctl` directly ASan is having a hard time to get its LD_PRELOAD= shenanigans straight with all the shells flying around. Let's make it a bit easier by using one of the nifty systemctl's features instead. --- test/units/testsuite-55.sh | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/test/units/testsuite-55.sh b/test/units/testsuite-55.sh index b265c8cce7..db13964311 100755 --- a/test/units/testsuite-55.sh +++ b/test/units/testsuite-55.sh @@ -60,36 +60,29 @@ if ! systemctl status testsuite-55-testchill.service; then exit 24; fi # Make sure we also work correctly on user units. -runas() { - declare userid=$1 - shift - # shellcheck disable=SC2016 - su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@" -} - -runas testuser systemctl start --user testsuite-55-testchill.service -runas testuser systemctl start --user testsuite-55-testbloat.service +systemctl start --machine "testuser@.host" --user testsuite-55-testchill.service +systemctl start --machine "testuser@.host" --user testsuite-55-testbloat.service # Verify systemd-oomd is monitoring the expected units oomctl | grep -E "/user.slice.*/testsuite-55-workload.slice" oomctl | grep "20.00%" oomctl | grep "Default Memory Pressure Duration: 2s" -runas testuser systemctl --user status testsuite-55-testchill.service +systemctl --machine "testuser@.host" --user status testsuite-55-testchill.service # systemd-oomd watches for elevated pressure for 2 seconds before acting. # It can take time to build up pressure so either wait 2 minutes or for the service to fail. timeout="$(date -ud "2 minutes" +%s)" while [[ $(date -u +%s) -le $timeout ]]; do - if ! runas testuser systemctl --user status testsuite-55-testbloat.service; then + if ! systemctl --machine "testuser@.host" --user status testsuite-55-testbloat.service; then break fi sleep 2 done # testbloat should be killed and testchill should be fine -if runas testuser systemctl --user status testsuite-55-testbloat.service; then exit 42; fi -if ! runas testuser systemctl --user status testsuite-55-testchill.service; then exit 24; fi +if systemctl --machine "testuser@.host" --user status testsuite-55-testbloat.service; then exit 42; fi +if ! systemctl --machine "testuser@.host" --user status testsuite-55-testchill.service; then exit 24; fi # only run this portion of the test if we can set xattrs if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then