mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
improve pci path search to use regex to make it more flexible
Related-To: NEO-6364 Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
c3e5e4d3cc
commit
83b099a48c
@ -124,7 +124,7 @@ TEST_F(DrmSimpleTests, GivenSelectedNotExistingDeviceWhenGetDeviceFdThenFail) {
|
||||
|
||||
TEST_F(DrmSimpleTests, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) {
|
||||
DebugManagerStateRestore stateRestore;
|
||||
DebugManager.flags.ForceDeviceId.set("1234");
|
||||
DebugManager.flags.ForceDeviceId.set("0000:00:02.0");
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
openRetVal = 1023; // fakeFd
|
||||
openFull = testOpen;
|
||||
@ -147,16 +147,16 @@ TEST_F(DrmSimpleTests, GivenSelectedExistingDeviceWhenOpenDirSuccedsThenHwDevice
|
||||
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
||||
EXPECT_EQ(1u, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("0000:test1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_STREQ("0000:00:03.1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
|
||||
entryIndex = 0;
|
||||
openCounter = 2;
|
||||
hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
||||
EXPECT_EQ(2u, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("0000:test1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_STREQ("0000:00:03.1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
||||
EXPECT_STREQ("0000:test2", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_STREQ("0000:00:02.0", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
}
|
||||
|
||||
TEST_F(DrmSimpleTests, GivenSelectedExistingDeviceWhenOpenDirFailsThenRetryOpeningRenderDevices) {
|
||||
@ -368,12 +368,12 @@ TEST_F(DrmSimpleTests, GivenMultipleAvailableDevicesWhenCreateMultipleRootDevice
|
||||
|
||||
openCounter = 4;
|
||||
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
||||
EXPECT_STREQ("/dev/dri/by-path/pci-0000:test2-render", lastOpenedPath.c_str());
|
||||
EXPECT_STREQ("/dev/dri/by-path/platform-4010000000.pcie-pci-0000:00:02.0-render", lastOpenedPath.c_str());
|
||||
EXPECT_EQ(requestedNumRootDevices, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("0000:test1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_STREQ("0000:00:03.1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
||||
EXPECT_STREQ("0000:test2", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
EXPECT_STREQ("0000:00:02.0", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
|
||||
}
|
||||
|
||||
TEST_F(DrmSimpleTests, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) {
|
||||
@ -805,48 +805,46 @@ TEST(PlatformsDestructor, whenGlobalPlatformsDestructorIsCalledThenGlobalPlatfor
|
||||
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, givenInvalidPciPathThenPciBusInfoIsNotAvailable) {
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, false);
|
||||
VariableBackup<decltype(entryIndex)> backupEntryIndex(&entryIndex, 0u);
|
||||
|
||||
openFull = openWithCounter;
|
||||
entryIndex = 1;
|
||||
openCounter = 1;
|
||||
|
||||
const uint32_t invVal = PhysicalDevicePciBusInfo::InvalidValue;
|
||||
|
||||
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
||||
ASSERT_NE(drm, nullptr);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDomain, invVal);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciBus, invVal);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDevice, invVal);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciFunction, invVal);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, givenValidPciPathThenPciBusInfoIsAvailable) {
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, false);
|
||||
VariableBackup<decltype(entryIndex)> backupEntryIndex(&entryIndex, 0u);
|
||||
|
||||
openFull = openWithCounter;
|
||||
entryIndex = 4;
|
||||
entryIndex = 1;
|
||||
openCounter = 2;
|
||||
|
||||
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
||||
ASSERT_NE(drm, nullptr);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDomain, 0u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciBus, 0u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 2u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 3u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciFunction, 1u);
|
||||
|
||||
entryIndex = 5;
|
||||
entryIndex = 2;
|
||||
openCounter = 1;
|
||||
|
||||
drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
||||
ASSERT_NE(drm, nullptr);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDomain, 0u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciBus, 3u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 0u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciBus, 0u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 2u);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciFunction, 0u);
|
||||
|
||||
uint32_t referenceData[4][4] = {
|
||||
{0x0a00, 0x00, 0x03, 0x1},
|
||||
{0x0000, 0xb3, 0x03, 0x1},
|
||||
{0x0000, 0x00, 0xb3, 0x1},
|
||||
{0x0000, 0x00, 0x03, 0xa}};
|
||||
for (uint32_t idx = 7; idx < 11; idx++) {
|
||||
entryIndex = idx;
|
||||
openCounter = 1;
|
||||
drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
||||
ASSERT_NE(drm, nullptr);
|
||||
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDomain, referenceData[idx - 7][0]);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciBus, referenceData[idx - 7][1]);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciDevice, referenceData[idx - 7][2]);
|
||||
EXPECT_EQ(drm->getPciBusInfo().pciFunction, referenceData[idx - 7][3]);
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +105,16 @@ int closedir(DIR *dirp) {
|
||||
|
||||
struct dirent entries[] = {
|
||||
{0, 0, 0, 0, "."},
|
||||
{0, 0, 0, 0, "pci-0000:00:03.1-render"},
|
||||
{0, 0, 0, 0, "platform-4010000000.pcie-pci-0000:00:02.0-render"},
|
||||
{0, 0, 0, 0, "pci-0000:test1-render"},
|
||||
{0, 0, 0, 0, "pci-0000:test2-render"},
|
||||
{0, 0, 0, 0, "pci-0000:1234-render"},
|
||||
{0, 0, 0, 0, "pci-0000:0:2.1-render"},
|
||||
{0, 0, 0, 0, "pci-0000:3:0.0-render"},
|
||||
{0, 0, 0, 0, "pci-0a00:00:03.1-render"},
|
||||
{0, 0, 0, 0, "pci-0000:b3:03.1-render"},
|
||||
{0, 0, 0, 0, "pci-0000:00:b3.1-render"},
|
||||
{0, 0, 0, 0, "pci-0000:00:03.a-render"},
|
||||
};
|
||||
|
||||
uint32_t entryIndex = 0u;
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <linux/limits.h>
|
||||
#include <regex>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@ -514,8 +515,6 @@ void appendHwDeviceId(std::vector<std::unique_ptr<HwDeviceId>> &hwDeviceIds, int
|
||||
std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironment &executionEnvironment) {
|
||||
std::vector<std::unique_ptr<HwDeviceId>> hwDeviceIds;
|
||||
executionEnvironment.osEnvironment = std::make_unique<OsEnvironment>();
|
||||
std::string devicePrefix = std::string(Os::pciDevicesDirectory) + "/pci-";
|
||||
const char *renderDeviceSuffix = "-render";
|
||||
size_t numRootDevices = 0u;
|
||||
if (DebugManager.flags.CreateMultipleRootDevices.get()) {
|
||||
numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get();
|
||||
@ -543,11 +542,14 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
|
||||
}
|
||||
|
||||
do {
|
||||
const std::regex renderRegex(".*([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]\\.[0-9a-fA-F])-render$");
|
||||
for (std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) {
|
||||
if (file->find(renderDeviceSuffix) == std::string::npos) {
|
||||
std::smatch fnMatch;
|
||||
auto reMatch = std::regex_match(*file, fnMatch, renderRegex);
|
||||
if (!reMatch) {
|
||||
continue;
|
||||
}
|
||||
std::string pciPath = file->substr(devicePrefix.size(), file->size() - devicePrefix.size() - strlen(renderDeviceSuffix));
|
||||
std::string pciPath = fnMatch[1];
|
||||
|
||||
if (DebugManager.flags.ForceDeviceId.get() != "unk") {
|
||||
if (file->find(DebugManager.flags.ForceDeviceId.get().c_str()) == std::string::npos) {
|
||||
@ -729,7 +731,7 @@ PhysicalDevicePciBusInfo Drm::getPciBusInfo() const {
|
||||
PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue);
|
||||
|
||||
if (adapterBDF.Data != std::numeric_limits<uint32_t>::max()) {
|
||||
pciBusInfo.pciDomain = 0;
|
||||
pciBusInfo.pciDomain = this->pciDomain;
|
||||
pciBusInfo.pciBus = adapterBDF.Bus;
|
||||
pciBusInfo.pciDevice = adapterBDF.Device;
|
||||
pciBusInfo.pciFunction = adapterBDF.Function;
|
||||
|
@ -10,6 +10,9 @@ if(UNIX)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock.h
|
||||
)
|
||||
target_sources(neo_libult PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/directory_linux.cpp
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
endif()
|
||||
|
28
shared/test/common/libult/linux/directory_linux.cpp
Normal file
28
shared/test/common/libult/linux/directory_linux.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/utilities/directory.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <dirent.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
std::vector<std::string> Directory::getFiles(const std::string &path) {
|
||||
std::vector<std::string> files;
|
||||
if (path == "./test_files/linux/by-path") {
|
||||
files.push_back("./test_files/linux/by-path/pci-0000:00:02.0-card");
|
||||
files.push_back("./test_files/linux/by-path/pci-0000:00:02.0-render");
|
||||
return files;
|
||||
}
|
||||
if (path == "./test_files/linux/devices/device/drm") {
|
||||
files.push_back("./test_files/linux/devices/device/drm/card1");
|
||||
return files;
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}; // namespace NEO
|
@ -17,13 +17,15 @@ namespace NEO {
|
||||
|
||||
class DrmMockDefault : public DrmMock {
|
||||
public:
|
||||
DrmMockDefault(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(rootDeviceEnvironment) {
|
||||
DrmMockDefault(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(rootDeviceEnvironment) {
|
||||
storedRetVal = 0;
|
||||
storedRetValForDeviceID = 0;
|
||||
storedRetValForDeviceRevID = 0;
|
||||
storedRetValForPooledEU = 0;
|
||||
storedRetValForMinEUinPool = 0;
|
||||
setGtType(GTTYPE_GT1);
|
||||
if (hwDeviceIdIn != nullptr)
|
||||
this->hwDeviceId = std::move(hwDeviceIdIn);
|
||||
}
|
||||
};
|
||||
|
||||
@ -35,7 +37,7 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
|
||||
if (pDrmToReturnFromCreateFunc) {
|
||||
return *pDrmToReturnFromCreateFunc;
|
||||
}
|
||||
auto drm = new DrmMockDefault(rootDeviceEnvironment);
|
||||
auto drm = new DrmMockDefault(std::move(hwDeviceId), rootDeviceEnvironment);
|
||||
|
||||
const HardwareInfo *hwInfo = rootDeviceEnvironment.getHardwareInfo();
|
||||
|
||||
|
@ -54,9 +54,10 @@ int open(const char *file, int flags) {
|
||||
if (strcmp(file, "/dev/dri/by-path/pci-0000:invalid-render") == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(file, "./test_files/linux/by-path/pci-0000-device-render") == 0) {
|
||||
if (strcmp(file, "./test_files/linux/by-path/pci-0000:00:02.0-render") == 0) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user