Manual merge of AOSP change 197338
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / vktTestCaseUtil.hpp
1 #ifndef _VKTTESTCASEUTIL_HPP
2 #define _VKTTESTCASEUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 Google Inc.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and/or associated documentation files (the
11  * "Materials"), to deal in the Materials without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Materials, and to
14  * permit persons to whom the Materials are furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice(s) and this permission notice shall be
18  * included in all copies or substantial portions of the Materials.
19  *
20  * The Materials are Confidential Information as defined by the
21  * Khronos Membership Agreement until designated non-confidential by
22  * Khronos, at which point this condition clause shall be removed.
23  *
24  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31  *
32  *//*!
33  * \file
34  * \brief TestCase utilities
35  *//*--------------------------------------------------------------------*/
36
37 #include "tcuDefs.hpp"
38 #include "vktTestCase.hpp"
39
40 namespace vkt
41 {
42
43 template<typename Arg0>
44 struct NoPrograms1
45 {
46         void    init    (vk::SourceCollections&, Arg0) const {}
47 };
48
49 template<typename Instance, typename Arg0, typename Programs = NoPrograms1<Arg0> >
50 class InstanceFactory1 : public TestCase
51 {
52 public:
53                                         InstanceFactory1        (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0)
54                                                 : TestCase      (testCtx, type, name, desc)
55                                                 , m_progs       ()
56                                                 , m_arg0        (arg0)
57                                         {}
58
59                                         InstanceFactory1        (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0)
60                                                 : TestCase      (testCtx, type, name, desc)
61                                                 , m_progs       (progs)
62                                                 , m_arg0        (arg0)
63                                         {}
64
65         void                    initPrograms            (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
66         TestInstance*   createInstance          (Context& context) const { return new Instance(context, m_arg0); }
67
68 private:
69         const Programs  m_progs;
70         const Arg0              m_arg0;
71 };
72
73 class FunctionInstance0 : public TestInstance
74 {
75 public:
76         typedef tcu::TestStatus (*Function)     (Context& context);
77
78                                         FunctionInstance0       (Context& context, Function function)
79                                                 : TestInstance  (context)
80                                                 , m_function    (function)
81                                         {}
82
83         tcu::TestStatus iterate                         (void) { return m_function(m_context); }
84
85 private:
86         const Function  m_function;
87 };
88
89 template<typename Arg0>
90 class FunctionInstance1 : public TestInstance
91 {
92 public:
93         typedef tcu::TestStatus (*Function)     (Context& context, Arg0 arg0);
94
95         struct Args
96         {
97                 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {}
98
99                 Function        func;
100                 Arg0            arg0;
101         };
102
103                                         FunctionInstance1       (Context& context, const Args& args)
104                                                 : TestInstance  (context)
105                                                 , m_args                (args)
106                                         {}
107
108         tcu::TestStatus iterate                         (void) { return m_args.func(m_context, m_args.arg0); }
109
110 private:
111         const Args              m_args;
112 };
113
114 class FunctionPrograms0
115 {
116 public:
117         typedef void    (*Function)             (vk::SourceCollections& dst);
118
119                                         FunctionPrograms0       (Function func)
120                                                 : m_func(func)
121                                         {}
122
123         void                    init                    (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); }
124
125 private:
126         const Function  m_func;
127 };
128
129 template<typename Arg0>
130 class FunctionPrograms1
131 {
132 public:
133         typedef void    (*Function)             (vk::SourceCollections& dst, Arg0 arg0);
134
135                                         FunctionPrograms1       (Function func)
136                                                 : m_func(func)
137                                         {}
138
139         void                    init                    (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); }
140
141 private:
142         const Function  m_func;
143 };
144
145 // createFunctionCase
146
147 inline TestCase* createFunctionCase (tcu::TestContext&                          testCtx,
148                                                                          tcu::TestNodeType                              type,
149                                                                          const std::string&                             name,
150                                                                          const std::string&                             desc,
151                                                                          FunctionInstance0::Function    testFunction)
152 {
153         return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction);
154 }
155
156 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext&                              testCtx,
157                                                                                                  tcu::TestNodeType                              type,
158                                                                                                  const std::string&                             name,
159                                                                                                  const std::string&                             desc,
160                                                                                                  FunctionPrograms0::Function    initPrograms,
161                                                                                                  FunctionInstance0::Function    testFunction)
162 {
163         return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>(
164                 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction);
165 }
166
167 template<typename Arg0>
168 TestCase* createFunctionCase (tcu::TestContext&                                                         testCtx,
169                                                           tcu::TestNodeType                                                             type,
170                                                           const std::string&                                                    name,
171                                                           const std::string&                                                    desc,
172                                                           typename FunctionInstance1<Arg0>::Function    testFunction,
173                                                           Arg0                                                                                  arg0)
174 {
175         return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>(
176                 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
177 }
178
179 template<typename Arg0>
180 TestCase* createFunctionCaseWithPrograms (tcu::TestContext&                                                             testCtx,
181                                                                                   tcu::TestNodeType                                                             type,
182                                                                                   const std::string&                                                    name,
183                                                                                   const std::string&                                                    desc,
184                                                                                   typename FunctionPrograms1<Arg0>::Function    initPrograms,
185                                                                                   typename FunctionInstance1<Arg0>::Function    testFunction,
186                                                                                   Arg0                                                                                  arg0)
187 {
188         return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >(
189                 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
190 }
191
192 // addFunctionCase
193
194 inline void addFunctionCase (tcu::TestCaseGroup*                        group,
195                                                          const std::string&                             name,
196                                                          const std::string&                             desc,
197                                                          FunctionInstance0::Function    testFunc)
198 {
199         group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc));
200 }
201
202 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup*                    group,
203                                                                                  const std::string&                             name,
204                                                                                  const std::string&                             desc,
205                                                                                  FunctionPrograms0::Function    initPrograms,
206                                                                                  FunctionInstance0::Function    testFunc)
207 {
208         group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc));
209 }
210
211 template<typename Arg0>
212 void addFunctionCase (tcu::TestCaseGroup*                                                       group,
213                                           const std::string&                                                    name,
214                                           const std::string&                                                    desc,
215                                           typename FunctionInstance1<Arg0>::Function    testFunc,
216                                           Arg0                                                                                  arg0)
217 {
218         group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0));
219 }
220
221 template<typename Arg0>
222 void addFunctionCase (tcu::TestCaseGroup*                                                       group,
223                                           tcu::TestNodeType                                                             type,
224                                           const std::string&                                                    name,
225                                           const std::string&                                                    desc,
226                                           typename FunctionInstance1<Arg0>::Function    testFunc,
227                                           Arg0                                                                                  arg0)
228 {
229         group->addChild(createFunctionCase<Arg0>(group->getTestContext(), type, name, desc, testFunc, arg0));
230 }
231
232 template<typename Arg0>
233 void addFunctionCaseWithPrograms (tcu::TestCaseGroup*                                                   group,
234                                                                   const std::string&                                                    name,
235                                                                   const std::string&                                                    desc,
236                                                                   typename FunctionPrograms1<Arg0>::Function    initPrograms,
237                                                                   typename FunctionInstance1<Arg0>::Function    testFunc,
238                                                                   Arg0                                                                                  arg0)
239 {
240         group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0));
241 }
242
243 template<typename Arg0>
244 void addFunctionCaseWithPrograms (tcu::TestCaseGroup*                                                   group,
245                                                                   tcu::TestNodeType                                                             type,
246                                                                   const std::string&                                                    name,
247                                                                   const std::string&                                                    desc,
248                                                                   typename FunctionPrograms1<Arg0>::Function    initPrograms,
249                                                                   typename FunctionInstance1<Arg0>::Function    testFunc,
250                                                                   Arg0                                                                                  arg0)
251 {
252         group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0));
253 }
254
255 } // vkt
256
257 #endif // _VKTTESTCASEUTIL_HPP