Path: blob/main/tests/freebsd_test_suite/macros.h
105957 views
/*-1* Copyright (c) 2015 EMC / Isilon Storage Division2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#ifndef _FREEBSD_TEST_MACROS_H_27#define _FREEBSD_TEST_MACROS_H_2829#include <sys/param.h>30#include <sys/module.h>31#include <sys/sysctl.h>32#include <string.h>33#include <errno.h>34#include <stdio.h>35#include <unistd.h>3637#include <atf-c.h>3839#define ATF_REQUIRE_FEATURE(_feature_name) do { \40if (feature_present(_feature_name) == 0) { \41atf_tc_skip("kernel feature (%s) not present", \42_feature_name); \43} \44} while(0)4546#define ATF_REQUIRE_KERNEL_MODULE(_mod_name) do { \47if (modfind(_mod_name) == -1) { \48atf_tc_skip("module %s could not be resolved: %s", \49_mod_name, strerror(errno)); \50} \51} while(0)5253#define ATF_REQUIRE_SYSCTL_BOOL(_mib_name, _required_value) do { \54bool value; \55size_t size = sizeof(value); \56if (sysctlbyname(_mib_name, &value, &size, NULL, 0) == -1) { \57atf_tc_skip("sysctl for %s failed: %s", _mib_name, \58strerror(errno)); \59} \60if (value != (_required_value)) \61atf_tc_skip("requires %s=%d, =%d", (_mib_name), \62(_required_value), value); \63} while (0)6465#define ATF_REQUIRE_SYSCTL_INT(_mib_name, _required_value) do { \66int value; \67size_t size = sizeof(value); \68if (sysctlbyname(_mib_name, &value, &size, NULL, 0) == -1) { \69atf_tc_skip("sysctl for %s failed: %s", _mib_name, \70strerror(errno)); \71} \72if (value != (_required_value)) \73atf_tc_skip("requires %s=%d, =%d", (_mib_name), \74(_required_value), value); \75} while(0)7677#define PLAIN_REQUIRE_FEATURE(_feature_name, _exit_code) do { \78if (feature_present(_feature_name) == 0) { \79printf("kernel feature (%s) not present\n", \80_feature_name); \81_exit(_exit_code); \82} \83} while(0)8485#define PLAIN_REQUIRE_KERNEL_MODULE(_mod_name, _exit_code) do { \86if (modfind(_mod_name) == -1) { \87printf("module %s could not be resolved: %s\n", \88_mod_name, strerror(errno)); \89_exit(_exit_code); \90} \91} while(0)9293#endif949596