1 /* 2 * Automated Testing Framework (atf) 3 * 4 * Copyright (c) 2008, 2009 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/tc.h> 34 #include <atf-c/tp.h> 35 36 #define ATF_TC_NAME(tc) \ 37 (atfu_ ## tc ## _tc) 38 39 #define ATF_TC_PACK_NAME(tc) \ 40 (atfu_ ## tc ## _tc_pack) 41 42 #define ATF_TC(tc) \ 43 static void atfu_ ## tc ## _head(atf_tc_t *); \ 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 = { \ 47 .m_ident = #tc, \ 48 .m_head = atfu_ ## tc ## _head, \ 49 .m_body = atfu_ ## tc ## _body, \ 50 .m_cleanup = NULL, \ 51 } 52 53 #define ATF_TC_WITH_CLEANUP(tc) \ 54 static void atfu_ ## tc ## _head(atf_tc_t *); \ 55 static void atfu_ ## tc ## _body(const atf_tc_t *); \ 56 static void atfu_ ## tc ## _cleanup(const atf_tc_t *); \ 57 static atf_tc_t atfu_ ## tc ## _tc; \ 58 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \ 59 .m_ident = #tc, \ 60 .m_head = atfu_ ## tc ## _head, \ 61 .m_body = atfu_ ## tc ## _body, \ 62 .m_cleanup = atfu_ ## tc ## _cleanup, \ 63 } 64 65 #define ATF_TC_HEAD(tc, tcptr) \ 66 static \ 67 void \ 68 atfu_ ## tc ## _head(atf_tc_t *tcptr) 69 70 #define ATF_TC_HEAD_NAME(tc) \ 71 (atfu_ ## tc ## _head) 72 73 #define ATF_TC_BODY(tc, tcptr) \ 74 static \ 75 void \ 76 atfu_ ## tc ## _body(const atf_tc_t *tcptr) 77 78 #define ATF_TC_BODY_NAME(tc) \ 79 (atfu_ ## tc ## _body) 80 81 #define ATF_TC_CLEANUP(tc, tcptr) \ 82 static \ 83 void \ 84 atfu_ ## tc ## _cleanup(const atf_tc_t *tcptr) 85 86 #define ATF_TC_CLEANUP_NAME(tc) \ 87 (atfu_ ## tc ## _cleanup) 88 89 #define ATF_TP_ADD_TCS(tps) \ 90 static atf_error_t atfu_tp_add_tcs(atf_tp_t *); \ 91 int atf_tp_main(int, char **, atf_error_t (*)(atf_tp_t *)); \ 92 \ 93 int \ 94 main(int argc, char **argv) \ 95 { \ 96 return atf_tp_main(argc, argv, atfu_tp_add_tcs); \ 97 } \ 98 static \ 99 atf_error_t \ 100 atfu_tp_add_tcs(atf_tp_t *tps) 101 102 #define ATF_TP_ADD_TC(tp, tc) \ 103 do { \ 104 atf_error_t atfu_err; \ 105 atfu_err = atf_tc_init_pack(&atfu_ ## tc ## _tc, \ 106 &atfu_ ## tc ## _tc_pack, \ 107 atf_tp_get_config(tp)); \ 108 if (atf_is_error(atfu_err)) \ 109 return atfu_err; \ 110 atfu_err = atf_tp_add_tc(tp, &atfu_ ## tc ## _tc); \ 111 if (atf_is_error(atfu_err)) \ 112 return atfu_err; \ 113 } while (0) 114 115 #define ATF_REQUIRE_MSG(x, fmt, ...) \ 116 do { \ 117 if (!(x)) \ 118 atf_tc_fail_requirement(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \ 119 } while(0) 120 121 #define ATF_CHECK_MSG(x, fmt, ...) \ 122 do { \ 123 if (!(x)) \ 124 atf_tc_fail_check(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \ 125 } while(0) 126 127 #define ATF_REQUIRE(x) \ 128 ATF_REQUIRE_MSG(x, #x " not met") 129 130 #define ATF_CHECK(x) \ 131 ATF_CHECK_MSG(x, #x " not met") 132 133 #define ATF_REQUIRE_EQ(x, y) \ 134 ATF_REQUIRE_MSG((x) == (y), "%s != %s", #x, #y) 135 136 #define ATF_CHECK_EQ(x, y) \ 137 ATF_CHECK_MSG((x) == (y), "%s != %s", #x, #y) 138 139 #define ATF_REQUIRE_EQ_MSG(x, y, fmt, ...) \ 140 ATF_REQUIRE_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__) 141 142 #define ATF_CHECK_EQ_MSG(x, y, fmt, ...) \ 143 ATF_CHECK_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__) 144 145 #define ATF_REQUIRE_STREQ(x, y) \ 146 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) 147 148 #define ATF_CHECK_STREQ(x, y) \ 149 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y) 150 151 #define ATF_REQUIRE_STREQ_MSG(x, y, fmt, ...) \ 152 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \ 153 #x, #y, x, y, ##__VA_ARGS__) 154 155 #define ATF_CHECK_STREQ_MSG(x, y, fmt, ...) \ 156 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \ 157 #x, #y, x, y, ##__VA_ARGS__) 158 159 #endif /* !defined(ATF_C_MACROS_H) */ 160