1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2019 Advanced Micro Devices, Inc.
6 * Copyright (c) 2019 The Khronos Group Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 *//*!
21 * \file
22 * \brief VK_EXT_tooling_info tests
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktApiToolingInfoTests.hpp"
26 #include "vktTestGroupUtil.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkStrUtil.hpp"
30 #include "vkTypeUtil.hpp"
31 #include "tcuTestLog.hpp"
32 #include <iostream>
33 #include <string>
34 #include <vector>
35
36 #include <string.h>
37
38 using namespace vk;
39
40 namespace vkt
41 {
42 namespace api
43 {
44 namespace
45 {
46
validateToolPurposeFlagBits(const VkToolPurposeFlagsEXT purposes)47 bool validateToolPurposeFlagBits(const VkToolPurposeFlagsEXT purposes)
48 {
49 const VkToolPurposeFlagsEXT validPurposes =
50 VK_TOOL_PURPOSE_VALIDATION_BIT_EXT | VK_TOOL_PURPOSE_PROFILING_BIT_EXT | VK_TOOL_PURPOSE_TRACING_BIT_EXT |
51 VK_TOOL_PURPOSE_ADDITIONAL_FEATURES_BIT_EXT | VK_TOOL_PURPOSE_MODIFYING_FEATURES_BIT_EXT |
52 VK_TOOL_PURPOSE_DEBUG_REPORTING_BIT_EXT | VK_TOOL_PURPOSE_DEBUG_MARKERS_BIT_EXT;
53 return (purposes | validPurposes) == validPurposes;
54 }
55
checkSupport(Context & context)56 void checkSupport(Context &context)
57 {
58 context.requireDeviceFunctionality("VK_EXT_tooling_info");
59 }
60
validateGetter(Context & context)61 tcu::TestStatus validateGetter(Context &context)
62 {
63 tcu::TestLog &testLog = context.getTestContext().getLog();
64
65 VkResult result = VK_SUCCESS;
66 uint32_t toolCount = 0;
67
68 result = context.getInstanceInterface().getPhysicalDeviceToolProperties(context.getPhysicalDevice(), &toolCount,
69 DE_NULL);
70
71 if (result != VK_SUCCESS)
72 {
73 testLog << tcu::TestLog::Message << "getPhysicalDeviceToolPropertiesEXT wrong result code"
74 << tcu::TestLog::EndMessage;
75 return tcu::TestStatus::fail("Fail");
76 }
77
78 if (toolCount > 0)
79 {
80 uint32_t toolCountSecondCall = toolCount;
81
82 std::vector<VkPhysicalDeviceToolPropertiesEXT> deviceToolPropertiesEXTArray(toolCountSecondCall);
83
84 for (size_t toolNdx = 0; toolNdx < deviceToolPropertiesEXTArray.size(); ++toolNdx)
85 {
86 deviceToolPropertiesEXTArray[toolNdx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT;
87 }
88
89 result = context.getInstanceInterface().getPhysicalDeviceToolProperties(
90 context.getPhysicalDevice(), &toolCountSecondCall, &deviceToolPropertiesEXTArray[0]);
91
92 if (result != VK_SUCCESS)
93 {
94 testLog << tcu::TestLog::Message << "getPhysicalDeviceToolPropertiesEXT wrong result code"
95 << tcu::TestLog::EndMessage;
96 return tcu::TestStatus::fail("Fail");
97 }
98
99 if (toolCountSecondCall != toolCount)
100 {
101 testLog << tcu::TestLog::Message << "Got different tools count on the second call"
102 << tcu::TestLog::EndMessage;
103 return tcu::TestStatus::fail("Fail");
104 }
105
106 toolCountSecondCall++;
107
108 deviceToolPropertiesEXTArray.resize(toolCountSecondCall);
109
110 for (size_t toolNdx = 0; toolNdx < deviceToolPropertiesEXTArray.size(); ++toolNdx)
111 {
112 deviceToolPropertiesEXTArray[toolNdx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT;
113 }
114
115 result = context.getInstanceInterface().getPhysicalDeviceToolProperties(
116 context.getPhysicalDevice(), &toolCountSecondCall, &deviceToolPropertiesEXTArray[0]);
117
118 if (result != VK_SUCCESS)
119 {
120 testLog << tcu::TestLog::Message << "getPhysicalDeviceToolPropertiesEXT wrong result code"
121 << tcu::TestLog::EndMessage;
122 return tcu::TestStatus::fail("Fail");
123 }
124
125 if (toolCountSecondCall != toolCount)
126 {
127 testLog << tcu::TestLog::Message << "Bigger array causes an error" << tcu::TestLog::EndMessage;
128 return tcu::TestStatus::fail("Fail");
129 }
130
131 toolCountSecondCall = 0;
132
133 result = context.getInstanceInterface().getPhysicalDeviceToolProperties(
134 context.getPhysicalDevice(), &toolCountSecondCall, &deviceToolPropertiesEXTArray[0]);
135
136 if (result != VK_INCOMPLETE)
137 {
138 testLog << tcu::TestLog::Message << "getPhysicalDeviceToolPropertiesEXT wrong result code"
139 << tcu::TestLog::EndMessage;
140 return tcu::TestStatus::fail("Fail");
141 }
142
143 if (toolCountSecondCall != 0)
144 {
145 testLog << tcu::TestLog::Message << "Zero array causes an error" << tcu::TestLog::EndMessage;
146 return tcu::TestStatus::fail("Fail");
147 }
148 }
149
150 if (toolCount > 1)
151 {
152 uint32_t toolCountSecondCall = toolCount / 2;
153
154 std::vector<VkPhysicalDeviceToolPropertiesEXT> deviceToolPropertiesEXTArray(toolCountSecondCall);
155
156 for (size_t toolNdx = 0; toolNdx < deviceToolPropertiesEXTArray.size(); ++toolNdx)
157 {
158 deviceToolPropertiesEXTArray[toolNdx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT;
159 }
160
161 result = context.getInstanceInterface().getPhysicalDeviceToolProperties(
162 context.getPhysicalDevice(), &toolCountSecondCall, &deviceToolPropertiesEXTArray[0]);
163
164 if (result != VK_INCOMPLETE)
165 {
166 testLog << tcu::TestLog::Message << "getPhysicalDeviceToolPropertiesEXT wrong result code"
167 << tcu::TestLog::EndMessage;
168 return tcu::TestStatus::fail("Fail");
169 }
170
171 if (toolCountSecondCall != (toolCount / 2))
172 {
173 testLog << tcu::TestLog::Message << "Smaller array causes an error" << tcu::TestLog::EndMessage;
174 return tcu::TestStatus::fail("Fail");
175 }
176 }
177
178 return tcu::TestStatus::pass("Pass");
179 }
180
validateToolsProperties(Context & context)181 tcu::TestStatus validateToolsProperties(Context &context)
182 {
183 tcu::TestLog &testLog = context.getTestContext().getLog();
184
185 bool result = true;
186 uint32_t toolCount = 0;
187
188 VK_CHECK(context.getInstanceInterface().getPhysicalDeviceToolProperties(context.getPhysicalDevice(), &toolCount,
189 DE_NULL));
190
191 if (toolCount > 0)
192 {
193 std::vector<VkPhysicalDeviceToolPropertiesEXT> deviceToolPropertiesEXTArray(toolCount);
194
195 for (size_t toolNdx = 0; toolNdx < deviceToolPropertiesEXTArray.size(); ++toolNdx)
196 {
197 deviceToolPropertiesEXTArray[toolNdx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT;
198 }
199
200 VK_CHECK(context.getInstanceInterface().getPhysicalDeviceToolProperties(context.getPhysicalDevice(), &toolCount,
201 &deviceToolPropertiesEXTArray[0]));
202
203 for (uint32_t i = 0; i < toolCount; ++i)
204 {
205 size_t nameSize = strnlen(deviceToolPropertiesEXTArray[i].name, VK_MAX_EXTENSION_NAME_SIZE);
206 size_t versionSize = strnlen(deviceToolPropertiesEXTArray[i].version, VK_MAX_EXTENSION_NAME_SIZE);
207 size_t descSize = strnlen(deviceToolPropertiesEXTArray[i].description, VK_MAX_DESCRIPTION_SIZE);
208 size_t layerSize = strnlen(deviceToolPropertiesEXTArray[i].layer, VK_MAX_EXTENSION_NAME_SIZE);
209
210 result = result &&
211 (deviceToolPropertiesEXTArray[i].sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT);
212 result = result && validateToolPurposeFlagBits(deviceToolPropertiesEXTArray[i].purposes);
213 result = result && ((nameSize > 0) && (nameSize < VK_MAX_EXTENSION_NAME_SIZE));
214 result = result && ((versionSize > 0) && (versionSize < VK_MAX_EXTENSION_NAME_SIZE));
215 result = result && ((descSize > 0) && (descSize < VK_MAX_DESCRIPTION_SIZE));
216 result = result && ((layerSize == 0) || (layerSize < VK_MAX_EXTENSION_NAME_SIZE));
217
218 if (result == false)
219 {
220 testLog << tcu::TestLog::Message << "Tool validation failed" << tcu::TestLog::EndMessage;
221 testLog << tcu::TestLog::Message << "Tool name: " << deviceToolPropertiesEXTArray[i].name
222 << tcu::TestLog::EndMessage;
223 testLog << tcu::TestLog::Message << "Version: " << deviceToolPropertiesEXTArray[i].version
224 << tcu::TestLog::EndMessage;
225 testLog << tcu::TestLog::Message << "Description: " << deviceToolPropertiesEXTArray[i].description
226 << tcu::TestLog::EndMessage;
227 testLog << tcu::TestLog::Message
228 << "Purposes: " << getToolPurposeFlagsStr(deviceToolPropertiesEXTArray[i].purposes)
229 << tcu::TestLog::EndMessage;
230 if (layerSize > 0)
231 {
232 testLog << tcu::TestLog::Message << "Corresponding Layer: " << deviceToolPropertiesEXTArray[i].layer
233 << tcu::TestLog::EndMessage;
234 }
235 break;
236 }
237 }
238 }
239
240 if (result)
241 {
242 return tcu::TestStatus::pass("Pass");
243 }
244 else
245 {
246 return tcu::TestStatus::fail("Fail");
247 }
248 }
249
createTestCases(tcu::TestCaseGroup * group)250 void createTestCases(tcu::TestCaseGroup *group)
251 {
252 addFunctionCase(group, "validate_getter", checkSupport, validateGetter);
253 addFunctionCase(group, "validate_tools_properties", checkSupport, validateToolsProperties);
254 }
255
256 } // namespace
257
createToolingInfoTests(tcu::TestContext & testCtx)258 tcu::TestCaseGroup *createToolingInfoTests(tcu::TestContext &testCtx)
259 {
260 return createTestGroup(testCtx, "tooling_info", createTestCases);
261 }
262
263 } // namespace api
264 } // namespace vkt
265