Merge branch '259-fix-arm-gcc-issue' into 'vulkan-cts-1.0'
[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 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27  *
28  *//*!
29  * \file
30  * \brief TestCase utilities
31  *//*--------------------------------------------------------------------*/
32
33 #include "tcuDefs.hpp"
34 #include "vktTestCase.hpp"
35
36 namespace vkt
37 {
38
39 template<typename Arg0>
40 struct NoPrograms1
41 {
42         void    init    (vk::SourceCollections&, Arg0) const {}
43 };
44
45 template<typename Instance, typename Arg0, typename Programs = NoPrograms1<Arg0> >
46 class InstanceFactory1 : public TestCase
47 {
48 public:
49                                         InstanceFactory1        (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Arg0& arg0)
50                                                 : TestCase      (testCtx, type, name, desc)
51                                                 , m_progs       ()
52                                                 , m_arg0        (arg0)
53                                         {}
54
55                                         InstanceFactory1        (tcu::TestContext& testCtx, tcu::TestNodeType type, const std::string& name, const std::string& desc, const Programs& progs, const Arg0& arg0)
56                                                 : TestCase      (testCtx, type, name, desc)
57                                                 , m_progs       (progs)
58                                                 , m_arg0        (arg0)
59                                         {}
60
61         void                    initPrograms            (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); }
62         TestInstance*   createInstance          (Context& context) const { return new Instance(context, m_arg0); }
63
64 private:
65         const Programs  m_progs;
66         const Arg0              m_arg0;
67 };
68
69 class FunctionInstance0 : public TestInstance
70 {
71 public:
72         typedef tcu::TestStatus (*Function)     (Context& context);
73
74                                         FunctionInstance0       (Context& context, Function function)
75                                                 : TestInstance  (context)
76                                                 , m_function    (function)
77                                         {}
78
79         tcu::TestStatus iterate                         (void) { return m_function(m_context); }
80
81 private:
82         const Function  m_function;
83 };
84
85 template<typename Arg0>
86 class FunctionInstance1 : public TestInstance
87 {
88 public:
89         typedef tcu::TestStatus (*Function)     (Context& context, Arg0 arg0);
90
91         struct Args
92         {
93                 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {}
94
95                 Function        func;
96                 Arg0            arg0;
97         };
98
99                                         FunctionInstance1       (Context& context, const Args& args)
100                                                 : TestInstance  (context)
101                                                 , m_args                (args)
102                                         {}
103
104         tcu::TestStatus iterate                         (void) { return m_args.func(m_context, m_args.arg0); }
105
106 private:
107         const Args              m_args;
108 };
109
110 class FunctionPrograms0
111 {
112 public:
113         typedef void    (*Function)             (vk::SourceCollections& dst);
114
115                                         FunctionPrograms0       (Function func)
116                                                 : m_func(func)
117                                         {}
118
119         void                    init                    (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); }
120
121 private:
122         const Function  m_func;
123 };
124
125 template<typename Arg0>
126 class FunctionPrograms1
127 {
128 public:
129         typedef void    (*Function)             (vk::SourceCollections& dst, Arg0 arg0);
130
131                                         FunctionPrograms1       (Function func)
132                                                 : m_func(func)
133                                         {}
134
135         void                    init                    (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); }
136
137 private:
138         const Function  m_func;
139 };
140
141 // createFunctionCase
142
143 inline TestCase* createFunctionCase (tcu::TestContext&                          testCtx,
144                                                                          tcu::TestNodeType                              type,
145                                                                          const std::string&                             name,
146                                                                          const std::string&                             desc,
147                                                                          FunctionInstance0::Function    testFunction)
148 {
149         return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction);
150 }
151
152 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext&                              testCtx,
153                                                                                                  tcu::TestNodeType                              type,
154                                                                                                  const std::string&                             name,
155                                                                                                  const std::string&                             desc,
156                                                                                                  FunctionPrograms0::Function    initPrograms,
157                                                                                                  FunctionInstance0::Function    testFunction)
158 {
159         return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>(
160                 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction);
161 }
162
163 template<typename Arg0>
164 TestCase* createFunctionCase (tcu::TestContext&                                                         testCtx,
165                                                           tcu::TestNodeType                                                             type,
166                                                           const std::string&                                                    name,
167                                                           const std::string&                                                    desc,
168                                                           typename FunctionInstance1<Arg0>::Function    testFunction,
169                                                           Arg0                                                                                  arg0)
170 {
171         return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>(
172                 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
173 }
174
175 template<typename Arg0>
176 TestCase* createFunctionCaseWithPrograms (tcu::TestContext&                                                             testCtx,
177                                                                                   tcu::TestNodeType                                                             type,
178                                                                                   const std::string&                                                    name,
179                                                                                   const std::string&                                                    desc,
180                                                                                   typename FunctionPrograms1<Arg0>::Function    initPrograms,
181                                                                                   typename FunctionInstance1<Arg0>::Function    testFunction,
182                                                                                   Arg0                                                                                  arg0)
183 {
184         return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >(
185                 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0));
186 }
187
188 // addFunctionCase
189
190 inline void addFunctionCase (tcu::TestCaseGroup*                        group,
191                                                          const std::string&                             name,
192                                                          const std::string&                             desc,
193                                                          FunctionInstance0::Function    testFunc)
194 {
195         group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc));
196 }
197
198 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup*                    group,
199                                                                                  const std::string&                             name,
200                                                                                  const std::string&                             desc,
201                                                                                  FunctionPrograms0::Function    initPrograms,
202                                                                                  FunctionInstance0::Function    testFunc)
203 {
204         group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc));
205 }
206
207 template<typename Arg0>
208 void addFunctionCase (tcu::TestCaseGroup*                                                       group,
209                                           const std::string&                                                    name,
210                                           const std::string&                                                    desc,
211                                           typename FunctionInstance1<Arg0>::Function    testFunc,
212                                           Arg0                                                                                  arg0)
213 {
214         group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0));
215 }
216
217 template<typename Arg0>
218 void addFunctionCase (tcu::TestCaseGroup*                                                       group,
219                                           tcu::TestNodeType                                                             type,
220                                           const std::string&                                                    name,
221                                           const std::string&                                                    desc,
222                                           typename FunctionInstance1<Arg0>::Function    testFunc,
223                                           Arg0                                                                                  arg0)
224 {
225         group->addChild(createFunctionCase<Arg0>(group->getTestContext(), type, name, desc, testFunc, arg0));
226 }
227
228 template<typename Arg0>
229 void addFunctionCaseWithPrograms (tcu::TestCaseGroup*                                                   group,
230                                                                   const std::string&                                                    name,
231                                                                   const std::string&                                                    desc,
232                                                                   typename FunctionPrograms1<Arg0>::Function    initPrograms,
233                                                                   typename FunctionInstance1<Arg0>::Function    testFunc,
234                                                                   Arg0                                                                                  arg0)
235 {
236         group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0));
237 }
238
239 template<typename Arg0>
240 void addFunctionCaseWithPrograms (tcu::TestCaseGroup*                                                   group,
241                                                                   tcu::TestNodeType                                                             type,
242                                                                   const std::string&                                                    name,
243                                                                   const std::string&                                                    desc,
244                                                                   typename FunctionPrograms1<Arg0>::Function    initPrograms,
245                                                                   typename FunctionInstance1<Arg0>::Function    testFunc,
246                                                                   Arg0                                                                                  arg0)
247 {
248         group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0));
249 }
250
251 } // vkt
252
253 #endif // _VKTTESTCASEUTIL_HPP