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 { 35 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: 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 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 54 void initPrograms (vk::SourceCollections& dst) const { m_progs.init(dst, m_arg0); } 55 TestInstance* createInstance (Context& context) const { return new Instance(context, m_arg0); } 56 57 private: 58 const Programs m_progs; 59 const Arg0 m_arg0; 60 }; 61 62 class FunctionInstance0 : public TestInstance 63 { 64 public: 65 typedef tcu::TestStatus (*Function) (Context& context); 66 67 FunctionInstance0 (Context& context, Function function) 68 : TestInstance (context) 69 , m_function (function) 70 {} 71 72 tcu::TestStatus iterate (void) { return m_function(m_context); } 73 74 private: 75 const Function m_function; 76 }; 77 78 template<typename Arg0> 79 class FunctionInstance1 : public TestInstance 80 { 81 public: 82 typedef tcu::TestStatus (*Function) (Context& context, Arg0 arg0); 83 84 struct Args 85 { 86 Args (Function func_, Arg0 arg0_) : func(func_), arg0(arg0_) {} 87 88 Function func; 89 Arg0 arg0; 90 }; 91 92 FunctionInstance1 (Context& context, const Args& args) 93 : TestInstance (context) 94 , m_args (args) 95 {} 96 97 tcu::TestStatus iterate (void) { return m_args.func(m_context, m_args.arg0); } 98 99 private: 100 const Args m_args; 101 }; 102 103 class FunctionPrograms0 104 { 105 public: 106 typedef void (*Function) (vk::SourceCollections& dst); 107 108 FunctionPrograms0 (Function func) 109 : m_func(func) 110 {} 111 112 void init (vk::SourceCollections& dst, FunctionInstance0::Function) const { m_func(dst); } 113 114 private: 115 const Function m_func; 116 }; 117 118 template<typename Arg0> 119 class FunctionPrograms1 120 { 121 public: 122 typedef void (*Function) (vk::SourceCollections& dst, Arg0 arg0); 123 124 FunctionPrograms1 (Function func) 125 : m_func(func) 126 {} 127 128 void init (vk::SourceCollections& dst, const typename FunctionInstance1<Arg0>::Args& args) const { m_func(dst, args.arg0); } 129 130 private: 131 const Function m_func; 132 }; 133 134 // createFunctionCase 135 136 inline TestCase* createFunctionCase (tcu::TestContext& testCtx, 137 tcu::TestNodeType type, 138 const std::string& name, 139 const std::string& desc, 140 FunctionInstance0::Function testFunction) 141 { 142 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function>(testCtx, type, name, desc, testFunction); 143 } 144 145 inline TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx, 146 tcu::TestNodeType type, 147 const std::string& name, 148 const std::string& desc, 149 FunctionPrograms0::Function initPrograms, 150 FunctionInstance0::Function testFunction) 151 { 152 return new InstanceFactory1<FunctionInstance0, FunctionInstance0::Function, FunctionPrograms0>( 153 testCtx, type, name, desc, FunctionPrograms0(initPrograms), testFunction); 154 } 155 156 template<typename Arg0> 157 TestCase* createFunctionCase (tcu::TestContext& testCtx, 158 tcu::TestNodeType type, 159 const std::string& name, 160 const std::string& desc, 161 typename FunctionInstance1<Arg0>::Function testFunction, 162 Arg0 arg0) 163 { 164 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args>( 165 testCtx, type, name, desc, typename FunctionInstance1<Arg0>::Args(testFunction, arg0)); 166 } 167 168 template<typename Arg0> 169 TestCase* createFunctionCaseWithPrograms (tcu::TestContext& testCtx, 170 tcu::TestNodeType type, 171 const std::string& name, 172 const std::string& desc, 173 typename FunctionPrograms1<Arg0>::Function initPrograms, 174 typename FunctionInstance1<Arg0>::Function testFunction, 175 Arg0 arg0) 176 { 177 return new InstanceFactory1<FunctionInstance1<Arg0>, typename FunctionInstance1<Arg0>::Args, FunctionPrograms1<Arg0> >( 178 testCtx, type, name, desc, FunctionPrograms1<Arg0>(initPrograms), typename FunctionInstance1<Arg0>::Args(testFunction, arg0)); 179 } 180 181 // addFunctionCase 182 183 inline void addFunctionCase (tcu::TestCaseGroup* group, 184 const std::string& name, 185 const std::string& desc, 186 FunctionInstance0::Function testFunc) 187 { 188 group->addChild(createFunctionCase(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc)); 189 } 190 191 inline void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group, 192 const std::string& name, 193 const std::string& desc, 194 FunctionPrograms0::Function initPrograms, 195 FunctionInstance0::Function testFunc) 196 { 197 group->addChild(createFunctionCaseWithPrograms(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc)); 198 } 199 200 template<typename Arg0> 201 void addFunctionCase (tcu::TestCaseGroup* group, 202 const std::string& name, 203 const std::string& desc, 204 typename FunctionInstance1<Arg0>::Function testFunc, 205 Arg0 arg0) 206 { 207 group->addChild(createFunctionCase<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, testFunc, arg0)); 208 } 209 210 template<typename Arg0> 211 void addFunctionCase (tcu::TestCaseGroup* group, 212 tcu::TestNodeType type, 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(), type, name, desc, testFunc, arg0)); 219 } 220 221 template<typename Arg0> 222 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group, 223 const std::string& name, 224 const std::string& desc, 225 typename FunctionPrograms1<Arg0>::Function initPrograms, 226 typename FunctionInstance1<Arg0>::Function testFunc, 227 Arg0 arg0) 228 { 229 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), tcu::NODETYPE_SELF_VALIDATE, name, desc, initPrograms, testFunc, arg0)); 230 } 231 232 template<typename Arg0> 233 void addFunctionCaseWithPrograms (tcu::TestCaseGroup* group, 234 tcu::TestNodeType type, 235 const std::string& name, 236 const std::string& desc, 237 typename FunctionPrograms1<Arg0>::Function initPrograms, 238 typename FunctionInstance1<Arg0>::Function testFunc, 239 Arg0 arg0) 240 { 241 group->addChild(createFunctionCaseWithPrograms<Arg0>(group->getTestContext(), type, name, desc, initPrograms, testFunc, arg0)); 242 } 243 244 } // vkt 245 246 #endif // _VKTTESTCASEUTIL_HPP 247