1b740c88bSEnji Cooper /*- 2b740c88bSEnji Cooper * Copyright (c) 2015 EMC / Isilon Storage Division 3b740c88bSEnji Cooper * All rights reserved. 4b740c88bSEnji Cooper * 5b740c88bSEnji Cooper * Redistribution and use in source and binary forms, with or without 6b740c88bSEnji Cooper * modification, are permitted provided that the following conditions 7b740c88bSEnji Cooper * are met: 8b740c88bSEnji Cooper * 1. Redistributions of source code must retain the above copyright 9b740c88bSEnji Cooper * notice, this list of conditions and the following disclaimer. 10b740c88bSEnji Cooper * 2. Redistributions in binary form must reproduce the above copyright 11b740c88bSEnji Cooper * notice, this list of conditions and the following disclaimer in the 12b740c88bSEnji Cooper * documentation and/or other materials provided with the distribution. 13b740c88bSEnji Cooper * 14b740c88bSEnji Cooper * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15b740c88bSEnji Cooper * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16b740c88bSEnji Cooper * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17b740c88bSEnji Cooper * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18b740c88bSEnji Cooper * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19b740c88bSEnji Cooper * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20b740c88bSEnji Cooper * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21b740c88bSEnji Cooper * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22b740c88bSEnji Cooper * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23b740c88bSEnji Cooper * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24b740c88bSEnji Cooper * SUCH DAMAGE. 25b740c88bSEnji Cooper */ 26b740c88bSEnji Cooper 27b740c88bSEnji Cooper #ifndef _FREEBSD_TEST_MACROS_H_ 28b740c88bSEnji Cooper #define _FREEBSD_TEST_MACROS_H_ 29b740c88bSEnji Cooper 30b740c88bSEnji Cooper #include <sys/param.h> 31b740c88bSEnji Cooper #include <sys/module.h> 323c5ba95aSAlan Somers #include <sys/sysctl.h> 33b740c88bSEnji Cooper #include <string.h> 34b740c88bSEnji Cooper #include <errno.h> 35c82b9f92SEnji Cooper #include <stdio.h> 36c82b9f92SEnji Cooper #include <unistd.h> 37b740c88bSEnji Cooper 38b740c88bSEnji Cooper #include <atf-c.h> 39b740c88bSEnji Cooper 4011b249f9SEnji Cooper #define ATF_REQUIRE_FEATURE(_feature_name) do { \ 4111b249f9SEnji Cooper if (feature_present(_feature_name) == 0) { \ 4211b249f9SEnji Cooper atf_tc_skip("kernel feature (%s) not present", \ 4311b249f9SEnji Cooper _feature_name); \ 4411b249f9SEnji Cooper } \ 4511b249f9SEnji Cooper } while(0) 4611b249f9SEnji Cooper 47b740c88bSEnji Cooper #define ATF_REQUIRE_KERNEL_MODULE(_mod_name) do { \ 48c82b9f92SEnji Cooper if (modfind(_mod_name) == -1) { \ 497ad92e6aSEnji Cooper atf_tc_skip("module %s could not be resolved: %s", \ 50b740c88bSEnji Cooper _mod_name, strerror(errno)); \ 51c82b9f92SEnji Cooper } \ 52b740c88bSEnji Cooper } while(0) 53b740c88bSEnji Cooper 54*8a271827SMark Johnston #define ATF_REQUIRE_SYSCTL_BOOL(_mib_name, _required_value) do { \ 55*8a271827SMark Johnston bool value; \ 56*8a271827SMark Johnston size_t size = sizeof(value); \ 57*8a271827SMark Johnston if (sysctlbyname(_mib_name, &value, &size, NULL, 0) == -1) { \ 58*8a271827SMark Johnston atf_tc_skip("sysctl for %s failed: %s", _mib_name, \ 59*8a271827SMark Johnston strerror(errno)); \ 60*8a271827SMark Johnston } \ 61*8a271827SMark Johnston if (value != (_required_value)) \ 62*8a271827SMark Johnston atf_tc_skip("requires %s=%d, =%d", (_mib_name), \ 63*8a271827SMark Johnston (_required_value), value); \ 64*8a271827SMark Johnston } while (0) 65*8a271827SMark Johnston 663c5ba95aSAlan Somers #define ATF_REQUIRE_SYSCTL_INT(_mib_name, _required_value) do { \ 673c5ba95aSAlan Somers int value; \ 683c5ba95aSAlan Somers size_t size = sizeof(value); \ 693c5ba95aSAlan Somers if (sysctlbyname(_mib_name, &value, &size, NULL, 0) == -1) { \ 703c5ba95aSAlan Somers atf_tc_skip("sysctl for %s failed: %s", _mib_name, \ 713c5ba95aSAlan Somers strerror(errno)); \ 723c5ba95aSAlan Somers } \ 73*8a271827SMark Johnston if (value != (_required_value)) \ 74*8a271827SMark Johnston atf_tc_skip("requires %s=%d, =%d", (_mib_name), \ 75*8a271827SMark Johnston (_required_value), value); \ 763c5ba95aSAlan Somers } while(0) 773c5ba95aSAlan Somers 7811b249f9SEnji Cooper #define PLAIN_REQUIRE_FEATURE(_feature_name, _exit_code) do { \ 7911b249f9SEnji Cooper if (feature_present(_feature_name) == 0) { \ 8011b249f9SEnji Cooper printf("kernel feature (%s) not present\n", \ 8111b249f9SEnji Cooper _feature_name); \ 8211b249f9SEnji Cooper _exit(_exit_code); \ 8311b249f9SEnji Cooper } \ 8411b249f9SEnji Cooper } while(0) 8511b249f9SEnji Cooper 86b740c88bSEnji Cooper #define PLAIN_REQUIRE_KERNEL_MODULE(_mod_name, _exit_code) do { \ 87b740c88bSEnji Cooper if (modfind(_mod_name) == -1) { \ 88c82b9f92SEnji Cooper printf("module %s could not be resolved: %s\n", \ 89c82b9f92SEnji Cooper _mod_name, strerror(errno)); \ 90c82b9f92SEnji Cooper _exit(_exit_code); \ 91b740c88bSEnji Cooper } \ 92b740c88bSEnji Cooper } while(0) 93b740c88bSEnji Cooper 94b740c88bSEnji Cooper #endif 95