summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-05-30 03:05:22 +0000
committerngie <ngie@FreeBSD.org>2017-05-30 03:05:22 +0000
commit6932de11ab5641f9c4a00a5be42b2a3b55c6d81c (patch)
tree9a06c8c218c4bf4b9c1ed03d39030c5ca415c2d9 /tests
parentbbaf5408419253e74bbcb75aad70ef507cb8bec7 (diff)
downloadFreeBSD-src-6932de11ab5641f9c4a00a5be42b2a3b55c6d81c.zip
FreeBSD-src-6932de11ab5641f9c4a00a5be42b2a3b55c6d81c.tar.gz
MFC r318094,r318098,r318099:
r318094: style(9): clean up trailing whitespace r318098: Refactor ATF_REQUIRE_UNSAFE_AIO and PLAIN_REQUIRE_UNSAFE_AIO This is being done to reduce duplication between the two macros. r318099: Print out when unsafe AIO is enabled to debugging purposes
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/aio/local.h73
1 files changed, 44 insertions, 29 deletions
diff --git a/tests/sys/aio/local.h b/tests/sys/aio/local.h
index 308b700..6620fe3 100644
--- a/tests/sys/aio/local.h
+++ b/tests/sys/aio/local.h
@@ -39,36 +39,51 @@
#include <atf-c.h>
-#define ATF_REQUIRE_UNSAFE_AIO() do { \
- size_t _len; \
- int _unsafe; \
- \
- _len = sizeof(_unsafe); \
- if (sysctlbyname("vfs.aio.enable_unsafe", &_unsafe, &_len, NULL,\
- 0) < 0) { \
- if (errno != ENOENT) \
- atf_libc_error(errno, \
- "Failed to read vfs.aio.enable_unsafe"); \
- } else if (_unsafe == 0) \
- atf_tc_skip("Unsafe AIO is disabled"); \
+static const char *sysctl_oid_name = "vfs.aio.enable_unsafe";
+
+static int
+is_unsafe_aio_enabled(void)
+{
+ size_t len;
+ int unsafe;
+
+ len = sizeof(unsafe);
+ if (sysctlbyname(sysctl_oid_name, &unsafe, &len, NULL, 0) < 0) {
+ if (errno == ENOENT)
+ return (-1);
+ return (0);
+ }
+ return (unsafe == 0 ? 0 : 1);
+}
+
+#define ATF_REQUIRE_UNSAFE_AIO() do { \
+ switch (is_unsafe_aio_enabled()) { \
+ case -1: \
+ atf_libc_error(errno, "Failed to read %s", sysctl_oid_name); \
+ break; \
+ case 0: \
+ atf_tc_skip("Unsafe AIO is disabled"); \
+ break; \
+ default: \
+ printf("Unsafe AIO is enabled\n"); \
+ break; \
+ } \
} while (0)
-
-#define PLAIN_REQUIRE_UNSAFE_AIO(_exit_code) do { \
- size_t _len; \
- int _unsafe; \
- \
- _len = sizeof(_unsafe); \
- if (sysctlbyname("vfs.aio.enable_unsafe", &_unsafe, &_len, NULL,\
- 0) < 0) { \
- if (errno != ENOENT) { \
- printf("Failed to read vfs.aio.enable_unsafe: %s\n",\
- strerror(errno)); \
- _exit(1); \
- } \
- } else if (_unsafe == 0) { \
- printf("Unsafe AIO is disabled"); \
- _exit(_exit_code); \
- } \
+
+#define PLAIN_REQUIRE_UNSAFE_AIO(_exit_code) do { \
+ switch (is_unsafe_aio_enabled()) { \
+ case -1: \
+ printf("Failed to read %s", sysctl_oid_name); \
+ _exit(_exit_code); \
+ break; \
+ case 0: \
+ printf("Unsafe AIO is disabled\n"); \
+ _exit(_exit_code); \
+ break; \
+ default: \
+ printf("Unsafe AIO is enabled\n"); \
+ break; \
+ } \
} while (0)
#endif /* !_AIO_TEST_LOCAL_H_ */
OpenPOWER on IntegriCloud