diff options
author | Enji Cooper <ngie@FreeBSD.org> | 2017-05-09 19:16:18 +0000 |
---|---|---|
committer | Enji Cooper <ngie@FreeBSD.org> | 2017-05-09 19:16:18 +0000 |
commit | 5fec77f1d6a91b85f026ead61f60f9875ef65013 (patch) | |
tree | 5577e88d47b19b3e44acc7cef83e819f3c5cdcd1 /tests | |
parent | 915780d7642db2677a54d56cc3cfbbfe3f849b6a (diff) | |
download | src-test2-5fec77f1d6a91b85f026ead61f60f9875ef65013.tar.gz src-test2-5fec77f1d6a91b85f026ead61f60f9875ef65013.zip |
Notes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sys/aio/local.h | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/tests/sys/aio/local.h b/tests/sys/aio/local.h index 5507df990ecb..b30db92a7fb9 100644 --- a/tests/sys/aio/local.h +++ b/tests/sys/aio/local.h @@ -39,36 +39,49 @@ #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: \ + 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: \ + break; \ + } \ } while (0) #endif /* !_AIO_TEST_LOCAL_H_ */ |