Revert "improve pci path search to use regex to make it more flexible"

This reverts commit dbffbbd193.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2021-10-25 21:45:23 +02:00
committed by Compute-Runtime-Automation
parent 7897fc2dca
commit ee942190ab
9 changed files with 39 additions and 58 deletions

View File

@@ -124,7 +124,7 @@ TEST_F(DrmSimpleTests, GivenSelectedNotExistingDeviceWhenGetDeviceFdThenFail) {
TEST_F(DrmSimpleTests, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.ForceDeviceId.set("0000:00:02.0");
DebugManager.flags.ForceDeviceId.set("1234");
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:00:03.1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_STREQ("0000:test1", 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:00:03.1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_STREQ("0000:test1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_NE(nullptr, hwDeviceIds[1].get());
EXPECT_STREQ("0000:00:02.0", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_STREQ("0000:test2", 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/platform-4010000000.pcie-pci-0000:00:02.0-render", lastOpenedPath.c_str());
EXPECT_STREQ("/dev/dri/by-path/pci-0000:test2-render", lastOpenedPath.c_str());
EXPECT_EQ(requestedNumRootDevices, hwDeviceIds.size());
EXPECT_NE(nullptr, hwDeviceIds[0].get());
EXPECT_STREQ("0000:00:03.1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_STREQ("0000:test1", hwDeviceIds[0]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_NE(nullptr, hwDeviceIds[1].get());
EXPECT_STREQ("0000:00:02.0", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
EXPECT_STREQ("0000:test2", hwDeviceIds[1]->as<HwDeviceIdDrm>()->getPciPath());
}
TEST_F(DrmSimpleTests, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) {
@@ -805,29 +805,48 @@ TEST(PlatformsDestructor, whenGlobalPlatformsDestructorIsCalledThenGlobalPlatfor
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
}
TEST_F(DrmTests, givenValidPciPathThenPciBusInfoIsAvailable) {
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;
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, 3u);
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 2u);
EXPECT_EQ(drm->getPciBusInfo().pciFunction, 1u);
entryIndex = 2;
entryIndex = 5;
openCounter = 1;
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().pciBus, 3u);
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 0u);
EXPECT_EQ(drm->getPciBusInfo().pciFunction, 0u);
}

View File

@@ -105,13 +105,11 @@ 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"},
};
uint32_t entryIndex = 0u;

View File

@@ -33,7 +33,6 @@
#include <cstdio>
#include <cstring>
#include <linux/limits.h>
#include <regex>
namespace NEO {
@@ -515,6 +514,8 @@ 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();
@@ -542,14 +543,11 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
}
do {
const std::regex renderRegex(".*(\\d\\d\\d\\d:\\d\\d:\\d\\d\\.\\d)-render$");
for (std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) {
std::smatch fnMatch;
auto reMatch = std::regex_match(*file, fnMatch, renderRegex);
if (!reMatch) {
if (file->find(renderDeviceSuffix) == std::string::npos) {
continue;
}
std::string pciPath = fnMatch[1];
std::string pciPath = file->substr(devicePrefix.size(), file->size() - devicePrefix.size() - strlen(renderDeviceSuffix));
if (DebugManager.flags.ForceDeviceId.get() != "unk") {
if (file->find(DebugManager.flags.ForceDeviceId.get().c_str()) == std::string::npos) {

View File

@@ -10,9 +10,6 @@ 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()

View File

@@ -1,28 +0,0 @@
/*
* 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

View File

@@ -17,15 +17,13 @@ namespace NEO {
class DrmMockDefault : public DrmMock {
public:
DrmMockDefault(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(rootDeviceEnvironment) {
DrmMockDefault(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);
}
};
@@ -37,7 +35,7 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
if (pDrmToReturnFromCreateFunc) {
return *pDrmToReturnFromCreateFunc;
}
auto drm = new DrmMockDefault(std::move(hwDeviceId), rootDeviceEnvironment);
auto drm = new DrmMockDefault(rootDeviceEnvironment);
const HardwareInfo *hwInfo = rootDeviceEnvironment.getHardwareInfo();

View File

@@ -54,10 +54,9 @@ 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:00:02.0-render") == 0) {
if (strcmp(file, "./test_files/linux/by-path/pci-0000-device-render") == 0) {
return fakeFileDescriptor;
}
return 0;
}