fix: use FileDescriptor class to handle open/close file descriptor in PCI/PMT

Related-To: NEO-9038
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2023-10-10 08:13:48 +00:00 committed by Compute-Runtime-Automation
parent e3260de8ca
commit a7e86f40bf
25 changed files with 79 additions and 344 deletions

View File

@ -8,6 +8,7 @@
#include "level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/os_interface/linux/file_descriptor.h"
#include "shared/source/utilities/directory.h"
#include "level_zero/sysman/source/api/pci/sysman_pci_imp.h"
@ -293,8 +294,7 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &
return false;
}
int fd = -1;
fd = this->openFunction(pciPath.c_str(), O_RDONLY);
auto fd = NEO::FileDescriptor(pciPath.c_str(), O_RDONLY);
if (fd < 0) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config File Open Failed \n", __FUNCTION__);
return false;
@ -303,10 +303,6 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config Mem Read Failed \n", __FUNCTION__);
return false;
}
if (this->closeFunction(fd) < 0) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config file close Failed \n", __FUNCTION__);
return false;
}
return true;
}

View File

@ -40,8 +40,6 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
L0::Sysman::SysfsAccess *pSysfsAccess = nullptr;
L0::Sysman::LinuxSysmanImp *pLinuxSysmanImp = nullptr;
bool getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &configMem);
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
private:

View File

@ -8,6 +8,7 @@
#include "level_zero/sysman/source/linux/pmt/sysman_pmt.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/os_interface/linux/file_descriptor.h"
#include "level_zero/sysman/source/linux/zes_os_sysman_imp.h"
#include "level_zero/sysman/source/sysman_device_imp.h"
@ -32,7 +33,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v
if (offset == keyOffsetMap.end()) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
auto fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY);
if (fd == -1) {
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
@ -41,11 +42,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v
if (this->preadFunction(fd, &value, sizeof(uint32_t), baseOffset + offset->second) != sizeof(uint32_t)) {
res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
if (this->closeFunction(fd) < 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return res;
}
@ -54,7 +50,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v
if (offset == keyOffsetMap.end()) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
auto fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY);
if (fd == -1) {
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
@ -63,11 +59,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v
if (this->preadFunction(fd, &value, sizeof(uint64_t), baseOffset + offset->second) != sizeof(uint64_t)) {
res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
if (this->closeFunction(fd) < 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return res;
}

View File

@ -44,8 +44,6 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass {
ze_result_t init(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, PRODUCT_FAMILY productFamily);
static void doInitPmtObject(FsAccess *pFsAccess, uint32_t subdeviceId, PlatformMonitoringTech *pPmt, const std::string &gpuUpstreamPortPath,
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject, PRODUCT_FAMILY productFamily);
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
private:

View File

@ -146,11 +146,9 @@ struct MockPmtFsAccess : public L0::Sysman::FsAccess {
class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech {
public:
PublicPlatformMonitoringTech(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
using PlatformMonitoringTech::closeFunction;
using PlatformMonitoringTech::doInitPmtObject;
using PlatformMonitoringTech::init;
using PlatformMonitoringTech::keyOffsetMap;
using PlatformMonitoringTech::openFunction;
using PlatformMonitoringTech::preadFunction;
using PlatformMonitoringTech::rootDeviceTelemNodeIndex;
using PlatformMonitoringTech::telemetryDeviceEntry;

View File

@ -13,8 +13,6 @@ namespace L0 {
namespace Sysman {
namespace ult {
static int fakeFileDescriptor = 123;
const std::map<std::string, uint64_t> dummyKeyOffsetMap = {
{"DUMMY_KEY", 0x0}};
@ -104,32 +102,24 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesTh
EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt, productFamily), ZE_RESULT_ERROR_NOT_AVAILABLE);
}
inline static int openMock(const char *pathname, int flags) {
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
return fakeFileDescriptor;
}
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
return fakeFileDescriptor;
}
return -1;
}
inline static int openMockReturnFailure(const char *pathname, int flags) {
return -1;
}
inline static int closeMock(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
inline static int closeMockReturnFailure(int fd) {
return -1;
inline static int openMockReturnSuccess(const char *pathname, int flags) {
NEO::SysCalls::closeFuncCalled = 0;
return 0;
}
ssize_t preadMockPmt(int fd, void *buf, size_t count, off_t offset) {
EXPECT_EQ(0u, NEO::SysCalls::closeFuncCalled);
*reinterpret_cast<uint32_t *>(buf) = 3u;
return count;
}
ssize_t preadMockPmt64(int fd, void *buf, size_t count, off_t offset) {
EXPECT_EQ(0u, NEO::SysCalls::closeFuncCalled);
*reinterpret_cast<uint64_t *>(buf) = 5u;
return count;
}
@ -139,52 +129,49 @@ ssize_t preadMockPmtFailure(int fd, void *buf, size_t count, off_t offset) {
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndOpenSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->openFunction = openMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt);
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndCloseSysCallFailsThenreadValueFails) {
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint32TypeThenSuccessIsReturned) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmt;
pPmt->closeFunction = closeMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt);
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(val, 3u);
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint64TypeThenSuccessIsReturned) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt64);
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(val, 5u);
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndOpenSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->openFunction = openMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndCloseSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmt;
pPmt->closeFunction = closeMockReturnFailure;
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndPreadSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmtFailure;
pPmt->closeFunction = closeMock;
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
@ -194,9 +181,7 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint3
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndPreadSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmtFailure;
pPmt->closeFunction = closeMock;
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;

View File

@ -95,8 +95,6 @@ struct MockPciSysfsAccess : public L0::Sysman::SysfsAccess {
class PublicLinuxPciImp : public L0::Sysman::LinuxPciImp {
public:
PublicLinuxPciImp(L0::Sysman::OsSysman *pOsSysman) : L0::Sysman::LinuxPciImp(pOsSysman) {}
using L0::Sysman::LinuxPciImp::closeFunction;
using L0::Sysman::LinuxPciImp::openFunction;
using L0::Sysman::LinuxPciImp::preadFunction;
using L0::Sysman::LinuxPciImp::pSysfsAccess;
};

View File

@ -25,32 +25,18 @@ constexpr int convertMegabitsPerSecondToBytesPerSecond = 125000;
constexpr int convertGigabitToMegabit = 1000;
constexpr double encodingGen1Gen2 = 0.8;
constexpr double encodingGen3andAbove = 0.98461538461;
static int fakeFileDescriptor = 123;
inline static int openMock(const char *pathname, int flags) {
if ((strcmp(pathname, mockRealPathConfig.c_str()) == 0) || (strcmp(pathname, mockRealPath2LevelsUpConfig.c_str()) == 0)) {
return fakeFileDescriptor;
}
return -1;
}
inline static int openMockReturnFailure(const char *pathname, int flags) {
return -1;
}
inline static int closeMock(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
inline static int closeMockReturnFailure(int fd) {
return -1;
inline static int openMockReturnSuccess(const char *pathname, int flags) {
NEO::SysCalls::closeFuncCalled = 0;
return 0;
}
ssize_t preadMock(int fd, void *buf, size_t count, off_t offset) {
EXPECT_EQ(0u, NEO::SysCalls::closeFuncCalled);
uint8_t *mockBuf = static_cast<uint8_t *>(buf);
// Sample config values
if (count == PCI_CFG_SPACE_EXP_SIZE) {
@ -225,6 +211,7 @@ class ZesPciFixture : public SysmanDeviceFixture {
L0::Sysman::PciImp *pPciImp;
L0::Sysman::OsPci *pOsPciPrev;
std::unique_ptr<L0::ult::Mock<L0::DriverHandleImp>> driverHandle;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup{&NEO::SysCalls::sysCallsOpen, openMockReturnSuccess};
void SetUp() override {
SysmanDeviceFixture::SetUp();
@ -237,8 +224,6 @@ class ZesPciFixture : public SysmanDeviceFixture {
pOsPciPrev = pPciImp->pOsPci;
pPciImp->pOsPci = nullptr;
PublicLinuxPciImp *pLinuxPciImp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImp->openFunction = openMock;
pLinuxPciImp->closeFunction = closeMock;
pLinuxPciImp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImp);
@ -289,8 +274,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetS
zes_pci_properties_t properties, propertiesBefore;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -343,8 +326,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndCapabilityL
double speed = 0;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockInvalidPos;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -362,8 +343,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIExpressC
double speed = 0;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockLoop;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -381,8 +360,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndUserIsNonRo
double speed = 0;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pSysfsAccess->isRootUserResult = false;
@ -402,27 +379,7 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigOpenFailsT
double speed = 0;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMockReturnFailure;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
pPciImp->pciGetStaticFields();
pPciImp->pOsPci->getMaxLinkCaps(speed, width);
EXPECT_EQ(width, -1);
EXPECT_EQ(speed, 0);
delete pLinuxPciImpTemp;
pPciImp->pOsPci = pOsPciOriginal;
}
TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigCloseFailsThenInvalidSpeedAndWidthAreReturned) {
int32_t width = 0;
double speed = 0;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -440,8 +397,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIHeaderIs
double speed = 0;
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -478,8 +433,7 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenFailsThenResizableBarSupportWillBeFalse) {
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMockReturnFailure;
pLinuxPciImpTemp->closeFunction = closeMock;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -494,8 +448,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadFailsThenResizableBarSupportWillBeFalse) {
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockFailure;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -510,8 +462,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadF
TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderFieldNotPresentThenResizableBarSupportFalseReturned) {
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -526,8 +476,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderF
TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabilityLinkListIsBrokenThenResizableBarSupportFalseReturned) {
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockInvalidPos;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);
@ -542,8 +490,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabil
TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndIfRebarCapabilityNotPresentThenResizableBarSupportFalseReturned) {
L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockLoop;
pPciImp->pOsPci = static_cast<L0::Sysman::OsPci *>(pLinuxPciImpTemp);

View File

@ -284,9 +284,7 @@ struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess {
};
struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech {
using L0::Sysman::PlatformMonitoringTech::closeFunction;
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
using L0::Sysman::PlatformMonitoringTech::openFunction;
using L0::Sysman::PlatformMonitoringTech::preadFunction;
using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry;

View File

@ -218,9 +218,7 @@ struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess {
struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech {
MockPowerPmt(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
using L0::Sysman::PlatformMonitoringTech::closeFunction;
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
using L0::Sysman::PlatformMonitoringTech::openFunction;
using L0::Sysman::PlatformMonitoringTech::preadFunction;
using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry;
~MockPowerPmt() override {

View File

@ -11,27 +11,9 @@ namespace L0 {
namespace Sysman {
namespace ult {
static int fakeFileDescriptor = 123;
constexpr uint64_t convertJouleToMicroJoule = 1000000u;
constexpr uint32_t powerHandleComponentCount = 1u;
inline static int openMockPower(const char *pathname, int flags) {
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
return fakeFileDescriptor;
}
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
return fakeFileDescriptor;
}
return -1;
}
inline static int closeMockPower(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
uint64_t *mockBuf = static_cast<uint64_t *>(buf);
*mockBuf = setEnergyCounter;
@ -183,8 +165,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
@ -506,8 +486,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
@ -658,8 +636,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);

View File

@ -11,27 +11,9 @@ namespace L0 {
namespace Sysman {
namespace ult {
static int fakeFileDescriptor = 123;
constexpr uint64_t convertJouleToMicroJoule = 1000000u;
constexpr uint32_t powerHandleComponentCount = 1u;
inline static int openMockPower(const char *pathname, int flags) {
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
return fakeFileDescriptor;
}
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
return fakeFileDescriptor;
}
return -1;
}
inline static int closeMockPower(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
uint64_t *mockBuf = static_cast<uint64_t *>(buf);
*mockBuf = setEnergyCounter;
@ -190,8 +172,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
@ -666,8 +646,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
@ -778,8 +756,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);

View File

@ -44,9 +44,7 @@ const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5";
struct MockTemperaturePmt : public L0::Sysman::PlatformMonitoringTech {
MockTemperaturePmt(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
using L0::Sysman::PlatformMonitoringTech::closeFunction;
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
using L0::Sysman::PlatformMonitoringTech::openFunction;
using L0::Sysman::PlatformMonitoringTech::preadFunction;
using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry;
@ -175,4 +173,4 @@ class PublicLinuxTemperatureImp : public L0::Sysman::LinuxTemperatureImp {
} // namespace ult
} // namespace Sysman
} // namespace L0
} // namespace L0

View File

@ -9,6 +9,7 @@
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/os_interface/linux/file_descriptor.h"
#include "level_zero/tools/source/sysman/sysman_imp.h"
@ -31,7 +32,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v
if (offset == keyOffsetMap.end()) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
auto fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY);
if (fd == -1) {
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
@ -40,11 +41,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v
if (this->preadFunction(fd, &value, sizeof(uint32_t), baseOffset + offset->second) != sizeof(uint32_t)) {
res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
if (this->closeFunction(fd) < 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return res;
}
@ -53,7 +49,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v
if (offset == keyOffsetMap.end()) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
auto fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY);
if (fd == -1) {
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
@ -63,10 +59,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v
res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
if (this->closeFunction(fd) < 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return res;
}

View File

@ -42,8 +42,6 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass {
ze_result_t init(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, PRODUCT_FAMILY productFamily);
static void doInitPmtObject(FsAccess *pFsAccess, uint32_t subdeviceId, PlatformMonitoringTech *pPmt, const std::string &gpuUpstreamPortPath,
std::map<uint32_t, L0::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject, PRODUCT_FAMILY productFamily);
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
private:

View File

@ -37,8 +37,6 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
SysfsAccess *pSysfsAccess = nullptr;
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
bool getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &configMem);
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
private:

View File

@ -145,11 +145,9 @@ struct MockPmtFsAccess : public FsAccess {
class PublicPlatformMonitoringTech : public L0::PlatformMonitoringTech {
public:
PublicPlatformMonitoringTech(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
using PlatformMonitoringTech::closeFunction;
using PlatformMonitoringTech::doInitPmtObject;
using PlatformMonitoringTech::init;
using PlatformMonitoringTech::keyOffsetMap;
using PlatformMonitoringTech::openFunction;
using PlatformMonitoringTech::preadFunction;
using PlatformMonitoringTech::telemetryDeviceEntry;
};

View File

@ -5,6 +5,8 @@
*
*/
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
#include "mock_pmt.h"
@ -13,7 +15,6 @@ extern bool sysmanUltsEnable;
namespace L0 {
namespace ult {
static int fakeFileDescriptor = 123;
const std::map<std::string, uint64_t> dummyKeyOffsetMap = {
{"DUMMY_KEY", 0x0}};
@ -119,32 +120,24 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesTh
EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt, productFamily), ZE_RESULT_ERROR_NOT_AVAILABLE);
}
inline static int openMock(const char *pathname, int flags) {
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
return fakeFileDescriptor;
}
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
return fakeFileDescriptor;
}
return -1;
}
inline static int openMockReturnFailure(const char *pathname, int flags) {
return -1;
}
inline static int closeMock(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
inline static int closeMockReturnFailure(int fd) {
return -1;
inline static int openMockReturnSuccess(const char *pathname, int flags) {
NEO::SysCalls::closeFuncCalled = 0;
return 0;
}
ssize_t preadMockPmt(int fd, void *buf, size_t count, off_t offset) {
EXPECT_EQ(0u, NEO::SysCalls::closeFuncCalled);
*reinterpret_cast<uint32_t *>(buf) = 3u;
return count;
}
ssize_t preadMockPmt64(int fd, void *buf, size_t count, off_t offset) {
EXPECT_EQ(0u, NEO::SysCalls::closeFuncCalled);
*reinterpret_cast<uint64_t *>(buf) = 5u;
return count;
}
@ -154,52 +147,49 @@ ssize_t preadMockPmtFailure(int fd, void *buf, size_t count, off_t offset) {
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndOpenSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->openFunction = openMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt);
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndCloseSysCallFailsThenreadValueFails) {
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint32TypeThenSuccessIsReturned) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmt;
pPmt->closeFunction = closeMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt);
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(val, 3u);
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint64TypeThenSuccessIsReturned) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt64);
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(val, 5u);
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndOpenSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->openFunction = openMockReturnFailure;
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndCloseSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmt;
pPmt->closeFunction = closeMockReturnFailure;
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndPreadSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmtFailure;
pPmt->closeFunction = closeMock;
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
@ -209,9 +199,7 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint3
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndPreadSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmtFailure;
pPmt->closeFunction = closeMock;
uint64_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;

View File

@ -92,8 +92,6 @@ struct MockPciSysfsAccess : public SysfsAccess {
class PublicLinuxPciImp : public L0::LinuxPciImp {
public:
PublicLinuxPciImp(OsSysman *pOsSysman) : LinuxPciImp(pOsSysman) {}
using LinuxPciImp::closeFunction;
using LinuxPciImp::openFunction;
using LinuxPciImp::preadFunction;
using LinuxPciImp::pSysfsAccess;
};

View File

@ -30,27 +30,11 @@ constexpr int convertMegabitsPerSecondToBytesPerSecond = 125000;
constexpr int convertGigabitToMegabit = 1000;
constexpr double encodingGen1Gen2 = 0.8;
constexpr double encodingGen3andAbove = 0.98461538461;
static int fakeFileDescriptor = 123;
inline static int openMock(const char *pathname, int flags) {
if ((strcmp(pathname, mockRealPathConfig.c_str()) == 0) || (strcmp(pathname, mockRealPath2LevelsUpConfig.c_str()) == 0)) {
return fakeFileDescriptor;
}
return -1;
}
inline static int openMockReturnFailure(const char *pathname, int flags) {
return -1;
}
inline static int closeMock(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
ssize_t preadMock(int fd, void *buf, size_t count, off_t offset) {
uint8_t *mockBuf = static_cast<uint8_t *>(buf);
// Sample config values
@ -252,8 +236,6 @@ class ZesPciFixture : public SysmanDeviceFixture {
pPciImp->pOsPci = nullptr;
memoryManager->localMemorySupported[0] = 0;
PublicLinuxPciImp *pLinuxPciImp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImp->openFunction = openMock;
pLinuxPciImp->closeFunction = closeMock;
pLinuxPciImp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImp);
@ -314,8 +296,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetS
memoryManager->localMemorySupported[0] = 1;
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -369,8 +349,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndCapabilityL
memoryManager->localMemorySupported[0] = 1;
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockInvalidPos;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -389,8 +367,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndUserIsNonRo
memoryManager->localMemorySupported[0] = 1;
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pSysfsAccess->isRootUserResult = false;
@ -411,8 +387,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIExpressC
memoryManager->localMemorySupported[0] = 1;
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockLoop;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -432,7 +406,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigOpenFailsT
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -451,9 +424,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIHeaderIs
memoryManager->localMemorySupported[0] = 1;
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
pPciImp->pciGetStaticFields();
@ -490,7 +460,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMock;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -505,8 +474,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadFailsThenResizableBarSupportWillBeFalse) {
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockFailure;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -521,8 +488,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadF
TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderFieldNotPresentThenResizableBarSupportFalseReturned) {
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -537,8 +502,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderF
TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabilityLinkListIsBrokenThenResizableBarSupportFalseReturned) {
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockInvalidPos;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
@ -553,8 +516,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabil
TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndIfRebarCapabilityNotPresentThenResizableBarSupportFalseReturned) {
OsPci *pOsPciOriginal = pPciImp->pOsPci;
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
pLinuxPciImpTemp->openFunction = openMock;
pLinuxPciImpTemp->closeFunction = closeMock;
pLinuxPciImpTemp->preadFunction = preadMockLoop;
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);

View File

@ -282,9 +282,7 @@ struct MockPowerSysfsAccess : public SysfsAccess {
};
struct MockPowerPmt : public PlatformMonitoringTech {
using PlatformMonitoringTech::closeFunction;
using PlatformMonitoringTech::keyOffsetMap;
using PlatformMonitoringTech::openFunction;
using PlatformMonitoringTech::preadFunction;
using PlatformMonitoringTech::telemetryDeviceEntry;

View File

@ -216,9 +216,7 @@ struct MockPowerSysfsAccess : public SysfsAccess {
struct MockPowerPmt : public PlatformMonitoringTech {
MockPowerPmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
using PlatformMonitoringTech::closeFunction;
using PlatformMonitoringTech::keyOffsetMap;
using PlatformMonitoringTech::openFunction;
using PlatformMonitoringTech::preadFunction;
using PlatformMonitoringTech::telemetryDeviceEntry;
~MockPowerPmt() override {

View File

@ -11,27 +11,9 @@
namespace L0 {
namespace ult {
static int fakeFileDescriptor = 123;
constexpr uint64_t convertJouleToMicroJoule = 1000000u;
constexpr uint32_t powerHandleComponentCount = 1u;
inline static int openMockPower(const char *pathname, int flags) {
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
return fakeFileDescriptor;
}
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
return fakeFileDescriptor;
}
return -1;
}
inline static int closeMockPower(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
uint64_t *mockBuf = static_cast<uint64_t *>(buf);
*mockBuf = setEnergyCounter;
@ -184,8 +166,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
}
@ -507,8 +487,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
}
@ -657,8 +635,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
}

View File

@ -11,27 +11,9 @@
namespace L0 {
namespace ult {
static int fakeFileDescriptor = 123;
constexpr uint64_t convertJouleToMicroJoule = 1000000u;
constexpr uint32_t powerHandleComponentCount = 1u;
inline static int openMockPower(const char *pathname, int flags) {
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
return fakeFileDescriptor;
}
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
return fakeFileDescriptor;
}
return -1;
}
inline static int closeMockPower(int fd) {
if (fd == fakeFileDescriptor) {
return 0;
}
return -1;
}
ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
uint64_t *mockBuf = static_cast<uint64_t *>(buf);
*mockBuf = setEnergyCounter;
@ -191,8 +173,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
}
@ -666,8 +646,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
}
@ -776,8 +754,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId));
pPmt->openFunction = openMockPower;
pPmt->closeFunction = closeMockPower;
pPmt->preadFunction = preadMockPower;
}

View File

@ -41,9 +41,7 @@ const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5";
struct MockTemperaturePmt : public PlatformMonitoringTech {
MockTemperaturePmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
using PlatformMonitoringTech::closeFunction;
using PlatformMonitoringTech::keyOffsetMap;
using PlatformMonitoringTech::openFunction;
using PlatformMonitoringTech::preadFunction;
using PlatformMonitoringTech::telemetryDeviceEntry;
@ -170,4 +168,4 @@ class PublicLinuxTemperatureImp : public L0::LinuxTemperatureImp {
using LinuxTemperatureImp::type;
};
} // namespace ult
} // namespace L0
} // namespace L0