diff --git a/shared/source/os_interface/linux/pci_path.cpp b/shared/source/os_interface/linux/pci_path.cpp index 7247c71cc5..365cfd5777 100644 --- a/shared/source/os_interface/linux/pci_path.cpp +++ b/shared/source/os_interface/linux/pci_path.cpp @@ -48,6 +48,10 @@ std::optional getPciPath(int deviceFd) { auto pciPathPos = deviceLinkPath->find("/drm/render"); + if (pciPathPos == std::string::npos) { + pciPathPos = deviceLinkPath->find("/drm/card"); + } + if (pciPathPos == std::string::npos || pciPathPos < 12) { return std::nullopt; } diff --git a/shared/test/unit_test/os_interface/linux/pci_path_tests.cpp b/shared/test/unit_test/os_interface/linux/pci_path_tests.cpp index cd3bab749f..98fbf352e9 100644 --- a/shared/test/unit_test/os_interface/linux/pci_path_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/pci_path_tests.cpp @@ -81,3 +81,39 @@ TEST(DrmTest, whenGettingPciPathThenProperPathIsReturned) { EXPECT_TRUE(pciPath.has_value()); EXPECT_EQ(outPciPath, *pciPath); } + +TEST(DrmTest, whenGettingPciPathContainsCard0ThenProperPathIsReturned) { + static const int fileDescriptorCard = 0x127; + + static const char devicePathCard[] = "devicePathCard"; + + static const char linkPathCard[] = "../../devices/pci0000:4a/0000:4b:00.0/0000:4c:01.0/0001:02:03.4/drm/card0"; + + static const char outPciPath[] = "0001:02:03.4"; + + VariableBackup allowFakeDevicePathBackup{&SysCalls::allowFakeDevicePath, true}; + VariableBackup getDevicePathBackup(&SysCalls::sysCallsGetDevicePath); + VariableBackup readlinkBackup(&SysCalls::sysCallsReadlink); + + SysCalls::sysCallsGetDevicePath = [](int deviceFd, char *buf, size_t &bufSize) -> int { + if (deviceFd == fileDescriptorCard) { + bufSize = sizeof(devicePathCard); + strcpy_s(buf, bufSize, devicePathCard); + return 0; + } + return -1; + }; + + SysCalls::sysCallsReadlink = [](const char *path, char *buf, size_t bufSize) -> int { + if (strcmp(path, devicePathCard) == 0) { + bufSize = sizeof(linkPathCard); + strcpy_s(buf, bufSize, linkPathCard); + return static_cast(bufSize); + } + return -1; + }; + + auto pciPath = getPciPath(fileDescriptorCard); + EXPECT_TRUE(pciPath.has_value()); + EXPECT_EQ(outPciPath, *pciPath); +}