git: 9647bf242362 - main - tests: kern: add some tests for recently added logsigexit

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 14 Dec 2024 05:18:54 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=9647bf242362752f513b2aeac659dd4ee41174f7

commit 9647bf242362752f513b2aeac659dd4ee41174f7
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-12-14 05:17:20 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-12-14 05:18:31 +0000

    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(+)

diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index 8785caf4e293..be05f5d01faa 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 000000000000..c40c033bbefd
--- /dev/null
+++ b/tests/sys/kern/logsigexit_test.sh
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2024 Kyle Evans <kevans@FreeBSD.org>
+#
+# 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
+}