Treat DynamicLibrary library list as alternatives
authorRicardo Garcia <rgarcia@igalia.com>
Mon, 12 Dec 2022 09:17:21 +0000 (10:17 +0100)
committerPiotr Byszewski <piotr.byszewski@mobica.com>
Mon, 9 Jan 2023 11:16:20 +0000 (11:16 +0000)
Instead of attempting to load all libraries provided, we should only
attempt to load one of them and stop when the first one succeeds.

Affects WSI tests in DRM envs.

Specifically affects:
dEQP-VK.api.device_drm_properties.drm_files_exist

Components: Framework, Vulkan
VK-GL-CTS issue: 4171
VK-GL-CTS public issue: 303

Change-Id: Ib86d25662ce0b783b37ebacb26a6944452d22fd2

external/vulkancts/modules/vulkan/api/vktApiDeviceDrmPropertiesTests.cpp
framework/common/tcuLibDrm.cpp
framework/delibs/decpp/deDynamicLibrary.cpp

index 3222a51..77b6d65 100644 (file)
@@ -74,7 +74,7 @@ void testFilesExist (const VkPhysicalDeviceDrmPropertiesEXT& deviceDrmProperties
 #endif // DEQP_SUPPORT_DRM && !defined (CTS_USES_VULKANSC)
 
        if (!primaryFound && !renderFound) {
-               TCU_THROW(NotSupportedError, "Nether DRM primary nor render device files were found");
+               TCU_THROW(NotSupportedError, "Neither DRM primary nor render device files were found");
        }
 }
 
index d5d835e..8ea814c 100644 (file)
@@ -199,7 +199,7 @@ const char* LibDrm::libDrmFiles[] =
 {
        "libdrm.so.2",
        "libdrm.so",
-       DE_NULL
+       nullptr
 };
 
 } // tcu
index 3284f9d..894852b 100644 (file)
@@ -30,7 +30,7 @@ namespace de
 {
 
 DynamicLibrary::DynamicLibrary (const char* fileName)
-       : m_library(DE_NULL)
+       : m_library(nullptr)
 {
        m_library = deDynamicLibrary_open(fileName);
        if (!m_library)
@@ -38,13 +38,22 @@ DynamicLibrary::DynamicLibrary (const char* fileName)
 }
 
 DynamicLibrary::DynamicLibrary (const char* fileNames[])
-       : m_library(DE_NULL)
+       : m_library(nullptr)
 {
-       for (int i = 0; !m_library && fileNames[i]; i++)
+       for (size_t i = 0u; fileNames[i] != nullptr; ++i)
        {
                m_library = deDynamicLibrary_open(fileNames[i]);
-               if (!m_library)
-                       throw std::runtime_error(std::string("Failed to open dynamic library: '") + fileNames[0] + "'");
+               if (m_library)
+                       break;
+       }
+
+       if (!m_library)
+       {
+               std::string nameList;
+               for (size_t i = 0u; fileNames[i] != nullptr; ++i)
+                       nameList += (nameList.empty() ? "" : ", ") + std::string(fileNames[i]);
+               const std::string msg = "Failed to open dynamic library: tried " + nameList;
+               throw std::runtime_error(msg);
        }
 }