1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26 #if !defined(ATF_C_MACROS_H)
27 #define ATF_C_MACROS_H
31 #include <atf-c/defs.h>
32 #include <atf-c/error.h>
35 #include <atf-c/utils.h>
37 #define ATF_TC_NAME(tc) \
40 #define ATF_TC_PACK_NAME(tc) \
41 (atfu_ ## tc ## _tc_pack)
43 #define ATF_TC_WITHOUT_HEAD(tc) \
44 static void atfu_ ## tc ## _body(const atf_tc_t *); \
45 static atf_tc_t atfu_ ## tc ## _tc; \
46 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \
49 .m_body = atfu_ ## tc ## _body, \
54 static void atfu_ ## tc ## _head(atf_tc_t *); \
55 static void atfu_ ## tc ## _body(const atf_tc_t *); \
56 static atf_tc_t atfu_ ## tc ## _tc; \
57 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \
59 .m_head = atfu_ ## tc ## _head, \
60 .m_body = atfu_ ## tc ## _body, \
64 #define ATF_TC_WITH_CLEANUP(tc) \
65 static void atfu_ ## tc ## _head(atf_tc_t *); \
66 static void atfu_ ## tc ## _body(const atf_tc_t *); \
67 static void atfu_ ## tc ## _cleanup(const atf_tc_t *); \
68 static atf_tc_t atfu_ ## tc ## _tc; \
69 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \
71 .m_head = atfu_ ## tc ## _head, \
72 .m_body = atfu_ ## tc ## _body, \
73 .m_cleanup = atfu_ ## tc ## _cleanup, \
76 #define ATF_TC_HEAD(tc, tcptr) \
79 atfu_ ## tc ## _head(atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED)
81 #define ATF_TC_HEAD_NAME(tc) \
82 (atfu_ ## tc ## _head)
84 #define ATF_TC_BODY(tc, tcptr) \
87 atfu_ ## tc ## _body(const atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED)
89 #define ATF_TC_BODY_NAME(tc) \
90 (atfu_ ## tc ## _body)
92 #define ATF_TC_CLEANUP(tc, tcptr) \
95 atfu_ ## tc ## _cleanup(const atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED)
97 #define ATF_TC_CLEANUP_NAME(tc) \
98 (atfu_ ## tc ## _cleanup)
100 #define ATF_TP_ADD_TCS(tps) \
101 static atf_error_t atfu_tp_add_tcs(atf_tp_t *); \
102 int atf_tp_main(int, char **, atf_error_t (*)(atf_tp_t *)); \
105 main(int argc, char **argv) \
107 return atf_tp_main(argc, argv, atfu_tp_add_tcs); \
111 atfu_tp_add_tcs(atf_tp_t *tps)
113 #define ATF_TP_ADD_TC(tp, tc) \
115 atf_error_t atfu_err; \
116 char **atfu_config = atf_tp_get_config(tp); \
117 if (atfu_config == NULL) \
118 return atf_no_memory_error(); \
119 atfu_err = atf_tc_init_pack(&atfu_ ## tc ## _tc, \
120 &atfu_ ## tc ## _tc_pack, \
121 (const char *const *)atfu_config); \
122 atf_utils_free_charpp(atfu_config); \
123 if (atf_is_error(atfu_err)) \
125 atfu_err = atf_tp_add_tc(tp, &atfu_ ## tc ## _tc); \
126 if (atf_is_error(atfu_err)) \
130 #define ATF_REQUIRE_MSG(expression, fmt, ...) \
133 atf_tc_fail_requirement(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
136 #define ATF_CHECK_MSG(expression, fmt, ...) \
139 atf_tc_fail_check(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
142 #define ATF_REQUIRE(expression) \
145 atf_tc_fail_requirement(__FILE__, __LINE__, "%s", \
146 #expression " not met"); \
149 #define ATF_CHECK(expression) \
152 atf_tc_fail_check(__FILE__, __LINE__, "%s", \
153 #expression " not met"); \
156 #define ATF_REQUIRE_EQ(expected, actual) \
157 ATF_REQUIRE_MSG((expected) == (actual), "%s != %s", #expected, #actual)
159 #define ATF_CHECK_EQ(expected, actual) \
160 ATF_CHECK_MSG((expected) == (actual), "%s != %s", #expected, #actual)
162 #define ATF_REQUIRE_EQ_MSG(expected, actual, fmt, ...) \
163 ATF_REQUIRE_MSG((expected) == (actual), "%s != %s: " fmt, \
164 #expected, #actual, ##__VA_ARGS__)
166 #define ATF_CHECK_EQ_MSG(expected, actual, fmt, ...) \
167 ATF_CHECK_MSG((expected) == (actual), "%s != %s: " fmt, \
168 #expected, #actual, ##__VA_ARGS__)
170 #define ATF_REQUIRE_STREQ(expected, actual) \
171 ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \
172 #expected, #actual, expected, actual)
174 #define ATF_CHECK_STREQ(expected, actual) \
175 ATF_CHECK_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \
176 #expected, #actual, expected, actual)
178 #define ATF_REQUIRE_STREQ_MSG(expected, actual, fmt, ...) \
179 ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, \
180 "%s != %s (%s != %s): " fmt, \
181 #expected, #actual, expected, actual, ##__VA_ARGS__)
183 #define ATF_CHECK_STREQ_MSG(expected, actual, fmt, ...) \
184 ATF_CHECK_MSG(strcmp(expected, actual) == 0, \
185 "%s != %s (%s != %s): " fmt, \
186 #expected, #actual, expected, actual, ##__VA_ARGS__)
188 #define ATF_REQUIRE_MATCH(regexp, string) \
189 ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \
190 "'%s' not matched in '%s'", regexp, string);
192 #define ATF_CHECK_MATCH(regexp, string) \
193 ATF_CHECK_MSG(atf_utils_grep_string("%s", string, regexp), \
194 "'%s' not matched in '%s'", regexp, string);
196 #define ATF_REQUIRE_MATCH_MSG(regexp, string, fmt, ...) \
197 ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \
198 "'%s' not matched in '%s': " fmt, regexp, string, \
201 #define ATF_CHECK_MATCH_MSG(regexp, string, fmt, ...) \
202 ATF_CHECK_MSG(atf_utils_grep_string("%s", string, regexp), \
203 "'%s' not matched in '%s': " fmt, regexp, string, \
206 #define ATF_CHECK_ERRNO(exp_errno, bool_expr) \
207 atf_tc_check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr)
209 #define ATF_REQUIRE_ERRNO(exp_errno, bool_expr) \
210 atf_tc_require_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr)
212 #endif /* !defined(ATF_C_MACROS_H) */