1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2018 Intel Corporation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Functional tests using vkrunner
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktVkRunnerExampleTests.hpp"
25 #include "vktVkRunnerTestCase.hpp"
26 #include "vktTestGroupUtil.hpp"
27
28 namespace vkt
29 {
30 namespace vkrunner
31 {
32 namespace
33 {
34
createVkRunnerTests(tcu::TestCaseGroup * vkRunnerTests)35 void createVkRunnerTests (tcu::TestCaseGroup* vkRunnerTests)
36 {
37 tcu::TestContext& testCtx = vkRunnerTests->getTestContext();
38
39 static const struct
40 {
41 const char *filename, *name, *description;
42 } tests[] =
43 {
44 { "spirv.shader_test", "spirv", "Example test using a SPIR-V shaders in text format" },
45 { "ubo.shader_test", "ubo", "Example test setting values in a UBO" },
46 { "vertex-data.shader_test", "vertex-data", "Example test using a vertex data section" },
47 };
48
49 for (size_t i = 0; i < sizeof tests / sizeof tests[0]; i++)
50 {
51 /* shader_test files are saved in <path>/external/vulkancts/data/vulkan/vkrunner/<categoryname>/ */
52 VkRunnerTestCase *testCase = new VkRunnerTestCase(testCtx,
53 "example",
54 tests[i].filename,
55 tests[i].name,
56 tests[i].description);
57 /* Need to call getShaders() manually to detect any issue in the
58 * shader test file, like invalid test commands or the file doesn't exist.
59 */
60 testCase->getShaders();
61 vkRunnerTests->addChild(testCase);
62 }
63
64 // Add some tests of the sqrt function using the templating mechanism
65 for (int i = 1; i <= 8; i++)
66 {
67 std::stringstream testName;
68 testName << "sqrt_" << i;
69 VkRunnerTestCase *testCase = new VkRunnerTestCase(testCtx,
70 "example",
71 "sqrt.shader_test",
72 testName.str().c_str(),
73 "Example test using the templating mechanism");
74 std::stringstream inputString;
75 inputString << (i * i);
76 std::stringstream outputString;
77 outputString << i;
78 testCase->addTokenReplacement("<INPUT>", inputString.str().c_str());
79 testCase->addTokenReplacement("<OUTPUT>", outputString.str().c_str());
80 /* Call getShaders() after doing the token
81 * replacements in the shader test. Otherwise, VkRunner will fail when found
82 * unknown commands or invalid sentences when processing the shader test file.
83 */
84 testCase->getShaders();
85 vkRunnerTests->addChild(testCase);
86 }
87 }
88
89 } // anonymous
90
createTests(tcu::TestContext & testCtx)91 tcu::TestCaseGroup* createTests (tcu::TestContext& testCtx)
92 {
93 return createTestGroup(testCtx, "vkrunner-example", "VkRunner Tests", createVkRunnerTests);
94 }
95
96 } // vkrunner
97 } // vkt
98