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