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,
65 deviceDrmProperties.primaryMajor,
66 deviceDrmProperties.primaryMinor))
67 primaryFound = true;
68 if (libDrm.findDeviceNode(drmDevices, numDrmDevices,
69 deviceDrmProperties.renderMajor,
70 deviceDrmProperties.renderMinor))
71 renderFound = true;
72
73 libDrm.freeDevices(drmDevices, numDrmDevices);
74 #endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
75
76 if (!primaryFound && !renderFound) {
77 TCU_THROW(NotSupportedError, "Neither DRM primary nor render device files were found");
78 }
79 }
80
testDeviceDrmProperties(Context & context,const TestType testType)81 static tcu::TestStatus testDeviceDrmProperties (Context& context, const TestType testType)
82 {
83
84 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
85 VkPhysicalDeviceProperties2 deviceProperties2;
86 const int memsetPattern = 0xaa;
87 VkPhysicalDeviceDrmPropertiesEXT deviceDrmProperties;
88
89 deMemset(&deviceDrmProperties, 0, sizeof(deviceDrmProperties));
90 deviceDrmProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;
91 deviceDrmProperties.pNext = DE_NULL;
92
93 deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
94 deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
95 deviceProperties2.pNext = &deviceDrmProperties;
96
97 context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
98
99 switch (testType)
100 {
101 case TEST_FILES_EXIST: testFilesExist (deviceDrmProperties); break;
102 default: TCU_THROW(InternalError, "Unknown test type specified");
103 }
104
105 return tcu::TestStatus::pass("Pass");
106 }
107
createTestCases(tcu::TestCaseGroup * group)108 static void createTestCases (tcu::TestCaseGroup* group)
109 {
110 addFunctionCase(group, "drm_files_exist", "Verify device files for major/minor nodes exist", checkSupport, testDeviceDrmProperties, TEST_FILES_EXIST);
111 }
112
113 } // anonymous
114
createDeviceDrmPropertiesTests(tcu::TestContext & testCtx)115 tcu::TestCaseGroup* createDeviceDrmPropertiesTests(tcu::TestContext& testCtx)
116 {
117 return createTestGroup(testCtx, "device_drm_properties", "VK_EXT_device_drm_properties tests", createTestCases);
118 }
119
120 } // api
121 } // vkt
122