1 #ifndef _VKTTESTCASEUTIL_HPP
2 #define _VKTTESTCASEUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2015 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 TestCase utilities
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "vktTestCase.hpp"
28
29 namespace vkt
30 {
31
32 template<typename Arg0>
33 struct NoPrograms1
34 {
initvkt::NoPrograms135 void init (vk::SourceCollections&, Arg0) const {}
36 };
37
38 template<typename Instance, typename Arg0, typename Programs = NoPrograms1<Arg0> >
39 class InstanceFactory1 : public TestCase
40 {
41 public:
InstanceFactory1(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,const Arg0 & arg0)42 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0)
43 : TestCase (testCtx, type, name, desc)
44 , m_progs ()
45 , m_arg0 (arg0)
46 {}
47
InstanceFactory1(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,const Programs & progs,const Arg0 & arg0)48 InstanceFactory1 (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0)
49 : TestCase (testCtx, type, name, desc)
50 , m_progs (progs)
51 , m_arg0 (arg0)
52 {}
53
initPrograms(vk::SourceCollections & dst) const54 void initPrograms (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
createInstance(Context & context) const55 TestInstance* createInstance (Context& context) const { return new Instance(context, m_arg0); }
checkSupport(Context &) const56 void checkSupport (Context&) const { }
57
58 private:
59 const Programs m_progs;
60 const Arg0 m_arg0;
61 };
62
63 template<typename Instance, typename Arg0, typename Support, typename Programs = NoPrograms1<Arg0> >
64 class InstanceFactory1WithSupport : public TestCase
65 {
66 public:
67
InstanceFactory1WithSupport(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,const Arg0 & arg0,const Support & support)68 InstanceFactory1WithSupport (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0, const Support& support)
69 : TestCase (testCtx, type, name, desc)
70 , m_progs ()
71 , m_arg0 (arg0)
72 , m_support (support)
73 {}
74
InstanceFactory1WithSupport(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,const Programs & progs,const Arg0 & arg0,const Support & support)75 InstanceFactory1WithSupport (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0, const Support& support)
76 : TestCase (testCtx, type, name, desc)
77 , m_progs (progs)
78 , m_arg0 (arg0)
79 , m_support (support)
80 {}
81
initPrograms(vk::SourceCollections & dst) const82 void initPrograms (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
createInstance(Context & context) const83 TestInstance* createInstance (Context& context) const { return new Instance(context, m_arg0); }
checkSupport(Context & context) const84 void checkSupport (Context& context) const { m_support.checkSupport(context); }
85
86 private:
87 const Programs m_progs;
88 const Arg0 m_arg0;
89 const Support m_support;
90 };
91
92 class FunctionInstance0 : public TestInstance
93 {
94 public:
95 typedef tcu::TestStatus (*Function) (Context& context);
96
FunctionInstance0(Context & context,Function function)97 FunctionInstance0 (Context& context, Function function)
98 : TestInstance (context)
99 , m_function (function)
100 {}
101
iterate(void)102 tcu::TestStatus iterate (void) { return m_function(m_context); }
103
104 private:
105 const Function m_function;
106 };
107
108 template<typename Arg0>
109 class FunctionInstance1 : public TestInstance
110 {
111 public:
112 typedef tcu::TestStatus (*Function) (Context& context, Arg0 arg0);
113
114 struct Args
115 {
Argsvkt::FunctionInstance1::Args116 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {}
117
118 Function func;
119 Arg0 arg0;
120 };
121
FunctionInstance1(Context & context,const Args & args)122 FunctionInstance1 (Context& context, const Args& args)
123 : TestInstance (context)
124 , m_args (args)
125 {}
126
iterate(void)127 tcu::TestStatus iterate (void) { return m_args.func(m_context, m_args.arg0); }
128
129 private:
130 const Args m_args;
131 };
132
133 class FunctionPrograms0
134 {
135 public:
136 typedef void (*Function) (vk::SourceCollections& dst);
137
FunctionPrograms0(Function func)138 FunctionPrograms0 (Function func)
139 : m_func(func)
140 {}
141
init(vk::SourceCollections & dst,FunctionInstance0::Function) const142 void init (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); }
143
144 private:
145 const Function m_func;
146 };
147
148 class FunctionSupport0
149 {
150 public:
151 typedef void (*Function) (Context& context);
152
FunctionSupport0(Function function)153 FunctionSupport0 (Function function)
154 : m_function(function)
155 {}
156
checkSupport(Context & context) const157 void checkSupport (Context& context) const { m_function(context); }
158
159 private:
160 const Function m_function;
161 };
162
163 template<typename Arg0>
164 class FunctionSupport1
165 {
166 public:
167 typedef void (*Function) (Context& context, Arg0 arg0);
168
169 struct Args
170 {
Argsvkt::FunctionSupport1::Args171 Args (Function func_, Arg0 arg0_)
172 : func(func_)
173 , arg0(arg0_)
174 {}
175
176 Function func;
177 Arg0 arg0;
178 };
179
FunctionSupport1(const Args & args)180 FunctionSupport1 (const Args& args)
181 : m_args(args)
182 {}
183
checkSupport(Context & context) const184 void checkSupport (Context& context) const { return m_args.func(context, m_args.arg0); }
185
186 private:
187 const Args m_args;
188 };
189
190 template<typename Arg0>
191 class FunctionPrograms1
192 {
193 public:
194 typedef void (*Function) (vk::SourceCollections& dst, Arg0 arg0);
195
FunctionPrograms1(Function func)196 FunctionPrograms1 (Function func)
197 : m_func(func)
198 {}
199
init(vk::SourceCollections & dst,const typename FunctionInstance1<Arg0>::Args & args) const200 void init (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); }
201
202 private:
203 const Function m_func;
204 };
205
206 // createFunctionCase
207
createFunctionCase(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,FunctionInstance0::Function testFunction)208 inline TestCase* createFunctionCase (tcu::TestContext& testCtx,
209 tcu::TestNodeType type,
210 const std::string& name,
211 const std::string& desc,
212 FunctionInstance0::Function testFunction)
213 {
214 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction);
215 }
216
createFunctionCase(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,FunctionSupport0::Function checkSupport,FunctionInstance0::Function testFunction)217 inline TestCase* createFunctionCase (tcu::TestContext& testCtx,
218 tcu::TestNodeType type,
219 const std::string& name,
220 const std::string& desc,
221 FunctionSupport0::Function checkSupport,
222 FunctionInstance0::Function testFunction)
223 {
224 return new InstanceFactory1WithSupport<FunctionInstance0, FunctionInstance0::Function, FunctionSupport0>(testCtx, type, name, desc, testFunction, checkSupport);
225 }
226
createFunctionCaseWithPrograms(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,FunctionPrograms0::Function initPrograms,FunctionInstance0::Function testFunction)227 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
228 tcu::TestNodeType type,
229 const std::string& name,
230 const std::string& desc,
231 FunctionPrograms0::Function initPrograms,
232 FunctionInstance0::Function testFunction)
233 {
234 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>(
235 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction);
236 }
237
createFunctionCaseWithPrograms(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,FunctionSupport0::Function checkSupport,FunctionPrograms0::Function initPrograms,FunctionInstance0::Function testFunction)238 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
239 tcu::TestNodeType type,
240 const std::string& name,
241 const std::string& desc,
242 FunctionSupport0::Function checkSupport,
243 FunctionPrograms0::Function initPrograms,
244 FunctionInstance0::Function testFunction)
245 {
246 return new InstanceFactory1WithSupport<FunctionInstance0, FunctionInstance0::Function, FunctionSupport0, FunctionPrograms0>(
247 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction, checkSupport);
248 }
249
250 template<typename Arg0>
createFunctionCase(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,typename FunctionInstance1<Arg0>::Function testFunction,Arg0 arg0)251 TestCase* createFunctionCase (tcu::TestContext& testCtx,
252 tcu::TestNodeType type,
253 const std::string& name,
254 const std::string& desc,
255 typename FunctionInstance1<Arg0>::Function testFunction,
256 Arg0 arg0)
257 {
258 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>(
259 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
260 }
261
262 template<typename Arg0>
createFunctionCase(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,typename FunctionSupport1<Arg0>::Function checkSupport,typename FunctionInstance1<Arg0>::Function testFunction,Arg0 arg0)263 TestCase* createFunctionCase (tcu::TestContext& testCtx,
264 tcu::TestNodeType type,
265 const std::string& name,
266 const std::string& desc,
267 typename FunctionSupport1<Arg0>::Function checkSupport,
268 typename FunctionInstance1<Arg0>::Function testFunction,
269 Arg0 arg0)
270 {
271 return new InstanceFactory1WithSupport<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionSupport1<Arg0> >(
272 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0), typename FunctionSupport1<Arg0>::Args(checkSupport, arg0));
273 }
274
275 template<typename Arg0>
createFunctionCaseWithPrograms(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,typename FunctionPrograms1<Arg0>::Function initPrograms,typename FunctionInstance1<Arg0>::Function testFunction,Arg0 arg0)276 TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
277 tcu::TestNodeType type,
278 const std::string& name,
279 const std::string& desc,
280 typename FunctionPrograms1<Arg0>::Function initPrograms,
281 typename FunctionInstance1<Arg0>::Function testFunction,
282 Arg0 arg0)
283 {
284 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >(
285 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
286 }
287
288 template<typename Arg0>
createFunctionCaseWithPrograms(tcu::TestContext & testCtx,tcu::TestNodeType type,const std::string & name,const std::string & desc,typename FunctionSupport1<Arg0>::Function checkSupport,typename FunctionPrograms1<Arg0>::Function initPrograms,typename FunctionInstance1<Arg0>::Function testFunction,Arg0 arg0)289 TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx,
290 tcu::TestNodeType type,
291 const std::string& name,
292 const std::string& desc,
293 typename FunctionSupport1<Arg0>::Function checkSupport,
294 typename FunctionPrograms1<Arg0>::Function initPrograms,
295 typename FunctionInstance1<Arg0>::Function testFunction,
296 Arg0 arg0)
297 {
298 return new InstanceFactory1WithSupport<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionSupport1<Arg0>, FunctionPrograms1<Arg0> >(
299 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0), typename FunctionSupport1<Arg0>::Args(checkSupport, arg0));
300 }
301
302 // addFunctionCase
303
addFunctionCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,FunctionInstance0::Function testFunc)304 inline void addFunctionCase (tcu::TestCaseGroup* group,
305 const std::string& name,
306 const std::string& desc,
307 FunctionInstance0::Function testFunc)
308 {
309 group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc));
310 }
311
addFunctionCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,FunctionSupport0::Function checkSupport,FunctionInstance0::Function testFunc)312 inline void addFunctionCase (tcu::TestCaseGroup* group,
313 const std::string& name,
314 const std::string& desc,
315 FunctionSupport0::Function checkSupport,
316 FunctionInstance0::Function testFunc)
317 {
318 group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, checkSupport, testFunc));
319 }
320
addFunctionCaseWithPrograms(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,FunctionPrograms0::Function initPrograms,FunctionInstance0::Function testFunc)321 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
322 const std::string& name,
323 const std::string& desc,
324 FunctionPrograms0::Function initPrograms,
325 FunctionInstance0::Function testFunc)
326 {
327 group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc));
328 }
329
addFunctionCaseWithPrograms(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,FunctionSupport0::Function checkSupport,FunctionPrograms0::Function initPrograms,FunctionInstance0::Function testFunc)330 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
331 const std::string& name,
332 const std::string& desc,
333 FunctionSupport0::Function checkSupport,
334 FunctionPrograms0::Function initPrograms,
335 FunctionInstance0::Function testFunc)
336 {
337 group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, checkSupport, initPrograms, testFunc));
338 }
339
340 template<typename Arg0>
addFunctionCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,typename FunctionInstance1<Arg0>::Function testFunc,Arg0 arg0)341 void addFunctionCase (tcu::TestCaseGroup* group,
342 const std::string& name,
343 const std::string& desc,
344 typename FunctionInstance1<Arg0>::Function testFunc,
345 Arg0 arg0)
346 {
347 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0));
348 }
349
350 template<typename Arg0>
addFunctionCase(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,typename FunctionSupport1<Arg0>::Function checkSupport,typename FunctionInstance1<Arg0>::Function testFunc,Arg0 arg0)351 void addFunctionCase (tcu::TestCaseGroup* group,
352 const std::string& name,
353 const std::string& desc,
354 typename FunctionSupport1<Arg0>::Function checkSupport,
355 typename FunctionInstance1<Arg0>::Function testFunc,
356 Arg0 arg0)
357 {
358 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, checkSupport, testFunc, arg0));
359 }
360
361 template<typename Arg0>
addFunctionCase(tcu::TestCaseGroup * group,tcu::TestNodeType type,const std::string & name,const std::string & desc,typename FunctionInstance1<Arg0>::Function testFunc,Arg0 arg0)362 void addFunctionCase (tcu::TestCaseGroup* group,
363 tcu::TestNodeType type,
364 const std::string& name,
365 const std::string& desc,
366 typename FunctionInstance1<Arg0>::Function testFunc,
367 Arg0 arg0)
368 {
369 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), type, name, desc, testFunc, arg0));
370 }
371
372 template<typename Arg0>
addFunctionCaseWithPrograms(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,typename FunctionPrograms1<Arg0>::Function initPrograms,typename FunctionInstance1<Arg0>::Function testFunc,Arg0 arg0)373 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
374 const std::string& name,
375 const std::string& desc,
376 typename FunctionPrograms1<Arg0>::Function initPrograms,
377 typename FunctionInstance1<Arg0>::Function testFunc,
378 Arg0 arg0)
379 {
380 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0));
381 }
382
383 template<typename Arg0>
addFunctionCaseWithPrograms(tcu::TestCaseGroup * group,const std::string & name,const std::string & desc,typename FunctionSupport1<Arg0>::Function checkSupport,typename FunctionPrograms1<Arg0>::Function initPrograms,typename FunctionInstance1<Arg0>::Function testFunc,Arg0 arg0)384 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
385 const std::string& name,
386 const std::string& desc,
387 typename FunctionSupport1<Arg0>::Function checkSupport,
388 typename FunctionPrograms1<Arg0>::Function initPrograms,
389 typename FunctionInstance1<Arg0>::Function testFunc,
390 Arg0 arg0)
391 {
392 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, checkSupport, initPrograms, testFunc, arg0));
393 }
394
395 template<typename Arg0>
addFunctionCaseWithPrograms(tcu::TestCaseGroup * group,tcu::TestNodeType type,const std::string & name,const std::string & desc,typename FunctionPrograms1<Arg0>::Function initPrograms,typename FunctionInstance1<Arg0>::Function testFunc,Arg0 arg0)396 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group,
397 tcu::TestNodeType type,
398 const std::string& name,
399 const std::string& desc,
400 typename FunctionPrograms1<Arg0>::Function initPrograms,
401 typename FunctionInstance1<Arg0>::Function testFunc,
402 Arg0 arg0)
403 {
404 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0));
405 }
406
407 } // vkt
408
409 #endif // _VKTTESTCASEUTIL_HPP
410