1 /* 2 * Automated Testing Framework (atf) 3 * 4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #if !defined(ATF_C_MACROS_H) 31 #define ATF_C_MACROS_H 32 33 #include <atf-c/defs.h> 34 #include <atf-c/error.h> 35 #include <atf-c/tc.h> 36 #include <atf-c/tp.h> 37 #include <atf-c/utils.h> 38 39 #define ATF_TC_NAME(tc) \ 40 (atfu_ ## tc ## _tc) 41 42 #define ATF_TC_PACK_NAME(tc) \ 43 (atfu_ ## tc ## _tc_pack) 44 45 #define ATF_TC_WITHOUT_HEAD(tc) \ 46 static void atfu_ ## tc ## _body(const atf_tc_t *); \ 47 static atf_tc_t atfu_ ## tc ## _tc; \ 48 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \ 49 .m_ident = #tc, \ 50 .m_head = NULL, \ 51 .m_body = atfu_ ## tc ## _body, \ 52 .m_cleanup = NULL, \ 53 } 54 55 #define ATF_TC(tc) \ 56 static void atfu_ ## tc ## _head(atf_tc_t *); \ 57 static void atfu_ ## tc ## _body(const atf_tc_t *); \ 58 static atf_tc_t atfu_ ## tc ## _tc; \ 59 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \ 60 .m_ident = #tc, \ 61 .m_head = atfu_ ## tc ## _head, \ 62 .m_body = atfu_ ## tc ## _body, \ 63 .m_cleanup = NULL, \ 64 } 65 66 #define ATF_TC_WITH_CLEANUP(tc) \ 67 static void atfu_ ## tc ## _head(atf_tc_t *); \ 68 static void atfu_ ## tc ## _body(const atf_tc_t *); \ 69 static void atfu_ ## tc ## _cleanup(const atf_tc_t *); \ 70 static atf_tc_t atfu_ ## tc ## _tc; \ 71 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \ 72 .m_ident = #tc, \ 73 .m_head = atfu_ ## tc ## _head, \ 74 .m_body = atfu_ ## tc ## _body, \ 75 .m_cleanup = atfu_ ## tc ## _cleanup, \ 76 } 77 78 #define ATF_TC_HEAD(tc, tcptr) \ 79 static \ 80 void \ 81 atfu_ ## tc ## _head(atf_tc_t *tcptr) 82 83 #define ATF_TC_HEAD_NAME(tc) \ 84 (atfu_ ## tc ## _head) 85 86 #define ATF_TC_BODY(tc, tcptr) \ 87 static \ 88 void \ 89 atfu_ ## tc ## _body(const atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED) 90 91 #define ATF_TC_BODY_NAME(tc) \ 92 (atfu_ ## tc ## _body) 93 94 #define ATF_TC_CLEANUP(tc, tcptr) \ 95 static \ 96 void \ 97 atfu_ ## tc ## _cleanup(const atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED) 98 99 #define ATF_TC_CLEANUP_NAME(tc) \ 100 (atfu_ ## tc ## _cleanup) 101 102 #define ATF_TP_ADD_TCS(tps) \ 103 static atf_error_t atfu_tp_add_tcs(atf_tp_t *); \ 104 int atf_tp_main(int, char **, atf_error_t (*)(atf_tp_t *)); \ 105 \ 106 int \ 107 main(int argc, char **argv) \ 108 { \ 109 return atf_tp_main(argc, argv, atfu_tp_add_tcs); \ 110 } \ 111 static \ 112 atf_error_t \ 113 atfu_tp_add_tcs(atf_tp_t *tps) 114 115 #define ATF_TP_ADD_TC(tp, tc) \ 116 do { \ 117 atf_error_t atfu_err; \ 118 char **atfu_config = atf_tp_get_config(tp); \ 119 if (atfu_config == NULL) \ 120 return atf_no_memory_error(); \ 121 atfu_err = atf_tc_init_pack(&atfu_ ## tc ## _tc, \ 122 &atfu_ ## tc ## _tc_pack, \ 123 (const char *const *)atfu_config); \ 124 atf_utils_free_charpp(atfu_config); \ 125 if (atf_is_error(atfu_err)) \ 126 return atfu_err; \ 127 atfu_err = atf_tp_add_tc(tp, &atfu_ ## tc ## _tc); \ 128 if (atf_is_error(atfu_err)) \ 129 return atfu_err; \ 130 } while (0) 131 132 #define ATF_REQUIRE_MSG(x, fmt, ...) \ 133 do { \ 134 if (!(x)) \ 135 atf_tc_fail_requirement(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \ 136 } while(0) 137 138 #define ATF_CHECK_MSG(x, fmt, ...) \ 139 do { \ 140 if (!(x)) \ 141 atf_tc_fail_check(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \ 142 } while(0) 143 144 #define ATF_REQUIRE(x) \ 145 do { \ 146 if (!(x)) \ 147 atf_tc_fail_requirement(__FILE__, __LINE__, "%s", #x " not met"); \ 148 } while(0) 149 150 #define ATF_CHECK(x) \ 151 do { \ 152 if (!(x)) \ 153 atf_tc_fail_check(__FILE__, __LINE__, "%s", #x " not met"); \ 154 } while(0) 155 156 #define ATF_REQUIRE_EQ(x, y) \ 157 ATF_REQUIRE_MSG((x) == (y), "%s != %s", #x, #y) 158 159 #define ATF_CHECK_EQ(x, y) \ 160 ATF_CHECK_MSG((x) == (y), "%s != %s", #x, #y) 161 162 #define ATF_REQUIRE_EQ_MSG(x, y, fmt, ...) \ 163 ATF_REQUIRE_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__) 164 165 #define ATF_CHECK_EQ_MSG(x, y, fmt, ...) \ 166 ATF_CHECK_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__) 167 168 #define ATF_REQUIRE_STREQ(x, y) \ 169 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) 170 171 #define ATF_CHECK_STREQ(x, y) \ 172 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) 173 174 #define ATF_REQUIRE_STREQ_MSG(x, y, fmt, ...) \ 175 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \ 176 #x, #y, x, y, ##__VA_ARGS__) 177 178 #define ATF_CHECK_STREQ_MSG(x, y, fmt, ...) \ 179 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \ 180 #x, #y, x, y, ##__VA_ARGS__) 181 182 #define ATF_CHECK_ERRNO(exp_errno, bool_expr) \ 183 atf_tc_check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr) 184 185 #define ATF_REQUIRE_ERRNO(exp_errno, bool_expr) \ 186 atf_tc_require_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr) 187 188 #endif /* !defined(ATF_C_MACROS_H) */ 189