xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/vktTestGroupUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTTESTGROUPUTIL_HPP
2 #define _VKTTESTGROUPUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief TestCaseGroup utilities
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuTestCase.hpp"
28 
29 namespace vkt
30 {
31 
32 class TestGroupHelper0 : public tcu::TestCaseGroup
33 {
34 public:
35     typedef void (*CreateChildrenFunc)(tcu::TestCaseGroup *testGroup);
36     typedef void (*CleanupGroupFunc)(tcu::TestCaseGroup *testGroup);
37 
TestGroupHelper0(tcu::TestContext & testCtx,const std::string & name,CreateChildrenFunc createChildren,CleanupGroupFunc cleanupGroup)38     TestGroupHelper0(tcu::TestContext &testCtx, const std::string &name, CreateChildrenFunc createChildren,
39                      CleanupGroupFunc cleanupGroup)
40         : tcu::TestCaseGroup(testCtx, name.c_str())
41         , m_createChildren(createChildren)
42         , m_cleanupGroup(cleanupGroup)
43     {
44     }
45 
~TestGroupHelper0(void)46     ~TestGroupHelper0(void)
47     {
48     }
49 
init(void)50     void init(void)
51     {
52         m_createChildren(this);
53     }
54 
deinit(void)55     void deinit(void)
56     {
57         if (m_cleanupGroup)
58             m_cleanupGroup(this);
59     }
60 
61 private:
62     const CreateChildrenFunc m_createChildren;
63     const CleanupGroupFunc m_cleanupGroup;
64 };
65 
66 template <typename Arg0>
67 class TestGroupHelper1 : public tcu::TestCaseGroup
68 {
69 public:
70     typedef void (*CreateChildrenFunc)(tcu::TestCaseGroup *testGroup, Arg0 arg0);
71     typedef void (*CleanupGroupFunc)(tcu::TestCaseGroup *testGroup, Arg0 arg0);
72 
TestGroupHelper1(tcu::TestContext & testCtx,const std::string & name,CreateChildrenFunc createChildren,const Arg0 & arg0,CleanupGroupFunc cleanupGroup)73     TestGroupHelper1(tcu::TestContext &testCtx, const std::string &name, CreateChildrenFunc createChildren,
74                      const Arg0 &arg0, CleanupGroupFunc cleanupGroup)
75         : tcu::TestCaseGroup(testCtx, name.c_str())
76         , m_createChildren(createChildren)
77         , m_cleanupGroup(cleanupGroup)
78         , m_arg0(arg0)
79     {
80     }
81 
init(void)82     void init(void)
83     {
84         m_createChildren(this, m_arg0);
85     }
deinit(void)86     void deinit(void)
87     {
88         if (m_cleanupGroup)
89             m_cleanupGroup(this, m_arg0);
90     }
91 
92 private:
93     const CreateChildrenFunc m_createChildren;
94     const CleanupGroupFunc m_cleanupGroup;
95     const Arg0 m_arg0;
96 };
97 
98 template <typename Arg0, typename Arg1>
99 class TestGroupHelper2 : public tcu::TestCaseGroup
100 {
101 public:
102     typedef void (*CreateChildrenFunc)(tcu::TestCaseGroup *testGroup, Arg0 arg0, Arg1 arg1);
103     typedef void (*CleanupGroupFunc)(tcu::TestCaseGroup *testGroup, Arg0 arg0, Arg1 arg1);
104 
TestGroupHelper2(tcu::TestContext & testCtx,const std::string & name,CreateChildrenFunc createChildren,const Arg0 & arg0,const Arg1 & arg1,CleanupGroupFunc cleanupGroup)105     TestGroupHelper2(tcu::TestContext &testCtx, const std::string &name, CreateChildrenFunc createChildren,
106                      const Arg0 &arg0, const Arg1 &arg1, CleanupGroupFunc cleanupGroup)
107         : tcu::TestCaseGroup(testCtx, name.c_str())
108         , m_createChildren(createChildren)
109         , m_cleanupGroup(cleanupGroup)
110         , m_arg0(arg0)
111         , m_arg1(arg1)
112     {
113     }
114 
init(void)115     void init(void)
116     {
117         m_createChildren(this, m_arg0, m_arg1);
118     }
deinit(void)119     void deinit(void)
120     {
121         if (m_cleanupGroup)
122             m_cleanupGroup(this, m_arg0, m_arg1);
123     }
124 
125 private:
126     const CreateChildrenFunc m_createChildren;
127     const CleanupGroupFunc m_cleanupGroup;
128     const Arg0 m_arg0;
129     const Arg1 m_arg1;
130 };
131 
createTestGroup(tcu::TestContext & testCtx,const std::string & name,TestGroupHelper0::CreateChildrenFunc createChildren,TestGroupHelper0::CleanupGroupFunc cleanupGroup=DE_NULL)132 inline tcu::TestCaseGroup *createTestGroup(tcu::TestContext &testCtx, const std::string &name,
133                                            TestGroupHelper0::CreateChildrenFunc createChildren,
134                                            TestGroupHelper0::CleanupGroupFunc cleanupGroup = DE_NULL)
135 {
136     return new TestGroupHelper0(testCtx, name, createChildren, cleanupGroup);
137 }
138 
139 template <typename Arg0>
createTestGroup(tcu::TestContext & testCtx,const std::string & name,typename TestGroupHelper1<Arg0>::CreateChildrenFunc createChildren,Arg0 arg0,typename TestGroupHelper1<Arg0>::CleanupGroupFunc cleanupGroup=DE_NULL)140 tcu::TestCaseGroup *createTestGroup(tcu::TestContext &testCtx, const std::string &name,
141                                     typename TestGroupHelper1<Arg0>::CreateChildrenFunc createChildren, Arg0 arg0,
142                                     typename TestGroupHelper1<Arg0>::CleanupGroupFunc cleanupGroup = DE_NULL)
143 {
144     return new TestGroupHelper1<Arg0>(testCtx, name, createChildren, arg0, cleanupGroup);
145 }
146 template <typename Arg0, typename Arg1>
createTestGroup(tcu::TestContext & testCtx,const std::string & name,typename TestGroupHelper2<Arg0,Arg1>::CreateChildrenFunc createChildren,Arg0 arg0,Arg1 arg1,typename TestGroupHelper2<Arg0,Arg1>::CleanupGroupFunc cleanupGroup=DE_NULL)147 tcu::TestCaseGroup *createTestGroup(tcu::TestContext &testCtx, const std::string &name,
148                                     typename TestGroupHelper2<Arg0, Arg1>::CreateChildrenFunc createChildren, Arg0 arg0,
149                                     Arg1 arg1,
150                                     typename TestGroupHelper2<Arg0, Arg1>::CleanupGroupFunc cleanupGroup = DE_NULL)
151 {
152     return new TestGroupHelper2<Arg0, Arg1>(testCtx, name, createChildren, arg0, arg1, cleanupGroup);
153 }
154 
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,TestGroupHelper0::CreateChildrenFunc createChildren)155 inline void addTestGroup(tcu::TestCaseGroup *parent, const std::string &name,
156                          TestGroupHelper0::CreateChildrenFunc createChildren)
157 {
158     parent->addChild(createTestGroup(parent->getTestContext(), name, createChildren));
159 }
160 
161 template <typename Arg0>
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,typename TestGroupHelper1<Arg0>::CreateChildrenFunc createChildren,Arg0 arg0,typename TestGroupHelper1<Arg0>::CleanupGroupFunc cleanupGroup=DE_NULL)162 void addTestGroup(tcu::TestCaseGroup *parent, const std::string &name,
163                   typename TestGroupHelper1<Arg0>::CreateChildrenFunc createChildren, Arg0 arg0,
164                   typename TestGroupHelper1<Arg0>::CleanupGroupFunc cleanupGroup = DE_NULL)
165 {
166     parent->addChild(createTestGroup<Arg0>(parent->getTestContext(), name, createChildren, arg0, cleanupGroup));
167 }
168 
169 template <typename Arg0, typename Arg1>
addTestGroup(tcu::TestCaseGroup * parent,const std::string & name,typename TestGroupHelper2<Arg0,Arg1>::CreateChildrenFunc createChildren,Arg0 arg0,Arg1 arg1,typename TestGroupHelper2<Arg0,Arg1>::CleanupGroupFunc cleanupGroup=DE_NULL)170 void addTestGroup(tcu::TestCaseGroup *parent, const std::string &name,
171                   typename TestGroupHelper2<Arg0, Arg1>::CreateChildrenFunc createChildren, Arg0 arg0, Arg1 arg1,
172                   typename TestGroupHelper2<Arg0, Arg1>::CleanupGroupFunc cleanupGroup = DE_NULL)
173 {
174     parent->addChild(
175         createTestGroup<Arg0, Arg1>(parent->getTestContext(), name, createChildren, arg0, arg1, cleanupGroup));
176 }
177 
178 } // namespace vkt
179 
180 #endif // _VKTTESTGROUPUTIL_HPP
181