git: 81011ca4c0a8 - stable/15 - exterror tests: harden the checks

Alexander Leidinger <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src,gmane.os.freebsd.devel.stable.scm
Message-ID <[email protected]>
The branch stable/15 has been updated by netchild:

URL: https://cgit.FreeBSD.org/src/commit/?id=81011ca4c0a8ba7e7911b128c187de38efa3c59d

commit 81011ca4c0a8ba7e7911b128c187de38efa3c59d
Author:     Alexander Leidinger <[email protected]>
AuthorDate: 2026-07-21 20:39:57 +0000
Commit:     Alexander Leidinger <[email protected]>
CommitDate: 2026-07-28 10:04:52 +0000

    exterror tests: harden the checks
    
    Skip the message-content check on kernels that do not advertise the
    exterr_strings feature, and pin the output format by clearing
    EXTERROR_VERBOSE.
    
    Reviewed by:            kib
    MFC after:              1 week
    Assisted-by:            Claude Code (Fable 5)
    Differential Revision:  https://reviews.freebsd.org/D58322
    
    (cherry picked from commit 1092aba1260ce5efb0d718352aa22158605c7506)
---
 tests/sys/kern/exterr_test.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/tests/sys/kern/exterr_test.c b/tests/sys/kern/exterr_test.c
index b4746a485f58..316b5b66b0e0 100644
--- a/tests/sys/kern/exterr_test.c
+++ b/tests/sys/kern/exterr_test.c
@@ -30,6 +30,20 @@
 #include <errno.h>
 #include <exterr.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Pin the message format by clearing EXTERROR_VERBOSE, which would
+ * otherwise change the output shape.
+ */
+static void
+pin_exterror_format(void)
+{
+
+	unsetenv("EXTERROR_VERBOSE");
+}
 
 ATF_TC(gettext_extended);
 ATF_TC_HEAD(gettext_extended, tc)
@@ -41,6 +55,8 @@ ATF_TC_BODY(gettext_extended, tc)
 	char exterr[UEXTERROR_MAXLEN];
 	int r;
 
+	pin_exterror_format();
+
 	/*
 	 * Use an invalid call to mmap() because it supports extended error
 	 * messages, requires no special resources, and does not need root.
@@ -50,8 +66,10 @@ ATF_TC_BODY(gettext_extended, tc)
 	r = uexterr_gettext(exterr, sizeof(exterr));
 	ATF_CHECK_EQ(0, r);
 	printf("Extended error: %s\n", exterr);
+	if (feature_present("exterr_strings") == 0)
+		atf_tc_skip("kernel built without EXTERR_STRINGS");
 	/* Note: error string may need to be updated due to kernel changes */
-	ATF_CHECK(strstr(exterr, " is not subset of ") != 0);
+	ATF_CHECK(strstr(exterr, " is not subset of ") != NULL);
 }
 
 ATF_TC(gettext_noextended);
@@ -65,6 +83,8 @@ ATF_TC_BODY(gettext_noextended, tc)
 	char exterr[UEXTERROR_MAXLEN];
 	int r;
 
+	pin_exterror_format();
+
 	ATF_CHECK_ERRNO(EINVAL, exterrctl(EXTERRCTL_UD, 0, NULL));
 	r = uexterr_gettext(exterr, sizeof(exterr));
 	ATF_CHECK_EQ(0, r);
@@ -82,6 +102,8 @@ ATF_TC_BODY(gettext_noextended_after_extended, tc)
 	char exterr[UEXTERROR_MAXLEN];
 	int r;
 
+	pin_exterror_format();
+
 	/*
 	 * First do something that will create an extended error message, but
 	 * ignore it.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.