Add VK_EXT_device_drm_properties tests
authorJames Jones <jajones@nvidia.com>
Fri, 8 Jan 2021 17:53:43 +0000 (09:53 -0800)
committerJames Jones <jajones@nvidia.com>
Wed, 30 Jun 2021 16:05:05 +0000 (09:05 -0700)
Verifies the basic API functionality works by
locating the device nodes associated with a Vulkan
device by matching them against the major and
minor device IDs reported by the extension.

Rather than assume the location of DRM device
nodes on the filesystem, these tests look them up
using libdrm's drmGetDevices[2]() function. This
requires some supporting code to properly load the
libraries, but should be more portable than simply
walking /dev/dri/*.

Components: Vulkan

New tests:

dEQP-VK.api.device_drm_properties.*

Change-Id: If9436e1595ad1132d5f542629c372a02fc3ed9e2

AndroidGen.mk
android/cts/master/vk-master-2021-03-01/api.txt
android/cts/master/vk-master/api.txt
external/vulkancts/framework/vulkan/vkDeviceProperties.inl
external/vulkancts/modules/vulkan/api/CMakeLists.txt
external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.cpp [new file with mode: 0644]
external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.hpp [new file with mode: 0644]
external/vulkancts/modules/vulkan/api/vktApiTests.cpp
external/vulkancts/mustpass/master/vk-default/api.txt
external/vulkancts/scripts/gen_framework.py

index 8093a06..8c548ad 100644 (file)
@@ -74,6 +74,7 @@ LOCAL_SRC_FILES := \
        external/vulkancts/modules/vulkan/api/vktApiCopiesAndBlittingTests.cpp \
        external/vulkancts/modules/vulkan/api/vktApiDescriptorPoolTests.cpp \
        external/vulkancts/modules/vulkan/api/vktApiDescriptorSetTests.cpp \
+       external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.cpp \
        external/vulkancts/modules/vulkan/api/vktApiDeviceInitializationTests.cpp \
        external/vulkancts/modules/vulkan/api/vktApiDriverPropertiesTests.cpp \
        external/vulkancts/modules/vulkan/api/vktApiExternalMemoryTests.cpp \
index 7127c1a..2c87781 100644 (file)
@@ -18,6 +18,7 @@ dEQP-VK.api.info.image_format_properties2.2d.linear.g8_b8r8_2plane_444_unorm_ext
 dEQP-VK.api.info.image_format_properties2.2d.linear.g10x6_b10x6r10x6_2plane_444_unorm_3pack16_ext
 dEQP-VK.api.info.image_format_properties2.2d.linear.g12x4_b12x4r12x4_2plane_444_unorm_3pack16_ext
 dEQP-VK.api.info.image_format_properties2.2d.linear.g16_b16r16_2plane_444_unorm_ext
+dEQP-VK.api.device_drm_properties.drm_files_exist
 dEQP-VK.api.device_init.enumerate_devices_alloc_leak
 dEQP-VK.api.device_init.create_device_global_priority
 dEQP-VK.api.device_init.create_device_global_priority_query
index f250d2b..0e7be2c 100644 (file)
@@ -3730,6 +3730,7 @@ dEQP-VK.api.info.sparse_image_format_properties2.3d.linear.astc_12x12_srgb_block
 dEQP-VK.api.info.android.mandatory_extensions
 dEQP-VK.api.info.android.no_unknown_extensions
 dEQP-VK.api.info.android.no_layers
+dEQP-VK.api.device_drm_properties.drm_files_exist
 dEQP-VK.api.device_init.create_instance_name_version
 dEQP-VK.api.device_init.create_instance_invalid_api_version
 dEQP-VK.api.device_init.create_instance_null_appinfo
index 6e14093..d1bf1f6 100644 (file)
@@ -15,7 +15,7 @@ namespace vk
 #define VK_NV_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME "VK_NV_device_generated_commands"
 #define VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME "VK_EXT_discard_rectangles"
 #define VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME "VK_KHR_driver_properties"
-#define DECL_EXT_DRM_EXTENSION_NAME "core_property"
+#define VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME "VK_EXT_physical_device_drm"
 #define VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME "VK_EXT_external_memory_host"
 #define VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME "VK_KHR_shader_float_controls"
 #define VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME "VK_EXT_fragment_density_map"
@@ -212,7 +212,7 @@ template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceDescriptorIndexingPrope
 template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceDeviceGeneratedCommandsPropertiesNV>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_PROPERTIES_NV, VK_NV_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME, VK_NV_DEVICE_GENERATED_COMMANDS_SPEC_VERSION, 39}; }
 template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceDiscardRectanglePropertiesEXT>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT, VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME, VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION, 38}; }
 template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceDriverProperties>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES, VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME, VK_KHR_DRIVER_PROPERTIES_SPEC_VERSION, 37}; }
-template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceDrmPropertiesEXT>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT, DECL_EXT_DRM_EXTENSION_NAME, 0, 36}; }
+template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceDrmPropertiesEXT>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT, VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME, VK_EXT_PHYSICAL_DEVICE_DRM_SPEC_VERSION, 36}; }
 template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceExternalMemoryHostPropertiesEXT>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT, VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, VK_EXT_EXTERNAL_MEMORY_HOST_SPEC_VERSION, 35}; }
 template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceFloatControlsProperties>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES, VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME, VK_KHR_SHADER_FLOAT_CONTROLS_SPEC_VERSION, 34}; }
 template<> PropertyDesc makePropertyDesc<VkPhysicalDeviceFragmentDensityMapPropertiesEXT>(void) { return PropertyDesc{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_PROPERTIES_EXT, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME, VK_EXT_FRAGMENT_DENSITY_MAP_SPEC_VERSION, 33}; }
@@ -262,7 +262,7 @@ static const PropertyStructCreationData propertyStructCreationArray[] =
        { createPropertyStructWrapper<VkPhysicalDeviceDeviceGeneratedCommandsPropertiesNV>, VK_NV_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME, VK_NV_DEVICE_GENERATED_COMMANDS_SPEC_VERSION },
        { createPropertyStructWrapper<VkPhysicalDeviceDiscardRectanglePropertiesEXT>, VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME, VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION },
        { createPropertyStructWrapper<VkPhysicalDeviceDriverProperties>, VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME, VK_KHR_DRIVER_PROPERTIES_SPEC_VERSION },
-       { createPropertyStructWrapper<VkPhysicalDeviceDrmPropertiesEXT>, DECL_EXT_DRM_EXTENSION_NAME, 0 },
+       { createPropertyStructWrapper<VkPhysicalDeviceDrmPropertiesEXT>, VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME, VK_EXT_PHYSICAL_DEVICE_DRM_SPEC_VERSION },
        { createPropertyStructWrapper<VkPhysicalDeviceExternalMemoryHostPropertiesEXT>, VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, VK_EXT_EXTERNAL_MEMORY_HOST_SPEC_VERSION },
        { createPropertyStructWrapper<VkPhysicalDeviceFloatControlsProperties>, VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME, VK_KHR_SHADER_FLOAT_CONTROLS_SPEC_VERSION },
        { createPropertyStructWrapper<VkPhysicalDeviceFragmentDensityMapPropertiesEXT>, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME, VK_EXT_FRAGMENT_DENSITY_MAP_SPEC_VERSION },
index 1a6b782..2827451 100644 (file)
@@ -12,6 +12,8 @@ set(DEQP_VK_API_SRCS
        vktApiTests.hpp
        vktApiSmokeTests.cpp
        vktApiSmokeTests.hpp
+       vktApiDeviceDrmPropertiesTests.cpp
+       vktApiDeviceDrmPropertiesTests.hpp
        vktApiDeviceInitializationTests.cpp
        vktApiDeviceInitializationTests.hpp
        vktApiDriverPropertiesTests.cpp
diff --git a/external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.cpp
new file mode 100644 (file)
index 0000000..882d11d
--- /dev/null
@@ -0,0 +1,223 @@
+/*-------------------------------------------------------------------------
+* Vulkan Conformance Tests
+* ------------------------
+*
+* Copyright (c) 2021 NVIDIA, Inc.
+* Copyright (c) 2021 The Khronos Group Inc.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*//*!
+* \file
+* \brief VK_EXT_device_drm_properties tests
+*//*--------------------------------------------------------------------*/
+
+#include "vktApiDeviceDrmPropertiesTests.hpp"
+#include "vktTestGroupUtil.hpp"
+#include "vktTestCaseUtil.hpp"
+#include "deFilePath.hpp"
+#include "deDirectoryIterator.hpp"
+#include "deDynamicLibrary.hpp"
+#if DEQP_SUPPORT_DRM
+#include <sys/sysmacros.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <xf86drm.h>
+#endif
+
+using namespace vk;
+
+namespace vkt
+{
+namespace api
+{
+namespace
+{
+
+enum TestType
+{
+       TEST_FILES_EXIST                        = 0,
+};
+
+void checkSupport (Context& context, const TestType config)
+{
+       DE_UNREF(config);
+       context.requireDeviceFunctionality("VK_EXT_physical_device_drm");
+}
+
+#if DEQP_SUPPORT_DRM
+class LibDrm : protected de::DynamicLibrary
+{
+       static const char* libDrmFiles[];
+
+       typedef int (*PFNDRMGETDEVICES2PROC)(deUint32, drmDevicePtr[], int);
+       typedef int (*PFNDRMGETDEVICESPROC)(drmDevicePtr[], int);
+       typedef void (*PFNDRMFREEDEVICESPROC)(drmDevicePtr[], int);
+       PFNDRMGETDEVICES2PROC pGetDevices2;
+       PFNDRMGETDEVICESPROC pGetDevices;
+       PFNDRMFREEDEVICESPROC pFreeDevices;
+
+       int intGetDevices(drmDevicePtr devices[], int maxDevices) const
+    {
+               if (pGetDevices2)
+                       return pGetDevices2(0, devices, maxDevices);
+               else
+                       return pGetDevices(devices, maxDevices);
+       }
+
+public:
+       LibDrm() : DynamicLibrary(libDrmFiles) {
+               pGetDevices2 = (PFNDRMGETDEVICES2PROC)getFunction("drmGetDevices2");
+               pGetDevices = (PFNDRMGETDEVICESPROC)getFunction("drmGetDevices");
+               pFreeDevices = (PFNDRMFREEDEVICESPROC)getFunction("drmFreeDevices");
+
+               if (!pGetDevices2 && !pGetDevices)
+                       TCU_FAIL("Could not load a valid drmGetDevices() variant from libdrm");
+
+               if (!pFreeDevices)
+                       TCU_FAIL("Could not load drmFreeDevices() from libdrm");
+       }
+
+       drmDevicePtr *getDevices(int *pNumDevices) const
+       {
+               *pNumDevices = intGetDevices(DE_NULL, 0);
+
+               if (*pNumDevices < 0)
+                       TCU_FAIL("Failed to query number of DRM devices in system");
+
+               if (*pNumDevices == 0)
+                       return DE_NULL;
+
+               drmDevicePtr *devs = new drmDevicePtr[*pNumDevices];
+
+               *pNumDevices = intGetDevices(devs, *pNumDevices);
+
+               if (*pNumDevices < 0)
+        {
+                       delete[] devs;
+                       TCU_FAIL("Failed to query list of DRM devices in system");
+               }
+
+               return devs;
+       }
+
+       void freeDevices(drmDevicePtr *devices, int count) const
+    {
+               pFreeDevices(devices, count);
+               delete[] devices;
+       }
+
+       ~LibDrm() { }
+};
+
+const char* LibDrm::libDrmFiles[] =
+{
+       "libdrm.so.2",
+       "libdrm.so",
+       DE_NULL
+};
+#endif // DEQP_SUPPORT_DRM
+
+void testFilesExist (const VkPhysicalDeviceDrmPropertiesEXT& deviceDrmProperties)
+{
+       bool primaryFound = !deviceDrmProperties.hasPrimary;
+       bool renderFound = !deviceDrmProperties.hasRender;
+
+#if DEQP_SUPPORT_DRM
+       static const LibDrm libDrm;
+
+       int numDrmDevices;
+       drmDevicePtr* drmDevices = libDrm.getDevices(&numDrmDevices);
+
+       for (int i = 0; i < numDrmDevices; i++)
+    {
+               for (int j = 0; j < DRM_NODE_MAX; j++)
+        {
+                       if (!(drmDevices[i]->available_nodes & (1 << j)))
+                               continue;
+
+                       struct stat statBuf;
+                       deMemset(&statBuf, 0, sizeof(statBuf));
+                       int res = stat(drmDevices[i]->nodes[j], &statBuf);
+
+                       if (res || !(statBuf.st_mode & S_IFCHR))
+                continue;
+
+                       if (deviceDrmProperties.primaryMajor == major(statBuf.st_rdev) &&
+                               deviceDrmProperties.primaryMinor == minor(statBuf.st_rdev))
+            {
+                               primaryFound = true;
+                               continue;
+                       }
+
+                       if (deviceDrmProperties.renderMajor == major(statBuf.st_rdev) &&
+                               deviceDrmProperties.renderMinor == minor(statBuf.st_rdev))
+            {
+                               renderFound = true;
+                               continue;
+                       }
+               }
+       }
+
+       libDrm.freeDevices(drmDevices, numDrmDevices);
+#endif // DEQP_SUPPORT_DRM
+
+       if (!primaryFound)
+               TCU_FAIL("DRM primary device file not found");
+
+       if (!renderFound)
+               TCU_FAIL("DRM render device file not found");
+}
+
+static tcu::TestStatus testDeviceDrmProperties (Context& context, const TestType testType)
+{
+
+       const VkPhysicalDevice                          physDevice                      = context.getPhysicalDevice();
+       VkPhysicalDeviceProperties2                     deviceProperties2;
+       const int                                                       memsetPattern           = 0xaa;
+       VkPhysicalDeviceDrmPropertiesEXT        deviceDrmProperties;
+
+       deMemset(&deviceDrmProperties, 0, sizeof(deviceDrmProperties));
+       deviceDrmProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;
+       deviceDrmProperties.pNext = DE_NULL;
+
+       deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
+       deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
+       deviceProperties2.pNext = &deviceDrmProperties;
+
+       context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
+
+       switch (testType)
+       {
+               case TEST_FILES_EXIST:                  testFilesExist          (deviceDrmProperties);                                  break;
+               default:                                                TCU_THROW(InternalError, "Unknown test type specified");
+       }
+
+       return tcu::TestStatus::pass("Pass");
+}
+
+static void createTestCases (tcu::TestCaseGroup* group)
+{
+       addFunctionCase(group, "drm_files_exist",               "Verify device files for major/minor nodes exist",              checkSupport,   testDeviceDrmProperties,        TEST_FILES_EXIST);
+}
+
+} // anonymous
+
+tcu::TestCaseGroup*    createDeviceDrmPropertiesTests(tcu::TestContext& testCtx)
+{
+       return createTestGroup(testCtx, "device_drm_properties", "VK_EXT_device_drm_properties tests", createTestCases);
+}
+
+} // api
+} // vkt
diff --git a/external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.hpp b/external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.hpp
new file mode 100644 (file)
index 0000000..a824f5f
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef _VKTAPIDEVICEDRMPROPERTIESTESTS_HPP
+#define _VKTAPIDEVICEDRMPROPERTIESTESTS_HPP
+/*-------------------------------------------------------------------------
+ * Vulkan Conformance Tests
+ * ------------------------
+ *
+ * Copyright (c) 2021 NVIDIA, Inc.
+ * Copyright (c) 2021 The Khronos Group Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *//*!
+ * \file
+ * \brief VK_KHR_driver_properties tests
+ *//*--------------------------------------------------------------------*/
+
+#include "tcuDefs.hpp"
+#include "tcuTestCase.hpp"
+
+namespace vkt
+{
+namespace api
+{
+
+tcu::TestCaseGroup*    createDeviceDrmPropertiesTests  (tcu::TestContext& testCtx);
+
+} // api
+} // vkt
+
+#endif // _VKTAPIDEVICEDRMPROPERTIESTESTS_HPP
index 41abc7d..185169e 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "vktTestGroupUtil.hpp"
 #include "vktApiSmokeTests.hpp"
+#include "vktApiDeviceDrmPropertiesTests.hpp"
 #include "vktApiDeviceInitializationTests.hpp"
 #include "vktApiDriverPropertiesTests.hpp"
 #include "vktApiObjectManagementTests.hpp"
@@ -73,6 +74,7 @@ void createApiTests (tcu::TestCaseGroup* apiTests)
        apiTests->addChild(createDriverPropertiesTests                          (testCtx));
        apiTests->addChild(createSmokeTests                                                     (testCtx));
        apiTests->addChild(api::createFeatureInfoTests                          (testCtx));
+       apiTests->addChild(createDeviceDrmPropertiesTests                       (testCtx));
        apiTests->addChild(createDeviceInitializationTests                      (testCtx));
        apiTests->addChild(createObjectManagementTests                          (testCtx));
        apiTests->addChild(createBufferTests                                            (testCtx));
index 956779a..5cf27d5 100644 (file)
@@ -3728,6 +3728,7 @@ dEQP-VK.api.info.sparse_image_format_properties2.3d.linear.astc_12x10_unorm_bloc
 dEQP-VK.api.info.sparse_image_format_properties2.3d.linear.astc_12x10_srgb_block
 dEQP-VK.api.info.sparse_image_format_properties2.3d.linear.astc_12x12_unorm_block
 dEQP-VK.api.info.sparse_image_format_properties2.3d.linear.astc_12x12_srgb_block
+dEQP-VK.api.device_drm_properties.drm_files_exist
 dEQP-VK.api.device_init.create_instance_name_version
 dEQP-VK.api.device_init.create_instance_invalid_api_version
 dEQP-VK.api.device_init.create_instance_null_appinfo
index eef8519..edb15c6 100755 (executable)
@@ -1938,6 +1938,8 @@ def generateDevicePropertiesDefs(src):
                                extType = "MAINTENANCE2"
                        elif extType == "SHADER_CORE":
                                extType = "SHADER_CORE_PROPERTIES"
+                       elif extType == "DRM":
+                               extType = "PHYSICAL_DEVICE_DRM"
                        # end handling special cases
                        ptrnExtensionName       = r'^\s*#define\s+(\w+' + sExtSuffix + '_' + extType + sVerSuffix +'[_0-9]*_EXTENSION_NAME).+$'
                        matchExtensionName      = re.search(ptrnExtensionName, src, re.M)