xref: /aosp_15_r20/external/ComputeLibrary/tests/framework/Registrars.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017 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_REGISTRARS
25 #define ARM_COMPUTE_TEST_FRAMEWORK_REGISTRARS
26 
27 #include "DatasetModes.h"
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.
49      * @param[in] mode      Mode in which the test should be activated.
50      * @param[in] status    Status of the test case.
51      */
52     TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status);
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.
57      * @param[in] mode      Mode in which the test should be activated.
58      * @param[in] status    Status of the test case.
59      * @param[in] dataset   Dataset used as input for the test case.
60      */
61     template <typename D>
62     TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status, D &&dataset);
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>
TestCaseRegistrar(std::string test_name,DatasetMode mode,TestCaseFactory::Status status)80 inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status)
81 {
82     Framework::get().add_test_case<T>(std::move(test_name), mode, status);
83 }
84 
85 template <typename T>
86 template <typename D>
TestCaseRegistrar(std::string test_name,DatasetMode mode,TestCaseFactory::Status status,D && dataset)87 inline TestCaseRegistrar<T>::TestCaseRegistrar(std::string test_name, DatasetMode mode, TestCaseFactory::Status status, D &&dataset)
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.
96         Framework::get().add_data_test_case<T>(test_name, mode, status, it.description(), it);
97     }
98 }
99 
TestSuiteRegistrar()100 inline TestSuiteRegistrar::TestSuiteRegistrar()
101 {
102     Framework::get().pop_suite();
103 }
104 
TestSuiteRegistrar(std::string name)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 */
114