]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test coverage for EnterNamespace= 34333/head
authorMichal Sekletar <msekleta@redhat.com>
Fri, 6 Sep 2024 17:23:09 +0000 (19:23 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 30 Oct 2024 12:38:27 +0000 (12:38 +0000)
test/TEST-74-AUX-UTILS/test.sh
test/units/TEST-74-AUX-UTILS.coredump.sh

index d9ae70c68ccbc5d1f2ba83232861b2e73f21a6d2..b10965040a0fcc91930fe55ed4f2d34f73df6b71 100755 (executable)
@@ -36,6 +36,7 @@ test_append_files() {
     instmods vmw_vsock_virtio_transport
     instmods vsock_loopback
     instmods vmw_vsock_vmci_transport
+    inst_binary gcc
     generate_module_dependencies
 }
 
index b9c8fde2a33cb4c437967f3495cb34ddd798e793..2c084f54d2441b23b7363eea4f558aaea98007d5 100755 (executable)
@@ -8,13 +8,15 @@ set -o pipefail
 
 # Make sure the binary name fits into 15 characters
 CORE_TEST_BIN="/tmp/test-dump"
+CORE_STACKTRACE_TEST_BIN="/tmp/test-stacktrace-dump"
+MAKE_STACKTRACE_DUMP="/tmp/make-stacktrace-dump"
 CORE_TEST_UNPRIV_BIN="/tmp/test-usr-dump"
 MAKE_DUMP_SCRIPT="/tmp/make-dump"
 # Unset $PAGER so we don't have to use --no-pager everywhere
 export PAGER=
 
 at_exit() {
-    rm -fv -- "$CORE_TEST_BIN" "$CORE_TEST_UNPRIV_BIN" "$MAKE_DUMP_SCRIPT"
+    rm -fv -- "$CORE_TEST_BIN" "$CORE_TEST_UNPRIV_BIN" "$MAKE_DUMP_SCRIPT" "$MAKE_STACKTRACE_DUMP"
 }
 
 trap at_exit EXIT
@@ -225,3 +227,32 @@ systemd-run -t --property CoredumpFilter=default ls /tmp
 (! coredumpctl dump --output=/dev/null --output=/dev/null "$CORE_TEST_BIN")
 (! coredumpctl debug --debugger=/bin/false)
 (! coredumpctl debug --debugger=/bin/true --debugger-arguments='"')
+
+# Test for EnterNamespace= feature
+if pkgconf --atleast-version 0.192 libdw ; then
+    # dwfl_set_sysroot() is supported only in libdw-0.192 or newer.
+    cat >"$MAKE_STACKTRACE_DUMP" <<END
+#!/bin/bash
+mount -t tmpfs tmpfs /tmp
+gcc -xc -O0 -g -o $CORE_STACKTRACE_TEST_BIN - <<EOF
+void baz(void) { int *x = 0; *x = 42; }
+void bar(void) { baz(); }
+void foo(void) { bar(); }
+int main(void) { foo(); return 0;}
+EOF
+$CORE_STACKTRACE_TEST_BIN
+END
+    chmod +x "$MAKE_STACKTRACE_DUMP"
+
+    mkdir -p /run/systemd/coredump.conf.d/
+    printf '[Coredump]\nEnterNamespace=no' >/run/systemd/coredump.conf.d/99-enter-namespace.conf
+
+    unshare --pid --fork --mount-proc --mount --uts --ipc --net /bin/bash -c "$MAKE_STACKTRACE_DUMP" || :
+    timeout 30 bash -c "until coredumpctl -1 info $CORE_STACKTRACE_TEST_BIN | grep -zvqE 'baz.*bar.*foo'; do sleep .2; done"
+
+    printf '[Coredump]\nEnterNamespace=yes' >/run/systemd/coredump.conf.d/99-enter-namespace.conf
+    unshare --pid --fork --mount-proc --mount --uts --ipc --net /bin/bash -c "$MAKE_STACKTRACE_DUMP" || :
+    timeout 30 bash -c "until coredumpctl -1 info $CORE_STACKTRACE_TEST_BIN | grep -zqE 'baz.*bar.*foo'; do sleep .2; done"
+else
+    echo "libdw doesn't not support setting sysroot, skipping EnterNamespace= test"
+fi