1 /* 2 * Copyright (c) 2017-2021 Arm Limited. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in all 14 * copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 #ifndef ARM_COMPUTE_TEST_FRAMEWORK_MACROS 25 #define ARM_COMPUTE_TEST_FRAMEWORK_MACROS 26 27 #include "Framework.h" 28 #include "Registrars.h" 29 #include "TestCase.h" 30 31 // 32 // TEST SUITE MACROS 33 // 34 #define TEST_SUITE(SUITE_NAME) \ 35 namespace SUITE_NAME##Suite \ 36 { \ 37 static arm_compute::test::framework::detail::TestSuiteRegistrar SUITE_NAME##Suite_reg{ #SUITE_NAME }; 38 39 #define TEST_SUITE_END() \ 40 static arm_compute::test::framework::detail::TestSuiteRegistrar Suite_end; \ 41 } 42 // 43 // TEST SUITE MACROS END 44 // 45 46 // 47 // HELPER MACROS 48 // 49 50 #define CONCAT(ARG0, ARG1) ARG0##ARG1 51 52 #define VARIADIC_SIZE_IMPL(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, size, ...) size 53 #define VARIADIC_SIZE(...) VARIADIC_SIZE_IMPL(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) 54 55 #define JOIN_PARAM1(OP, param) OP(0, param) 56 #define JOIN_PARAM2(OP, param, ...) \ 57 OP(1, param) \ 58 , JOIN_PARAM1(OP, __VA_ARGS__) 59 #define JOIN_PARAM3(OP, param, ...) \ 60 OP(2, param) \ 61 , JOIN_PARAM2(OP, __VA_ARGS__) 62 #define JOIN_PARAM4(OP, param, ...) \ 63 OP(3, param) \ 64 , JOIN_PARAM3(OP, __VA_ARGS__) 65 #define JOIN_PARAM5(OP, param, ...) \ 66 OP(4, param) \ 67 , JOIN_PARAM4(OP, __VA_ARGS__) 68 #define JOIN_PARAM6(OP, param, ...) \ 69 OP(5, param) \ 70 , JOIN_PARAM5(OP, __VA_ARGS__) 71 #define JOIN_PARAM7(OP, param, ...) \ 72 OP(6, param) \ 73 , JOIN_PARAM6(OP, __VA_ARGS__) 74 #define JOIN_PARAM8(OP, param, ...) \ 75 OP(7, param) \ 76 , JOIN_PARAM7(OP, __VA_ARGS__) 77 #define JOIN_PARAM9(OP, param, ...) \ 78 OP(8, param) \ 79 , JOIN_PARAM8(OP, __VA_ARGS__) 80 #define JOIN_PARAM10(OP, param, ...) \ 81 OP(9, param) \ 82 , JOIN_PARAM9(OP, __VA_ARGS__) 83 #define JOIN_PARAM11(OP, param, ...) \ 84 OP(10, param) \ 85 , JOIN_PARAM10(OP, __VA_ARGS__) 86 #define JOIN_PARAM12(OP, param, ...) \ 87 OP(11, param) \ 88 , JOIN_PARAM11(OP, __VA_ARGS__) 89 #define JOIN_PARAM13(OP, param, ...) \ 90 OP(12, param) \ 91 , JOIN_PARAM12(OP, __VA_ARGS__) 92 #define JOIN_PARAM14(OP, param, ...) \ 93 OP(13, param) \ 94 , JOIN_PARAM13(OP, __VA_ARGS__) 95 #define JOIN_PARAM15(OP, param, ...) \ 96 OP(14, param) \ 97 , JOIN_PARAM14(OP, __VA_ARGS__) 98 #define JOIN_PARAM16(OP, param, ...) \ 99 OP(15, param) \ 100 , JOIN_PARAM15(OP, __VA_ARGS__) 101 #define JOIN_PARAM(OP, NUM, ...) \ 102 CONCAT(JOIN_PARAM, NUM) \ 103 (OP, __VA_ARGS__) 104 105 #define MAKE_TYPE_PARAM(i, name) typename T##i 106 #define MAKE_ARG_PARAM(i, name) const T##i &name 107 #define MAKE_TYPE_PARAMS(...) JOIN_PARAM(MAKE_TYPE_PARAM, VARIADIC_SIZE(__VA_ARGS__), __VA_ARGS__) 108 #define MAKE_ARG_PARAMS(...) JOIN_PARAM(MAKE_ARG_PARAM, VARIADIC_SIZE(__VA_ARGS__), __VA_ARGS__) 109 110 // 111 // TEST CASE MACROS 112 // 113 #define TEST_CASE_CONSTRUCTOR(TEST_NAME) \ 114 TEST_NAME() = default; 115 #define DATA_TEST_CASE_CONSTRUCTOR(TEST_NAME, DATASET) \ 116 template <typename D> \ 117 explicit TEST_NAME(D &&data) : DataTestCase{ std::forward<D>(data) } \ 118 { \ 119 } 120 #define FIXTURE_SETUP(FIXTURE) \ 121 void do_setup() override \ 122 { \ 123 framework::Framework::get().set_new_fixture_call(false); \ 124 FIXTURE::setup(); \ 125 } 126 #define FIXTURE_DATA_SETUP(FIXTURE) \ 127 void do_setup() override \ 128 { \ 129 framework::Framework::get().set_new_fixture_call(false); \ 130 apply(this, &FIXTURE::setup<As...>, _data); \ 131 } 132 #define FIXTURE_DATA_SETUP_NEW(FIXTURE) \ 133 void do_setup() override \ 134 { \ 135 framework::Framework::get().set_new_fixture_call(true); \ 136 apply(this, &FIXTURE::setup<As...>, _data); \ 137 configure_target(); \ 138 if(!framework::Framework::get().configure_only()) \ 139 { \ 140 allocate_and_run_target(); \ 141 compute_reference(); \ 142 } \ 143 } 144 #define FIXTURE_RUN(FIXTURE) \ 145 void do_run() override \ 146 { \ 147 FIXTURE::run(); \ 148 } 149 #define FIXTURE_SYNC(FIXTURE) \ 150 void do_sync() override \ 151 { \ 152 FIXTURE::sync(); \ 153 } 154 #define FIXTURE_TEARDOWN(FIXTURE) \ 155 void do_teardown() override \ 156 { \ 157 FIXTURE::teardown(); \ 158 } 159 #define TEST_REGISTRAR(TEST_NAME, MODE, STATUS) \ 160 static arm_compute::test::framework::detail::TestCaseRegistrar<TEST_NAME> TEST_NAME##_reg \ 161 { \ 162 #TEST_NAME, MODE, STATUS \ 163 } 164 #define DATA_TEST_REGISTRAR(TEST_NAME, MODE, STATUS, DATASET) \ 165 static arm_compute::test::framework::detail::TestCaseRegistrar<TEST_NAME<decltype(DATASET)::type>> TEST_NAME##_reg \ 166 { \ 167 #TEST_NAME, MODE, STATUS, DATASET \ 168 } 169 170 #define TEST_CASE_IMPL(TEST_NAME, MODE, STATUS) \ 171 class TEST_NAME : public arm_compute::test::framework::TestCase \ 172 { \ 173 public: \ 174 TEST_CASE_CONSTRUCTOR(TEST_NAME) \ 175 void do_run() override; \ 176 }; \ 177 TEST_REGISTRAR(TEST_NAME, MODE, STATUS); \ 178 void TEST_NAME::do_run() 179 180 #define TEST_CASE(TEST_NAME, MODE) \ 181 TEST_CASE_IMPL(TEST_NAME, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE) 182 #define EXPECTED_FAILURE_TEST_CASE(TEST_NAME, MODE) \ 183 TEST_CASE_IMPL(TEST_NAME, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE) 184 #define DISABLED_TEST_CASE(TEST_NAME, MODE) \ 185 TEST_CASE_IMPL(TEST_NAME, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED) 186 187 #define DATA_TEST_CASE_IMPL(TEST_NAME, MODE, STATUS, DATASET, ...) \ 188 template <typename T> \ 189 class TEST_NAME; \ 190 template <typename... As> \ 191 class TEST_NAME<std::tuple<As...>> : public arm_compute::test::framework::DataTestCase<decltype(DATASET)::type> \ 192 { \ 193 public: \ 194 DATA_TEST_CASE_CONSTRUCTOR(TEST_NAME, DATASET) \ 195 void do_run() override \ 196 { \ 197 arm_compute::test::framework::apply(this, &TEST_NAME::run<As...>, _data); \ 198 } \ 199 template <MAKE_TYPE_PARAMS(__VA_ARGS__)> \ 200 void run(MAKE_ARG_PARAMS(__VA_ARGS__)); \ 201 }; \ 202 DATA_TEST_REGISTRAR(TEST_NAME, MODE, STATUS, DATASET); \ 203 template <typename... As> \ 204 template <MAKE_TYPE_PARAMS(__VA_ARGS__)> \ 205 void TEST_NAME<std::tuple<As...>>::run(MAKE_ARG_PARAMS(__VA_ARGS__)) 206 207 #define DATA_TEST_CASE(TEST_NAME, MODE, DATASET, ...) \ 208 DATA_TEST_CASE_IMPL(TEST_NAME, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE, DATASET, __VA_ARGS__) 209 #define EXPECTED_FAILURE_DATA_TEST_CASE(TEST_NAME, MODE, DATASET, ...) \ 210 DATA_TEST_CASE_IMPL(TEST_NAME, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE, DATASET, __VA_ARGS__) 211 #define DISABLED_DATA_TEST_CASE(TEST_NAME, MODE, DATASET, ...) \ 212 DATA_TEST_CASE_IMPL(TEST_NAME, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED, DATASET, __VA_ARGS__) 213 214 #define FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, STATUS) \ 215 class TEST_NAME : public arm_compute::test::framework::TestCase, public FIXTURE \ 216 { \ 217 public: \ 218 TEST_CASE_CONSTRUCTOR(TEST_NAME) \ 219 FIXTURE_SETUP(FIXTURE) \ 220 void do_run() override; \ 221 FIXTURE_TEARDOWN(FIXTURE) \ 222 }; \ 223 TEST_REGISTRAR(TEST_NAME, MODE, STATUS); \ 224 void TEST_NAME::do_run() 225 226 #define FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 227 FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE) 228 #define EXPECTED_FAILURE_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 229 FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE) 230 #define DISABLED_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 231 FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED) 232 233 #define EMPTY_BODY_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 234 FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 235 { \ 236 } 237 238 #define FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, STATUS, DATASET) \ 239 template <typename T> \ 240 class TEST_NAME; \ 241 template <typename... As> \ 242 class TEST_NAME<std::tuple<As...>> : public arm_compute::test::framework::DataTestCase<decltype(DATASET)::type>, public FIXTURE \ 243 { \ 244 public: \ 245 DATA_TEST_CASE_CONSTRUCTOR(TEST_NAME, DATASET) \ 246 FIXTURE_DATA_SETUP(FIXTURE) \ 247 void do_run() override; \ 248 FIXTURE_TEARDOWN(FIXTURE) \ 249 }; \ 250 DATA_TEST_REGISTRAR(TEST_NAME, MODE, STATUS, DATASET); \ 251 template <typename... As> \ 252 void TEST_NAME<std::tuple<As...>>::do_run() 253 254 #define FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, DATASET) \ 255 FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE, DATASET) 256 #define EXPECTED_FAILURE_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, DATASET) \ 257 FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE, DATASET) 258 #define DISABLED_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, DATASET) \ 259 FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED, DATASET) 260 261 #define FIXTURE_DATA_TEST_CASE_NEW_IMPL(TEST_NAME, FIXTURE, MODE, STATUS, DATASET) \ 262 template <typename T> \ 263 class TEST_NAME; \ 264 template <typename... As> \ 265 class TEST_NAME<std::tuple<As...>> : public arm_compute::test::framework::DataTestCase<decltype(DATASET)::type>, public FIXTURE \ 266 { \ 267 public: \ 268 DATA_TEST_CASE_CONSTRUCTOR(TEST_NAME, DATASET) \ 269 FIXTURE_DATA_SETUP_NEW(FIXTURE) \ 270 void do_run() override; \ 271 FIXTURE_TEARDOWN(FIXTURE) \ 272 }; \ 273 DATA_TEST_REGISTRAR(TEST_NAME, MODE, STATUS, DATASET); \ 274 template <typename... As> \ 275 void TEST_NAME<std::tuple<As...>>::do_run() 276 277 #define FIXTURE_DATA_TEST_CASE_NEW(TEST_NAME, FIXTURE, MODE, DATASET) \ 278 FIXTURE_DATA_TEST_CASE_NEW_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE, DATASET) 279 #define EXPECTED_FAILURE_FIXTURE_DATA_TEST_CASE_NEW(TEST_NAME, FIXTURE, MODE, DATASET) \ 280 FIXTURE_DATA_TEST_CASE_NEW_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE, DATASET) 281 #define DISABLED_FIXTURE_DATA_TEST_CASE_NEW(TEST_NAME, FIXTURE, MODE, DATASET) \ 282 FIXTURE_DATA_TEST_CASE_NEW_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED, DATASET) 283 284 #define REGISTER_FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, STATUS) \ 285 class TEST_NAME : public arm_compute::test::framework::TestCase, public FIXTURE \ 286 { \ 287 public: \ 288 TEST_CASE_CONSTRUCTOR(TEST_NAME) \ 289 FIXTURE_SETUP(FIXTURE) \ 290 FIXTURE_RUN(FIXTURE) \ 291 FIXTURE_SYNC(FIXTURE) \ 292 FIXTURE_TEARDOWN(FIXTURE) \ 293 }; \ 294 TEST_REGISTRAR(TEST_NAME, MODE, STATUS) 295 296 #define REGISTER_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 297 REGISTER_FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE) 298 #define EXPECTED_FAILURE_REGISTER_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 299 REGISTER_FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE) 300 #define DISABLED_REGISTER_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE) \ 301 REGISTER_FIXTURE_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED) 302 303 #define REGISTER_FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, STATUS, DATASET) \ 304 template <typename T> \ 305 class TEST_NAME; \ 306 template <typename... As> \ 307 class TEST_NAME<std::tuple<As...>> : public arm_compute::test::framework::DataTestCase<decltype(DATASET)::type>, public FIXTURE \ 308 { \ 309 public: \ 310 DATA_TEST_CASE_CONSTRUCTOR(TEST_NAME, DATASET) \ 311 FIXTURE_DATA_SETUP(FIXTURE) \ 312 FIXTURE_RUN(FIXTURE) \ 313 FIXTURE_SYNC(FIXTURE) \ 314 FIXTURE_TEARDOWN(FIXTURE) \ 315 }; \ 316 DATA_TEST_REGISTRAR(TEST_NAME, MODE, STATUS, DATASET) 317 318 #define REGISTER_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, DATASET) \ 319 REGISTER_FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE, DATASET) 320 #define EXPECTED_FAILURE_REGISTER_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, DATASET) \ 321 REGISTER_FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::EXPECTED_FAILURE, DATASET) 322 #define DISABLED_REGISTER_FIXTURE_DATA_TEST_CASE(TEST_NAME, FIXTURE, MODE, DATASET) \ 323 REGISTER_FIXTURE_DATA_TEST_CASE_IMPL(TEST_NAME, FIXTURE, MODE, arm_compute::test::framework::TestCaseFactory::Status::DISABLED, DATASET) 324 // 325 // TEST CASE MACROS END 326 // 327 #endif /* ARM_COMPUTE_TEST_FRAMEWORK_MACROS */