Revert "fix: use FileDescriptor class to handle open/close file descriptor in...

This reverts commit 174ec38b52.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2023-10-11 02:46:47 +02:00
committed by Compute-Runtime-Automation
parent dee5ecfdf3
commit 52cc796886
25 changed files with 349 additions and 30 deletions

View File

@@ -9,7 +9,6 @@
#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"
@@ -32,7 +31,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 = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY);
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
if (fd == -1) {
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
@@ -41,6 +40,11 @@ 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;
}
@@ -49,7 +53,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 = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY);
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
if (fd == -1) {
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
@@ -59,6 +63,10 @@ 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,6 +42,8 @@ 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,6 +37,8 @@ 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,9 +145,11 @@ 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,8 +5,6 @@
*
*/
#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"
@@ -15,6 +13,7 @@ extern bool sysmanUltsEnable;
namespace L0 {
namespace ult {
static int fakeFileDescriptor = 123;
const std::map<std::string, uint64_t> dummyKeyOffsetMap = {
{"DUMMY_KEY", 0x0}};
@@ -120,12 +119,32 @@ 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;
}
ssize_t preadMockPmt(int fd, void *buf, size_t count, off_t offset) {
*reinterpret_cast<uint32_t *>(buf) = 3u;
return count;
}
@@ -135,37 +154,52 @@ 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);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt);
pPmt->openFunction = openMockReturnFailure;
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint32TypeThenSuccessIsReturned) {
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndCloseSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt);
pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem;
pPmt->openFunction = openMock;
pPmt->preadFunction = preadMockPmt;
pPmt->closeFunction = closeMockReturnFailure;
uint32_t val = 0;
pPmt->keyOffsetMap = dummyKeyOffsetMap;
EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val));
EXPECT_EQ(val, 3u);
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndOpenSysCallFailsThenreadValueFails) {
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
pPmt->openFunction = 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;
@@ -175,7 +209,9 @@ 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,6 +92,8 @@ 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,11 +30,27 @@ 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
@@ -236,6 +252,8 @@ 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);
@@ -296,6 +314,8 @@ 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);
@@ -349,6 +369,8 @@ 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);
@@ -367,6 +389,8 @@ 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;
@@ -387,6 +411,8 @@ 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);
@@ -406,6 +432,7 @@ 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);
@@ -424,6 +451,9 @@ 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();
@@ -460,6 +490,7 @@ 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);
@@ -474,6 +505,8 @@ 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);
@@ -488,6 +521,8 @@ 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);
@@ -502,6 +537,8 @@ 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);
@@ -516,6 +553,8 @@ 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,7 +282,9 @@ 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,7 +216,9 @@ 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,9 +11,27 @@
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;
@@ -166,6 +184,8 @@ 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;
}
@@ -487,6 +507,8 @@ 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;
}
@@ -635,6 +657,8 @@ 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,9 +11,27 @@
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;
@@ -173,6 +191,8 @@ 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;
}
@@ -646,6 +666,8 @@ 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;
}
@@ -754,6 +776,8 @@ 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,7 +41,9 @@ 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;
@@ -168,4 +170,4 @@ class PublicLinuxTemperatureImp : public L0::LinuxTemperatureImp {
using LinuxTemperatureImp::type;
};
} // namespace ult
} // namespace L0
} // namespace L0