From 9647bf242362752f513b2aeac659dd4ee41174f7 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Fri, 13 Dec 2024 23:17:20 -0600 Subject: [PATCH] tests: kern: add some tests for recently added logsigexit We don't bother tweaking the sysctl in these tests, we'll just try with it forced both on and off via proccontrol(1). This could be problematic in the face of pid wrapping if we got really unfortunate, but the potential solutions need careful consideration- you probably don't want to assume a certain velocity of messages into syslog, so just checking the last N lines is probably similarly flakey. --- tests/sys/kern/Makefile | 1 + tests/sys/kern/logsigexit_test.sh | 36 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/sys/kern/logsigexit_test.sh diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 8785caf4e293c9..be05f5d01faa63 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -58,6 +58,7 @@ ATF_TESTS_C+= sigsys TEST_METADATA.sigsys+= is_exclusive="true" ATF_TESTS_SH+= coredump_phnum_test +ATF_TESTS_SH+= logsigexit_test ATF_TESTS_SH+= sonewconn_overflow TEST_METADATA.sonewconn_overflow+= required_programs="python" TEST_METADATA.sonewconn_overflow+= required_user="root" diff --git a/tests/sys/kern/logsigexit_test.sh b/tests/sys/kern/logsigexit_test.sh new file mode 100644 index 00000000000000..c40c033bbefdfc --- /dev/null +++ b/tests/sys/kern/logsigexit_test.sh @@ -0,0 +1,36 @@ +# +# Copyright (c) 2024 Kyle Evans +# +# SPDX-License-Identifier: BSD-2-Clause +# + +atf_test_case basic +basic_body() +{ + + # SIGABRT carefully chosen to avoid issues when run under Kyua. No + # matter the value of the global kern.logsigexit, these should force + # the messages as appropriate and we'll all be happy. + proccontrol -m logsigexit -s enable \ + sh -c 'echo $$ > enabled.out; kill -ABRT $$' + proccontrol -m logsigexit -s disable \ + sh -c 'echo $$ > disabled.out; kill -ABRT $$' + + atf_check test -s enabled.out + atf_check test -s disabled.out + + read enpid < enabled.out + read dispid < disabled.out + + 1>&2 echo "$enpid" + 1>&2 echo "$dispid" + + atf_check grep -Eq "$enpid.+exited on signal" /var/log/messages + atf_check -s not-exit:0 \ + grep -Eq "$dispid.+exited on signal" /var/log/messages +} + +atf_init_test_cases() +{ + atf_add_test_case basic +}