mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
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:
committed by
Compute-Runtime-Automation
parent
e3260de8ca
commit
a7e86f40bf
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user