git: a9732ce7b904 - stable/13 - tests: Add ATF_REQUIRE_SYSCTL_BOOL

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 07 May 2023 18:00:00 UTC
The branch stable/13 has been updated by markj:

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

commit a9732ce7b904f5f52fce4bba4a52a2898ca97782
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-04-25 13:54:23 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-05-07 17:54:09 +0000

    tests: Add ATF_REQUIRE_SYSCTL_BOOL
    
    Modify a capability mode test to use it for kern.trap_enotcap, to avoid
    false positives.
    
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 8a271827e7b5d5310e06df1f9f49ba0ef9efd263)
---
 tests/freebsd_test_suite/macros.h | 17 +++++++++++++++--
 tests/sys/vfs/lookup_cap_dotdot.c |  2 +-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/tests/freebsd_test_suite/macros.h b/tests/freebsd_test_suite/macros.h
index c5a3a3838ff7..dfce2fb810e1 100644
--- a/tests/freebsd_test_suite/macros.h
+++ b/tests/freebsd_test_suite/macros.h
@@ -53,6 +53,18 @@
 	}								\
 } while(0)
 
+#define	ATF_REQUIRE_SYSCTL_BOOL(_mib_name, _required_value) do {	\
+	bool value;							\
+	size_t size = sizeof(value);					\
+	if (sysctlbyname(_mib_name, &value, &size, NULL, 0) == -1) {	\
+		atf_tc_skip("sysctl for %s failed: %s", _mib_name,	\
+		    strerror(errno));					\
+	}								\
+	if (value != (_required_value))					\
+		atf_tc_skip("requires %s=%d, =%d", (_mib_name),		\
+		    (_required_value), value);				\
+} while (0)
+
 #define ATF_REQUIRE_SYSCTL_INT(_mib_name, _required_value) do {		\
 	int value;							\
 	size_t size = sizeof(value);					\
@@ -60,8 +72,9 @@
 		atf_tc_skip("sysctl for %s failed: %s", _mib_name,	\
 		    strerror(errno));					\
 	}								\
-	if (value != _required_value)					\
-		atf_tc_skip("requires %s=%d", _mib_name, _required_value); \
+	if (value != (_required_value))					\
+		atf_tc_skip("requires %s=%d, =%d", (_mib_name),		\
+		    (_required_value), value);				\
 } while(0)
 
 #define	PLAIN_REQUIRE_FEATURE(_feature_name, _exit_code) do {		\
diff --git a/tests/sys/vfs/lookup_cap_dotdot.c b/tests/sys/vfs/lookup_cap_dotdot.c
index dee1e0b11780..e023a50f8152 100644
--- a/tests/sys/vfs/lookup_cap_dotdot.c
+++ b/tests/sys/vfs/lookup_cap_dotdot.c
@@ -80,7 +80,7 @@ check_capsicum(void)
 {
 	ATF_REQUIRE_FEATURE("security_capabilities");
 	ATF_REQUIRE_FEATURE("security_capability_mode");
-	ATF_REQUIRE_SYSCTL_INT("kern.trap_enotcap", 0);
+	ATF_REQUIRE_SYSCTL_BOOL("kern.trap_enotcap", false);
 }
 
 /*