feature(sysman): Xe porting of Power Module

Related-To: LOCI-4851

Signed-off-by: Kumar, Shubham <shubham.kumar@intel.com>
This commit is contained in:
Kumar, Shubham
2023-10-03 05:47:56 +00:00
committed by Compute-Runtime-Automation
parent b3a7f5dccb
commit 03a8b76e02
8 changed files with 675 additions and 394 deletions

View File

@@ -13,6 +13,8 @@
#include "level_zero/sysman/source/api/power/sysman_power_imp.h"
#include "level_zero/sysman/source/device/sysman_device_imp.h"
#include "level_zero/sysman/source/shared/linux/pmt/sysman_pmt.h"
#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h"
#include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h"
#include "level_zero/sysman/source/sysman_const.h"
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h"
@@ -283,6 +285,241 @@ struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess {
MockPowerSysfsAccess() = default;
};
struct MockPowerSysfsAccessInterface : public L0::Sysman::SysFsAccessInterface {
std::vector<ze_result_t> mockReadReturnStatus{};
std::vector<ze_result_t> mockWriteReturnStatus{};
std::vector<ze_result_t> mockScanDirEntriesReturnStatus{};
std::vector<uint64_t> mockReadUnsignedLongValue{};
std::vector<uint32_t> mockReadUnsignedIntValue{};
bool isRepeated = false;
ze_result_t read(const std::string file, std::string &val) override {
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
if (file.compare(i915HwmonDir + "/" + "name") == 0) {
val = "i915";
result = ZE_RESULT_SUCCESS;
} else if (file.compare(nonI915HwmonDir + "/" + "name") == 0) {
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
} else {
val = "garbageI915";
result = ZE_RESULT_SUCCESS;
}
return result;
}
uint64_t sustainedPowerLimitEnabledVal = 1u;
uint64_t sustainedPowerLimitVal = 0;
uint64_t sustainedPowerLimitIntervalVal = 0;
uint64_t burstPowerLimitEnabledVal = 0;
uint64_t burstPowerLimitVal = 0;
uint64_t energyCounterNodeVal = expectedEnergyCounter;
ze_result_t getValUnsignedLongReturnErrorForBurstPowerLimit(const std::string file, uint64_t &val) {
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
val = burstPowerLimitEnabledVal;
}
if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValUnsignedLongReturnErrorForBurstPowerLimitEnabled(const std::string file, uint64_t &val) {
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE; // mocking the condition when user passes nullptr for sustained and peak power in zesPowerGetLimit and burst power file is absent
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValUnsignedLongReturnErrorForSustainedPowerLimitEnabled(const std::string file, uint64_t &val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE; // mocking the condition when user passes nullptr for burst and peak power in zesPowerGetLimit and sustained power file is absent
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValUnsignedLongReturnsPowerLimitEnabledAsDisabled(const std::string file, uint64_t &val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
val = 0;
return ZE_RESULT_SUCCESS;
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
val = 0;
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValUnsignedLongReturnErrorForSustainedPower(const std::string file, uint64_t &val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
val = 1;
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t getValUnsignedLongReturnErrorForSustainedPowerInterval(const std::string file, uint64_t &val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
val = 1;
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValUnsignedLongReturnErrorForBurstPowerLimit(const std::string file, const int val) {
if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValUnsignedLongReturnErrorForBurstPowerLimitEnabled(const std::string file, const int val) {
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValUnsignedLongReturnErrorForSustainedPowerLimitEnabled(const std::string file, const int val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValUnsignedLongReturnInsufficientForSustainedPowerLimitEnabled(const std::string file, const int val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValReturnErrorForSustainedPower(const std::string file, const int val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t setValReturnErrorForSustainedPowerInterval(const std::string file, const int val) {
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t read(const std::string file, uint64_t &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (!mockReadReturnStatus.empty()) {
result = mockReadReturnStatus.front();
if (!mockReadUnsignedLongValue.empty()) {
val = mockReadUnsignedLongValue.front();
}
if (isRepeated != true) {
if (mockReadUnsignedLongValue.size() != 0) {
mockReadUnsignedLongValue.erase(mockReadUnsignedLongValue.begin());
}
mockReadReturnStatus.erase(mockReadReturnStatus.begin());
}
return result;
}
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
val = sustainedPowerLimitEnabledVal;
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
val = sustainedPowerLimitVal;
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
val = sustainedPowerLimitIntervalVal;
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
val = burstPowerLimitEnabledVal;
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
val = burstPowerLimitVal;
} else if (file.compare(i915HwmonDir + "/" + energyCounterNode) == 0) {
val = energyCounterNodeVal;
} else {
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return result;
}
ze_result_t read(const std::string file, uint32_t &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (!mockReadReturnStatus.empty()) {
result = mockReadReturnStatus.front();
if (!mockReadUnsignedIntValue.empty()) {
val = mockReadUnsignedIntValue.front();
}
if (isRepeated != true) {
if (mockReadUnsignedIntValue.size() != 0) {
mockReadUnsignedIntValue.erase(mockReadUnsignedIntValue.begin());
}
mockReadReturnStatus.erase(mockReadReturnStatus.begin());
}
return result;
}
if (file.compare(i915HwmonDir + "/" + defaultPowerLimit) == 0) {
val = mockDefaultPowerLimitVal;
} else if (file.compare(i915HwmonDir + "/" + maxPowerLimit) == 0) {
val = mockMaxPowerLimitVal;
} else if (file.compare(i915HwmonDir + "/" + minPowerLimit) == 0) {
val = mockMinPowerLimitVal;
} else {
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return result;
}
ze_result_t write(const std::string file, const int val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (!mockWriteReturnStatus.empty()) {
ze_result_t result = mockWriteReturnStatus.front();
if (isRepeated != true) {
mockWriteReturnStatus.erase(mockWriteReturnStatus.begin());
}
return result;
}
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
sustainedPowerLimitEnabledVal = static_cast<uint64_t>(val);
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
sustainedPowerLimitVal = static_cast<uint64_t>(val);
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
sustainedPowerLimitIntervalVal = static_cast<uint64_t>(val);
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
burstPowerLimitEnabledVal = static_cast<uint64_t>(val);
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
burstPowerLimitVal = static_cast<uint64_t>(val);
} else {
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return result;
}
ze_result_t scanDirEntries(const std::string file, std::vector<std::string> &listOfEntries) override {
ze_result_t result = ZE_RESULT_ERROR_NOT_AVAILABLE;
if (!mockScanDirEntriesReturnStatus.empty()) {
ze_result_t result = mockScanDirEntriesReturnStatus.front();
if (isRepeated != true) {
mockScanDirEntriesReturnStatus.erase(mockScanDirEntriesReturnStatus.begin());
}
return result;
}
if (file.compare(hwmonDir) == 0) {
listOfEntries = listOfMockedHwmonDirs;
result = ZE_RESULT_SUCCESS;
}
return result;
}
MockPowerSysfsAccessInterface() = default;
};
struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech {
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
using L0::Sysman::PlatformMonitoringTech::preadFunction;
@@ -348,9 +585,10 @@ class PublicLinuxPowerImp : public L0::Sysman::LinuxPowerImp {
public:
PublicLinuxPowerImp(L0::Sysman::OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId) {}
using L0::Sysman::LinuxPowerImp::pPmt;
using L0::Sysman::LinuxPowerImp::pSysfsAccess;
};
class SysmanDevicePowerFixture : public SysmanDeviceFixture {
class SysmanDevicePowerFixtureI915 : public SysmanDeviceFixture {
protected:
L0::Sysman::SysmanDevice *device = nullptr;
std::unique_ptr<PublicLinuxPowerImp> pPublicLinuxPowerImp;
@@ -361,6 +599,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
L0::Sysman::FsAccess *pFsAccessOriginal = nullptr;
L0::Sysman::OsPower *pOsPowerOriginal = nullptr;
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> pmtMapOriginal;
void SetUp() override {
SysmanDeviceFixture::SetUp();
device = pSysmanDevice;
@@ -401,6 +640,19 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
}
};
class SysmanDevicePowerFixtureXe : public SysmanDeviceFixture {
protected:
L0::Sysman::SysmanDevice *device = nullptr;
void SetUp() override {
SysmanDeviceFixture::SetUp();
device = pSysmanDevice;
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
}
void TearDown() override {
SysmanDeviceFixture::TearDown();
}
};
class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
protected:
L0::Sysman::SysmanDevice *device = nullptr;

View File

@@ -20,13 +20,13 @@ ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
return count;
}
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
TEST_F(SysmanDevicePowerFixtureI915, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, powerHandleComponentCount);
}
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
TEST_F(SysmanDevicePowerFixtureI915, GivenInvalidComponentCountWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, powerHandleComponentCount);
@@ -36,7 +36,7 @@ TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerD
EXPECT_EQ(count, powerHandleComponentCount);
}
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidPowerHandlesIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidPowerHandlesIsReturned) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, powerHandleComponentCount);
@@ -48,16 +48,16 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerPointerWhenGettingCardPowerDomainWhenhwmonInterfaceExistsAndThenCallSucceeds) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerPointerWhenGettingCardPowerDomainWhenhwmonInterfaceExistsAndThenCallSucceeds) {
zes_pwr_handle_t phPower = {};
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_SUCCESS);
}
TEST_F(SysmanDevicePowerFixture, GivenInvalidPowerPointerWhenGettingCardPowerDomainAndThenReturnsFailure) {
TEST_F(SysmanDevicePowerFixtureI915, GivenInvalidPowerPointerWhenGettingCardPowerDomainAndThenReturnsFailure) {
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER);
}
TEST_F(SysmanDevicePowerFixture, GivenUninitializedPowerHandlesAndWhenGettingCardPowerDomainThenReturnsFailure) {
TEST_F(SysmanDevicePowerFixtureI915, GivenUninitializedPowerHandlesAndWhenGettingCardPowerDomainThenReturnsFailure) {
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
@@ -67,45 +67,44 @@ TEST_F(SysmanDevicePowerFixture, GivenUninitializedPowerHandlesAndWhenGettingCar
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenhwmonInterfaceExistsThenCallSucceeds) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesWhenhwmonInterfaceExistsThenCallSucceeds) {
for (auto &handle : handles) {
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
EXPECT_EQ(properties.defaultLimit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, static_cast<int32_t>(mockMinPowerLimitVal / milliFactor));
}
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
EXPECT_EQ(properties.defaultLimit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, static_cast<int32_t>(mockMinPowerLimitVal / milliFactor));
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenLimitsReturnsUnknown) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenLimitsReturnsUnknown) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->isPowerModuleSupported();
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto &handle : handles) {
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.defaultLimit, -1);
EXPECT_EQ(properties.maxLimit, -1);
EXPECT_EQ(properties.minLimit, -1);
}
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.defaultLimit, -1);
EXPECT_EQ(properties.maxLimit, -1);
EXPECT_EQ(properties.minLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenMaxLimitIsUnsupported) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenMaxLimitIsUnsupported) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->mockReadUnsignedIntValue.push_back(std::numeric_limits<uint32_t>::max());
@@ -133,256 +132,292 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesThenHwmonInterfaceExistAndMinLimitIsUnknown) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesThenHwmonInterfaceExistAndMinLimitIsUnknown) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->mockReadUnsignedIntValue.push_back(0);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadUnsignedIntValue.push_back(0);
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->mockReadUnsignedIntValue.push_back(0);
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
pSysFsAccess->mockReadUnsignedIntValue.push_back(0);
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto &handle : handles) {
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.defaultLimit, -1);
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.defaultLimit, -1);
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
pSysFsAccess->isRepeated = true;
for (auto handle : handles) {
zes_power_energy_counter_t energyCounter = {};
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pPmt->preadFunction = preadMockPower;
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
zes_power_energy_counter_t energyCounter = {};
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
ASSERT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getEnergyCounter(&energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
TEST_F(SysmanDevicePowerFixture, GivenSetPowerLimitsWhenGettingPowerLimitsWhenHwmonInterfaceExistThenLimitsSetEarlierAreRetrieved) {
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_sustained_limit_t sustainedSet = {};
zes_power_sustained_limit_t sustainedGet = {};
sustainedSet.enabled = 1;
sustainedSet.interval = 10;
sustainedSet.power = 300000;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
EXPECT_EQ(sustainedGet.power, sustainedSet.power);
EXPECT_EQ(sustainedGet.interval, sustainedSet.interval);
TEST_F(SysmanDevicePowerFixtureI915, GivenSetPowerLimitsWhenGettingPowerLimitsWhenHwmonInterfaceExistThenLimitsSetEarlierAreRetrieved) {
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
burstSet.power = 375000;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
EXPECT_EQ(burstSet.enabled, burstGet.enabled);
EXPECT_EQ(burstSet.power, burstGet.power);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_sustained_limit_t sustainedSet = {};
zes_power_sustained_limit_t sustainedGet = {};
sustainedSet.enabled = 1;
sustainedSet.interval = 10;
sustainedSet.power = 300000;
burstSet.enabled = 0;
burstGet.enabled = 0;
burstGet.power = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
EXPECT_EQ(burstSet.enabled, burstGet.enabled);
EXPECT_EQ(burstGet.power, 0);
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(&sustainedGet, nullptr, nullptr));
EXPECT_EQ(sustainedGet.power, sustainedSet.power);
EXPECT_EQ(sustainedGet.interval, sustainedSet.interval);
zes_power_peak_limit_t peakGet = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
EXPECT_EQ(peakGet.powerAC, -1);
EXPECT_EQ(peakGet.powerDC, -1);
}
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
burstSet.power = 375000;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(nullptr, &burstGet, nullptr));
EXPECT_EQ(burstSet.enabled, burstGet.enabled);
EXPECT_EQ(burstSet.power, burstGet.power);
burstSet.enabled = 0;
burstGet.enabled = 0;
burstGet.power = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(nullptr, &burstGet, nullptr));
EXPECT_EQ(burstSet.enabled, burstGet.enabled);
EXPECT_EQ(burstGet.power, 0);
zes_power_peak_limit_t peakGet = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(nullptr, nullptr, &peakGet));
EXPECT_EQ(peakGet.powerAC, -1);
EXPECT_EQ(peakGet.powerDC, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsReturnErrorWhenGettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenGetPowerLimitsReturnErrorWhenGettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesReturned) {
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
for (auto handle : handles) {
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
burstSet.power = 375000;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
}
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
burstSet.power = 375000;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimits(nullptr, &burstGet, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsReturnErrorWhenGettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesIsReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenGetPowerLimitsReturnErrorWhenGettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesIsReturned) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
pSysFsAccess->isRepeated = true;
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
burstSet.power = 375000;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
}
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
burstSet.power = 375000;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxPowerImp->getLimits(nullptr, &burstGet, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenSetPowerLimitsReturnErrorWhenSettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenSetPowerLimitsReturnErrorWhenSettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesReturned) {
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_burst_limit_t burstSet = {};
burstSet.enabled = 1;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
}
zes_power_burst_limit_t burstSet = {};
burstSet.enabled = 1;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenSetPowerLimitsReturnErrorWhenSettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitEnabledThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenSetPowerLimitsReturnErrorWhenSettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitEnabledThenProperErrorCodesReturned) {
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
}
zes_power_burst_limit_t burstSet = {};
zes_power_burst_limit_t burstGet = {};
burstSet.enabled = 1;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimits(nullptr, &burstGet, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerLimitNodeReturnErrorWhenSetOrGetPowerLimitsWhenHwmonInterfaceExistForSustainedPowerLimitEnabledThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenReadingSustainedPowerLimitNodeReturnErrorWhenSetOrGetPowerLimitsWhenHwmonInterfaceExistForSustainedPowerLimitEnabledThenProperErrorCodesReturned) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_sustained_limit_t sustainedSet = {};
zes_power_sustained_limit_t sustainedGet = {};
zes_power_sustained_limit_t sustainedSet = {};
zes_power_sustained_limit_t sustainedGet = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
}
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimits(&sustainedGet, nullptr, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenReadingSustainedPowerNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_sustained_limit_t sustainedGet = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
}
zes_power_sustained_limit_t sustainedGet = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimits(&sustainedGet, nullptr, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerIntervalNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenReadingSustainedPowerIntervalNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_sustained_limit_t sustainedGet = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
}
zes_power_sustained_limit_t sustainedGet = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimits(&sustainedGet, nullptr, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenwritingSustainedPowerNodeReturnErrorWhenSetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenwritingSustainedPowerNodeReturnErrorWhenSetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_sustained_limit_t sustainedSet = {};
sustainedSet.enabled = 1;
sustainedSet.interval = 10;
sustainedSet.power = 300000;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenwritingSustainedPowerIntervalNodeReturnErrorWhenSetPowerLimitsForSustainedPowerIntervalWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
TEST_F(SysmanDevicePowerFixtureI915, GivenwritingSustainedPowerIntervalNodeReturnErrorWhenSetPowerLimitsForSustainedPowerIntervalWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_sustained_limit_t sustainedSet = {};
sustainedSet.enabled = 1;
sustainedSet.interval = 10;
sustainedSet.power = 300000;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenWritingToSustainedPowerEnableNodeWithoutPermissionsThenValidErrorIsReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenWritingToSustainedPowerEnableNodeWithoutPermissionsThenValidErrorIsReturned) {
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_sustained_limit_t sustainedSet = {};
sustainedSet.enabled = 0;
EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndPermissionsThenFirstDisableSustainedPowerLimitAndThenEnableItAndCheckSuccesIsReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleAndPermissionsThenFirstDisableSustainedPowerLimitAndThenEnableItAndCheckSuccesIsReturned) {
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_sustained_limit_t sustainedSet = {};
zes_power_sustained_limit_t sustainedGet = {};
sustainedSet.enabled = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
sustainedSet.enabled = 1;
sustainedSet.interval = 10;
sustainedSet.power = 300000;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], &sustainedGet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(&sustainedSet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(&sustainedGet, nullptr, nullptr));
EXPECT_EQ(sustainedGet.enabled, sustainedSet.enabled);
EXPECT_EQ(sustainedGet.power, sustainedSet.power);
EXPECT_EQ(sustainedGet.interval, sustainedSet.interval);
}
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsWhenPowerLimitsAreDisabledWhenHwmonInterfaceExistThenAllPowerValuesAreIgnored) {
auto handles = getPowerHandles(powerHandleComponentCount);
TEST_F(SysmanDevicePowerFixtureI915, GivenGetPowerLimitsWhenPowerLimitsAreDisabledWhenHwmonInterfaceExistThenAllPowerValuesAreIgnored) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadUnsignedLongValue.push_back(0);
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
pSysFsAccess->mockReadUnsignedLongValue.push_back(0);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
zes_power_sustained_limit_t sustainedGet = {};
zes_power_burst_limit_t burstGet = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], &sustainedGet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(&sustainedGet, nullptr, nullptr));
EXPECT_EQ(sustainedGet.interval, 0);
EXPECT_EQ(sustainedGet.power, 0);
EXPECT_EQ(sustainedGet.enabled, 0);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], nullptr, &burstGet, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getLimits(nullptr, &burstGet, nullptr));
EXPECT_EQ(burstGet.enabled, 0);
EXPECT_EQ(burstGet.power, 0);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedGet, nullptr, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(&sustainedGet, nullptr, nullptr));
zes_power_burst_limit_t burstSet = {};
burstSet.enabled = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], nullptr, &burstSet, nullptr));
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->setLimits(nullptr, &burstSet, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenScanDirectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) {
TEST_F(SysmanDevicePowerFixtureI915, GivenScanDirectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -395,7 +430,7 @@ TEST_F(SysmanDevicePowerFixture, GivenScanDirectoriesFailAndPmtIsNotNullPointerT
delete pPowerImp;
}
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
TEST_F(SysmanDevicePowerFixtureI915, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -410,7 +445,7 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
EXPECT_EQ(count, powerHandleComponentCount);
}
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
TEST_F(SysmanDevicePowerFixtureI915, GivenInvalidComponentCountWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -429,7 +464,7 @@ TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerD
EXPECT_EQ(count, powerHandleComponentCount);
}
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidPowerHandlesIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidPowerHandlesIsReturned) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -450,83 +485,57 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesThenCallSucceeds) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesThenCallSucceeds) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
auto handles = getPowerHandles(powerHandleComponentCount);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->isPowerModuleSupported();
for (auto &handle : handles) {
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
}
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
auto handles = getPowerHandles(powerHandleComponentCount);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pPmt->preadFunction = preadMockPower;
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_energy_counter_t energyCounter;
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
zes_power_energy_counter_t energyCounter;
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
ASSERT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getEnergyCounter(&energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFileReturnsErrorAndPmtFailsThenFailureIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFileReturnsErrorAndPmtFailsThenFailureIsReturned) {
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = nullptr;
pLinuxPowerImp->isPowerModuleSupported();
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
for (auto &subDeviceIdToPmtEntry : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
delete subDeviceIdToPmtEntry.second;
}
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
uint32_t subdeviceId = 0;
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
do {
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, nullptr);
} while (++subdeviceId < subDeviceCount);
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetEnergyCounter(handle, &energyCounter));
}
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -543,7 +552,7 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThre
}
}
TEST_F(SysmanDevicePowerFixture, GivenScanDirectoriesFailAndPmtIsNullWhenGettingCardPowerThenReturnsFailure) {
TEST_F(SysmanDevicePowerFixtureI915, GivenScanDirectoriesFailAndPmtIsNullWhenGettingCardPowerThenReturnsFailure) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -565,7 +574,7 @@ TEST_F(SysmanDevicePowerFixture, GivenScanDirectoriesFailAndPmtIsNullWhenGetting
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenSettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
@@ -582,82 +591,76 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThre
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_sustained_limit_t sustained;
zes_power_burst_limit_t burst;
zes_power_peak_limit_t peak;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustained, &burst, &peak));
}
zes_power_sustained_limit_t sustained;
zes_power_burst_limit_t burst;
zes_power_peak_limit_t peak;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimits(&sustained, &burst, &peak));
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_sustained_limit_t sustained;
zes_power_burst_limit_t burst;
zes_power_peak_limit_t peak;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, &sustained, &burst, &peak));
}
zes_power_sustained_limit_t sustained;
zes_power_burst_limit_t burst;
zes_power_peak_limit_t peak;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimits(&sustained, &burst, &peak));
}
TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFailsThenValidPowerReadingsRetrievedFromPmt) {
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
pSysFsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysFsAccess->isRepeated = true;
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
auto handles = getPowerHandles(powerHandleComponentCount);
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pPmt->preadFunction = preadMockPower;
uint32_t subdeviceId = 0;
do {
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
pPmt->preadFunction = preadMockPower;
} while (++subdeviceId < subDeviceCount);
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
for (auto handle : handles) {
zes_power_energy_counter_t energyCounter;
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
zes_power_energy_counter_t energyCounter;
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
ASSERT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getEnergyCounter(&energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtWhenHwmonInterfaceExistThenUnsupportedFeatureIsReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
uint32_t limitCount = 0;
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtWhenHwmonInterfaceExistThenUnsupportedFeatureIsReturned) {
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &limitCount, nullptr));
}
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
uint32_t limitCount = 0;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getLimitsExt(&limitCount, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->setLimitsExt(&limitCount, nullptr));
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesExtThenApiReturnsFailure) {
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesExtThenApiReturnsFailure) {
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_properties_t properties = {};
@@ -669,22 +672,35 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesExtWithoutStypeThenExtPropertiesAreNotReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesExtWithoutStypeThenExtPropertiesAreNotReturned) {
properties.pNext = &extProperties;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
EXPECT_EQ(properties.defaultLimit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, static_cast<int32_t>(mockMinPowerLimitVal / milliFactor));
}
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
zes_power_properties_t properties = {};
zes_power_ext_properties_t extProperties = {};
properties.pNext = &extProperties;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
EXPECT_EQ(properties.defaultLimit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, static_cast<int32_t>(mockMinPowerLimitVal / milliFactor));
}
TEST_F(SysmanDevicePowerFixtureXe, GivenKmdInterfaceWhenGettingSysFsFilenamesForPowerForXeVersionThenProperPathsAreReturned) {
auto pSysmanKmdInterface = std::make_unique<SysmanKmdInterfaceXe>(pLinuxSysmanImp->getProductFamily());
EXPECT_STREQ("energy1_input", pSysmanKmdInterface->getSysfsFilePath(SysfsName::sysfsNameEnergyCounterNode, 0, false).c_str());
EXPECT_STREQ("power1_rated_max", pSysmanKmdInterface->getSysfsFilePath(SysfsName::sysfsNameDefaultPowerLimit, 0, false).c_str());
EXPECT_STREQ("power1_max", pSysmanKmdInterface->getSysfsFilePath(SysfsName::sysfsNameSustainedPowerLimit, 0, false).c_str());
EXPECT_STREQ("power1_max_interval", pSysmanKmdInterface->getSysfsFilePath(SysfsName::sysfsNameSustainedPowerLimitInterval, 0, false).c_str());
}
} // namespace ult

View File

@@ -11,16 +11,20 @@ namespace L0 {
namespace Sysman {
namespace ult {
constexpr uint32_t powerHandleComponentCount = 1u;
using SysmanDevicePowerFixtureHelper = SysmanDevicePowerFixture;
using SysmanDevicePowerFixtureHelper = SysmanDevicePowerFixtureI915;
TEST_F(SysmanDevicePowerFixtureHelper, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
zes_power_energy_counter_t energyCounter = {};
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
auto pSysFsAccess = std::make_unique<MockPowerSysfsAccessInterface>();
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysFsAccess.get();
pLinuxPowerImp->pPmt = pPmt;
pLinuxPowerImp->isPowerModuleSupported();
zes_power_energy_counter_t energyCounter = {};
ASSERT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getEnergyCounter(&energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
using SysmanDevicePowerMultiDeviceFixtureHelper = SysmanDevicePowerMultiDeviceFixture;