refactor(sysman): Move getEnergyCounter implementation to product specific file

Related-To: NEO-11296

Signed-off-by: Anvesh Bakwad <anvesh.bakwad@intel.com>
This commit is contained in:
Anvesh Bakwad
2025-02-21 16:17:16 +00:00
committed by Compute-Runtime-Automation
parent 51f275dc09
commit a017025e67
10 changed files with 150 additions and 256 deletions

View File

@@ -21,7 +21,6 @@ namespace L0 {
namespace Sysman {
namespace ult {
constexpr uint64_t setEnergyCounter = (83456u * 1048576u);
constexpr uint64_t mockKeyOffset = 0x420;
constexpr uint32_t mockLimitCount = 2u;
const std::string hwmonDir("device/hwmon");

View File

@@ -561,6 +561,14 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenHwMonDoesNotExistAndTelemDataNotAvaila
}
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode) {
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0, ZES_POWER_DOMAIN_PACKAGE));
pLinuxPowerImp->isTelemetrySupportAvailable = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getEnergyCounter(&energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
zes_energy_threshold_t threshold;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -17,13 +17,13 @@ using SysmanProductHelperPmtTest = ::testing::Test;
HWTEST2_F(SysmanProductHelperPmtTest, GivenSysmanProductHelperInstanceWhenGetGuidToKeyOffsetMapIsCalledThenValidMapIsReturned, IsDG1) {
const std::map<std::string, std::map<std::string, uint64_t>> mockDg1GuidToKeyOffsetMap = {{"0x490e01",
{{"PACKAGE_ENERGY", 0x420},
{{"SOC_TEMPERATURES", 0x60},
{"COMPUTE_TEMPERATURES", 0x68}}}};
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
auto pGuidToKeyOffsetMap = pSysmanProductHelper->getGuidToKeyOffsetMap();
EXPECT_NE(nullptr, pGuidToKeyOffsetMap);
EXPECT_EQ(mockDg1GuidToKeyOffsetMap.at("0x490e01").at("PACKAGE_ENERGY"), (*pGuidToKeyOffsetMap).at("0x490e01").at("PACKAGE_ENERGY"));
EXPECT_EQ(mockDg1GuidToKeyOffsetMap.at("0x490e01").at("SOC_TEMPERATURES"), (*pGuidToKeyOffsetMap).at("0x490e01").at("SOC_TEMPERATURES"));
EXPECT_EQ(mockDg1GuidToKeyOffsetMap.at("0x490e01").at("COMPUTE_TEMPERATURES"), (*pGuidToKeyOffsetMap).at("0x490e01").at("COMPUTE_TEMPERATURES"));
}

View File

@@ -58,9 +58,6 @@ static ssize_t mockReadSuccess(int fd, void *buf, size_t count, off_t offset) {
} else if (fd == 5) {
oStream << "0x490e01";
} else if (fd == 6) {
if (offset == mockKeyOffset) {
val = setEnergyCounter;
}
memcpy(buf, &val, count);
return count;
} else if (fd == 7) {
@@ -143,7 +140,13 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidProductHelperHandleWhenCalling
EXPECT_TRUE(pSysmanProductHelper->isPowerSetLimitSupported());
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWhenGettingPowerEnergyCounterThenFailureIsReturned, IsNotDG2) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pSysmanProductHelper->getPowerEnergyCounter(&energyCounter, pLinuxSysmanImp, ZES_POWER_DOMAIN_PACKAGE, 0));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
@@ -151,18 +154,20 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackag
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackageDomainWithTelemetryDataNotAvailableAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetryDataNotAvailableAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0xb15a0ede";
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
@@ -173,6 +178,94 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackag
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetryOffsetReadFailsAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::string invalidGuid = "0x4f9302";
if (fd == 4) {
count = -1;
}
return count;
});
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0, ZES_POWER_DOMAIN_PACKAGE));
pLinuxPowerImp->isTelemetrySupportAvailable = true;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetryKeyOffsetMapNotAvailableAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string invalidGuid = "0xABCDEFG";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, invalidGuid.data(), count);
}
return count;
});
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0, ZES_POWER_DOMAIN_PACKAGE));
pLinuxPowerImp->isTelemetrySupportAvailable = true;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportAvailableWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromPmtNode, IsDG2) {
static uint64_t setEnergyCounter = 123456u;
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
memcpy(buf, &setEnergyCounter, count);
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_EQ(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
// Calculate output energyCounter value
constexpr uint64_t fixedPointToJoule = 1048576;
uint64_t outputEnergyCounter = static_cast<uint64_t>((setEnergyCounter / fixedPointToJoule) * convertJouleToMicroJoule);
EXPECT_EQ(energyCounter.energy, outputEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackagePackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
@@ -181,220 +274,6 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackage
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackageDomainWithTelemetrySupportAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0xb15a0ede";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
}
return count;
});
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, true, 0, ZES_POWER_DOMAIN_PACKAGE));
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0xb15a0ede";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_EQ(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportAvailableWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromPmtNode, IsDG1) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x490e01";
// uint32_t mockKeyValue = 0x3;
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
memcpy(buf, &setEnergyCounter, count);
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_EQ(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode, IsDG1) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x490e01";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_EQ(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportAvailableWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromPmtNode, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
memcpy(buf, &setEnergyCounter, count);
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_EQ(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_EQ(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned, IsDG1) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);