2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
30 #if !defined(ATF_C_MACROS_H)
31 #define ATF_C_MACROS_H
33 #include <atf-c/defs.h>
34 #include <atf-c/error.h>
37 #include <atf-c/utils.h>
39 #define ATF_TC_NAME(tc) \
42 #define ATF_TC_PACK_NAME(tc) \
43 (atfu_ ## tc ## _tc_pack)
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 = { \
51 .m_body = atfu_ ## tc ## _body, \
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 = { \
61 .m_head = atfu_ ## tc ## _head, \
62 .m_body = atfu_ ## tc ## _body, \
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 = { \
73 .m_head = atfu_ ## tc ## _head, \
74 .m_body = atfu_ ## tc ## _body, \
75 .m_cleanup = atfu_ ## tc ## _cleanup, \
78 #define ATF_TC_HEAD(tc, tcptr) \
81 atfu_ ## tc ## _head(atf_tc_t *tcptr)
83 #define ATF_TC_HEAD_NAME(tc) \
84 (atfu_ ## tc ## _head)
86 #define ATF_TC_BODY(tc, tcptr) \
89 atfu_ ## tc ## _body(const atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED)
91 #define ATF_TC_BODY_NAME(tc) \
92 (atfu_ ## tc ## _body)
94 #define ATF_TC_CLEANUP(tc, tcptr) \
97 atfu_ ## tc ## _cleanup(const atf_tc_t *tcptr ATF_DEFS_ATTRIBUTE_UNUSED)
99 #define ATF_TC_CLEANUP_NAME(tc) \
100 (atfu_ ## tc ## _cleanup)
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 *)); \
107 main(int argc, char **argv) \
109 return atf_tp_main(argc, argv, atfu_tp_add_tcs); \
113 atfu_tp_add_tcs(atf_tp_t *tps)
115 #define ATF_TP_ADD_TC(tp, tc) \
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)) \
127 atfu_err = atf_tp_add_tc(tp, &atfu_ ## tc ## _tc); \
128 if (atf_is_error(atfu_err)) \
132 #define ATF_REQUIRE_MSG(x, fmt, ...) \
135 atf_tc_fail_requirement(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
138 #define ATF_CHECK_MSG(x, fmt, ...) \
141 atf_tc_fail_check(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
144 #define ATF_REQUIRE(x) \
147 atf_tc_fail_requirement(__FILE__, __LINE__, "%s", #x " not met"); \
150 #define ATF_CHECK(x) \
153 atf_tc_fail_check(__FILE__, __LINE__, "%s", #x " not met"); \
156 #define ATF_REQUIRE_EQ(x, y) \
157 ATF_REQUIRE_MSG((x) == (y), "%s != %s", #x, #y)
159 #define ATF_CHECK_EQ(x, y) \
160 ATF_CHECK_MSG((x) == (y), "%s != %s", #x, #y)
162 #define ATF_REQUIRE_EQ_MSG(x, y, fmt, ...) \
163 ATF_REQUIRE_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__)
165 #define ATF_CHECK_EQ_MSG(x, y, fmt, ...) \
166 ATF_CHECK_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__)
168 #define ATF_REQUIRE_STREQ(x, y) \
169 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y)
171 #define ATF_CHECK_STREQ(x, y) \
172 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y)
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__)
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__)
182 #define ATF_CHECK_ERRNO(exp_errno, bool_expr) \
183 atf_tc_check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr)
185 #define ATF_REQUIRE_ERRNO(exp_errno, bool_expr) \
186 atf_tc_require_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr)
188 #endif /* !defined(ATF_C_MACROS_H) */