Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017 Arm Limited. |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 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_REGISTRARS |
| 25 | #define ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS |
| 26 | |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 27 | #include "DatasetModes.h" |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 28 | #include "Framework.h" |
| 29 | |
| 30 | #include <string> |
| 31 | #include <utility> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace framework |
| 38 | { |
| 39 | namespace detail |
| 40 | { |
| 41 | /** Helper class to statically register a test case. */ |
| 42 | template <typename T> |
| 43 | class TestCaseRegistrar final |
| 44 | { |
| 45 | public: |
| 46 | /** Add a new test case with the given name to the framework. |
| 47 | * |
| 48 | * @param[in] test_name Name of the test case. |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 49 | * @param[in] mode Mode in which the test should be activated. |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 50 | * @param[in] status Status of the test case. |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 51 | */ |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 52 | TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 53 | |
| 54 | /** Add a new data test case with the given name to the framework. |
| 55 | * |
| 56 | * @param[in] test_name Name of the test case. |
Moritz Pflanzer | d03b00a | 2017-07-17 13:50:12 +0100 | [diff] [blame] | 57 | * @param[in] mode Mode in which the test should be activated. |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 58 | * @param[in] status Status of the test case. |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 59 | * @param[in] dataset Dataset used as input for the test case. |
| 60 | */ |
| 61 | template <typename D> |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 62 | TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status, D &&dataset); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /** Helper class to statically begin and end a test suite. */ |
| 66 | class TestSuiteRegistrar final |
| 67 | { |
| 68 | public: |
| 69 | /** Remove the last added test suite from the framework. */ |
| 70 | TestSuiteRegistrar(); |
| 71 | |
| 72 | /** Add a new test suite with the given name to the framework. |
| 73 | * |
| 74 | * @param[in] name Name of the test suite. |
| 75 | */ |
| 76 | TestSuiteRegistrar(std::string name); |
| 77 | }; |
| 78 | |
| 79 | template <typename T> |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 80 | inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status) |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 81 | { |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 82 | Framework::get().add_test_case<T>(std::move(test_name), mode, status); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | template <typename T> |
| 86 | template <typename D> |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 87 | inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status, D &&dataset) |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 88 | { |
| 89 | auto it = dataset.begin(); |
| 90 | |
| 91 | for(int i = 0; i < dataset.size(); ++i, ++it) |
| 92 | { |
| 93 | // WORKAROUND for GCC 4.9 |
| 94 | // The last argument should be *it to pass just the data and not the |
| 95 | // iterator. |
Moritz Pflanzer | bf234e0 | 2017-07-24 15:04:14 +0100 | [diff] [blame] | 96 | Framework::get().add_data_test_case<T>(test_name, mode, status, it.description(), it); |
Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | inline TestSuiteRegistrar::TestSuiteRegistrar() |
| 101 | { |
| 102 | Framework::get().pop_suite(); |
| 103 | } |
| 104 | |
| 105 | inline TestSuiteRegistrar::TestSuiteRegistrar(std::string name) |
| 106 | { |
| 107 | Framework::get().push_suite(std::move(name)); |
| 108 | } |
| 109 | } // namespace detail |
| 110 | } // namespace framework |
| 111 | } // namespace test |
| 112 | } // namespace arm_compute |
| 113 | #endif /* ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS */ |