Whitelist Vulkan CTS 1.1.3.1
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiDriverPropertiesTests.cpp
1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2018 Advanced Micro Devices, Inc.
6 * Copyright (c) 2018 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_KHR_driver_properties tests
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktApiDriverPropertiesTests.hpp"
26 #include "vktTestGroupUtil.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkTypeUtil.hpp"
30
31 using namespace vk;
32
33 namespace vkt
34 {
35 namespace api
36 {
37 namespace
38 {
39
40 static const deUint32 knownDriverIds[] =
41 {
42         // Specified in the Vulkan registry (vk.xml)
43         1,      // author = "Advanced Micro Devices, Inc."   comment = "AMD proprietary driver"
44         2,      // author = "Advanced Micro Devices, Inc."   comment = "AMD open-source driver"
45         3,      // author = "Mesa open source project"       comment = "Mesa RADV driver"
46         4,      // author = "NVIDIA Corporation"             comment = "NVIDIA proprietary driver"
47         5,      // author = "Intel Corporation"              comment = "Intel proprietary Windows driver"
48         6,      // author = "Intel Corporation"              comment = "Intel open-source Mesa driver"
49         7,      // author = "Imagination Technologies"       comment = "Imagination proprietary driver"
50         8,      // author = "Qualcomm Technologies, Inc."    comment = "Qualcomm proprietary driver"
51         9,      // author = "Arm Limited"                    comment = "Arm proprietary driver"
52 };
53
54 static const VkConformanceVersionKHR knownConformanceVersions[] =
55 {
56         makeConformanceVersionKHR(1, 1, 3, 1),
57         makeConformanceVersionKHR(1, 1, 3, 0),
58         makeConformanceVersionKHR(1, 1, 2, 3),
59         makeConformanceVersionKHR(1, 1, 2, 2),
60         makeConformanceVersionKHR(1, 1, 2, 1),
61         makeConformanceVersionKHR(1, 1, 2, 0),
62         makeConformanceVersionKHR(1, 1, 1, 3),
63         makeConformanceVersionKHR(1, 1, 1, 2),
64         makeConformanceVersionKHR(1, 1, 1, 1),
65         makeConformanceVersionKHR(1, 1, 1, 0),
66         makeConformanceVersionKHR(1, 1, 0, 3),
67         makeConformanceVersionKHR(1, 0, 2, 6),
68         makeConformanceVersionKHR(1, 0, 2, 5),
69         makeConformanceVersionKHR(1, 0, 2, 4),
70         makeConformanceVersionKHR(1, 0, 2, 3),
71         makeConformanceVersionKHR(1, 0, 2, 2),
72         makeConformanceVersionKHR(1, 0, 2, 1),
73         makeConformanceVersionKHR(1, 0, 2, 0),
74 };
75
76 DE_INLINE bool isNullTerminated(const char* str, const deUint32 maxSize)
77 {
78         return deStrnlen(str, maxSize) < maxSize;
79 }
80
81 DE_INLINE bool operator==(const VkConformanceVersionKHR& a, const VkConformanceVersionKHR& b)
82 {
83         return ((a.major == b.major)            &&
84                         (a.minor == b.minor)            &&
85                         (a.subminor == b.subminor)      &&
86                         (a.patch == b.patch));
87 }
88
89 tcu::TestStatus testQueryProperties (Context& context)
90 {
91         // Check extension support
92
93         if (!isDeviceExtensionSupported(context.getUsedApiVersion(), context.getDeviceExtensions(), "VK_KHR_driver_properties"))
94                 TCU_THROW(NotSupportedError, "Unsupported extension: VK_KHR_driver_properties");
95
96         // Query the driver properties
97
98         const VkPhysicalDevice                          physDevice                      = context.getPhysicalDevice();
99         const int                                                       memsetPattern           = 0xaa;
100         VkPhysicalDeviceProperties2                     deviceProperties2;
101         VkPhysicalDeviceDriverPropertiesKHR     deviceDriverProperties;
102
103         deMemset(&deviceDriverProperties, memsetPattern, sizeof(deviceDriverProperties));
104         deviceDriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
105         deviceDriverProperties.pNext = DE_NULL;
106
107         deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
108         deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
109         deviceProperties2.pNext = &deviceDriverProperties;
110
111         context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
112
113         // Verify the returned values
114
115         bool match = false;
116
117         for (const deUint32* pDriverId = knownDriverIds; (pDriverId != DE_ARRAY_END(knownDriverIds)) && !match; ++pDriverId)
118         {
119                 if (deviceDriverProperties.driverID == *pDriverId)
120                 {
121                         match = true;
122
123                         if (!isNullTerminated(deviceDriverProperties.driverName, VK_MAX_DRIVER_NAME_SIZE_KHR))
124                                 TCU_FAIL("Driver name is not a null-terminated string");
125
126                         if (deviceDriverProperties.driverName[0] == 0)
127                                 TCU_FAIL("Driver name is empty");
128
129                         if (!isNullTerminated(deviceDriverProperties.driverInfo, VK_MAX_DRIVER_INFO_SIZE_KHR))
130                                 TCU_FAIL("Driver info is not a null-terminated string");
131
132                         bool conformanceVersionMatch = false;
133
134                         for (const VkConformanceVersionKHR* pConformanceVersion  = knownConformanceVersions;
135                                                                                                 pConformanceVersion != DE_ARRAY_END(knownConformanceVersions);
136                                                                                           ++pConformanceVersion)
137                         {
138                                 if (deviceDriverProperties.conformanceVersion == *pConformanceVersion)
139                                 {
140                                         conformanceVersionMatch = true;
141                                         break;
142                                 }
143                         }
144
145                         if (!conformanceVersionMatch)
146                                 TCU_FAIL("Wrong driver conformance version");
147                 }
148         }
149
150         if (!match)
151                 TCU_FAIL("Driver ID did not match any known driver");
152
153         return tcu::TestStatus::pass("Pass");
154 }
155
156 void createTestCases (tcu::TestCaseGroup* group)
157 {
158         addFunctionCase(group, "properties", "Query VkPhysicalDeviceDriverPropertiesKHR and check its values", testQueryProperties);
159 }
160
161 } // anonymous
162
163 tcu::TestCaseGroup*     createDriverPropertiesTests(tcu::TestContext& testCtx)
164 {
165         return createTestGroup(testCtx, "driver_properties", "VK_KHR_driver_properties tests", createTestCases);
166 }
167
168 } // api
169 } // vkt