1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2021 NVIDIA, Inc.
6 * Copyright (c) 2021 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_device_drm_properties tests
23 *//*--------------------------------------------------------------------*/
24
25 #include "vktApiDeviceDrmPropertiesTests.hpp"
26 #include "vktTestGroupUtil.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "deFilePath.hpp"
29 #include "deDirectoryIterator.hpp"
30 #include "deDynamicLibrary.hpp"
31 #include "tcuLibDrm.hpp"
32
33 using namespace vk;
34
35 namespace vkt
36 {
37 namespace api
38 {
39 namespace
40 {
41
42 enum TestType
43 {
44 TEST_FILES_EXIST = 0,
45 };
46
checkSupport(Context & context,const TestType config)47 void checkSupport(Context &context, const TestType config)
48 {
49 DE_UNREF(config);
50 context.requireDeviceFunctionality("VK_EXT_physical_device_drm");
51 }
52
testFilesExist(const VkPhysicalDeviceDrmPropertiesEXT & deviceDrmProperties)53 void testFilesExist(const VkPhysicalDeviceDrmPropertiesEXT &deviceDrmProperties)
54 {
55 bool primaryFound = !deviceDrmProperties.hasPrimary;
56 bool renderFound = !deviceDrmProperties.hasRender;
57
58 #if DEQP_SUPPORT_DRM && !defined(CTS_USES_VULKANSC)
59 static const tcu::LibDrm libDrm;
60
61 int numDrmDevices;
62 drmDevicePtr *drmDevices = libDrm.getDevices(&numDrmDevices);
63
64 if (libDrm.findDeviceNode(drmDevices, numDrmDevices, deviceDrmProperties.primaryMajor,
65 deviceDrmProperties.primaryMinor))
66 primaryFound = true;
67 if (libDrm.findDeviceNode(drmDevices, numDrmDevices, deviceDrmProperties.renderMajor,
68 deviceDrmProperties.renderMinor))
69 renderFound = true;
70
71 libDrm.freeDevices(drmDevices, numDrmDevices);
72 #endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
73
74 if (!primaryFound && !renderFound)
75 {
76 TCU_THROW(NotSupportedError, "Neither DRM primary nor render device files were found");
77 }
78 }
79
testDeviceDrmProperties(Context & context,const TestType testType)80 static tcu::TestStatus testDeviceDrmProperties(Context &context, const TestType testType)
81 {
82
83 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
84 VkPhysicalDeviceProperties2 deviceProperties2;
85 const int memsetPattern = 0xaa;
86 VkPhysicalDeviceDrmPropertiesEXT deviceDrmProperties;
87
88 deMemset(&deviceDrmProperties, 0, sizeof(deviceDrmProperties));
89 deviceDrmProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;
90 deviceDrmProperties.pNext = DE_NULL;
91
92 deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
93 deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
94 deviceProperties2.pNext = &deviceDrmProperties;
95
96 context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
97
98 switch (testType)
99 {
100 case TEST_FILES_EXIST:
101 testFilesExist(deviceDrmProperties);
102 break;
103 default:
104 TCU_THROW(InternalError, "Unknown test type specified");
105 }
106
107 return tcu::TestStatus::pass("Pass");
108 }
109
createTestCases(tcu::TestCaseGroup * group)110 static void createTestCases(tcu::TestCaseGroup *group)
111 {
112 // Verify device files for major/minor nodes exist
113 addFunctionCase(group, "drm_files_exist", checkSupport, testDeviceDrmProperties, TEST_FILES_EXIST);
114 }
115
116 } // namespace
117
createDeviceDrmPropertiesTests(tcu::TestContext & testCtx)118 tcu::TestCaseGroup *createDeviceDrmPropertiesTests(tcu::TestContext &testCtx)
119 {
120 return createTestGroup(testCtx, "device_drm_properties", createTestCases);
121 }
122
123 } // namespace api
124 } // namespace vkt
125