git: 76757177c30b - releng/15.2 - modstat: allow compat support to fail in tests

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 19:51:58 UTC
The branch releng/15.2 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=76757177c30beb42a055650ddda076773c63a167

commit 76757177c30beb42a055650ddda076773c63a167
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-13 10:06:52 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-17 19:51:31 +0000

    modstat: allow compat support to fail in tests
    
    v1 and v2 versions of stuct module_stat are now gated by COMPAT_ ifdefs
    so allow the otherwise valid query to fail with EINVAL.
    
    Approved by:    re (cperciva)
    Effort:         CHERI upstreaming
    Reviewed by:    markj
    Reported by:    llm-postcr
    Sponsored by:   Innovate UK
    Fixes:          1ebf46ecb627 ("modstat: don't copyout while holding a lock")
    Differential Revision:  https://reviews.freebsd.org/D61460
    
    (cherry picked from commit ef726c645300870b6bdf3573079b1f89f3b45c74)
    (cherry picked from commit 4a9770b9256c7119da287b15a6e7900298e6d514)
---
 tests/sys/kern/module_test.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tests/sys/kern/module_test.c b/tests/sys/kern/module_test.c
index 37cbc3b3271a..b4f66ec9c953 100644
--- a/tests/sys/kern/module_test.c
+++ b/tests/sys/kern/module_test.c
@@ -30,6 +30,7 @@
 #include <sys/param.h>
 #include <sys/module.h>
 #include <errno.h>
+#include <unistd.h>
 #include <atf-c.h>
 
 ATF_TC_WITHOUT_HEAD(modfind);
@@ -144,11 +145,14 @@ ATF_TC_BODY(modstat_v1, tc)
 	ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == -1);
 	ATF_REQUIRE(errno == EINVAL);
 
+	/* Kernels only support module_stat_v1 when compiled with COMPAT_43 */
 	ms.version = sizeof(ms);
-	ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == 0);
-	ATF_REQUIRE(ms.id == modid);
-	if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name))
-		ATF_REQUIRE(modfind(ms.name) == modid);
+	if (modstat(modid, (struct module_stat *)&ms) == 0) {
+		ATF_REQUIRE(ms.id == modid);
+		if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name))
+			ATF_REQUIRE(modfind(ms.name) == modid);
+	} else
+		ATF_REQUIRE(errno == EINVAL);
 }
 
 ATF_TC_WITHOUT_HEAD(modstat_v2);
@@ -178,10 +182,14 @@ ATF_TC_BODY(modstat_v2, tc)
 	ATF_REQUIRE(errno == EINVAL);
 
 	ms.version = sizeof(ms);
-	ATF_REQUIRE(modstat(modid, (struct module_stat *)&ms) == 0);
-	ATF_REQUIRE(ms.id == modid);
-	if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name))
-		ATF_REQUIRE(modfind(ms.name) == modid);
+	if (modstat(modid, (struct module_stat *)&ms) == 0) {
+		ATF_REQUIRE(ms.id == modid);
+		if (strnlen(ms.name, sizeof(ms.name)) < sizeof(ms.name))
+			ATF_REQUIRE(modfind(ms.name) == modid);
+	} else {
+		ATF_REQUIRE(!feature_present("compat_freebsd13"));
+		ATF_REQUIRE(errno == EINVAL);
+	}
 }
 
 ATF_TP_ADD_TCS(tp)