blob: c22177c9e66f88fcc1cd4400b8b31f139dda5baa [file] [log] [blame]
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017 Arm Limited.
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01003 *
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 Pflanzerd03b00a2017-07-17 13:50:12 +010027#include "DatasetModes.h"
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010028#include "Framework.h"
29
30#include <string>
31#include <utility>
32
33namespace arm_compute
34{
35namespace test
36{
37namespace framework
38{
39namespace detail
40{
41/** Helper class to statically register a test case. */
42template <typename T>
43class TestCaseRegistrar final
44{
45public:
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 Pflanzerd03b00a2017-07-17 13:50:12 +010049 * @param[in] mode Mode in which the test should be activated.
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010050 * @param[in] status Status of the test case.
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010051 */
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010052 TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010053
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 Pflanzerd03b00a2017-07-17 13:50:12 +010057 * @param[in] mode Mode in which the test should be activated.
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010058 * @param[in] status Status of the test case.
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010059 * @param[in] dataset Dataset used as input for the test case.
60 */
61 template <typename D>
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010062 TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status, D &&dataset);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010063};
64
65/** Helper class to statically begin and end a test suite. */
66class TestSuiteRegistrar final
67{
68public:
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
79template <typename T>
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010080inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010081{
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010082 Framework::get().add_test_case<T>(std::move(test_name), mode, status);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010083}
84
85template <typename T>
86template <typename D>
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010087inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status, D &&dataset)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010088{
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 Pflanzerbf234e02017-07-24 15:04:14 +010096 Framework::get().add_data_test_case<T>(test_name, mode, status, it.description(), it);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010097 }
98}
99
100inline TestSuiteRegistrar::TestSuiteRegistrar()
101{
102 Framework::get().pop_suite();
103}
104
105inline 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 */