Remove gmock usage from PMT ULTs

Related-To: LOCI-3223

Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
Bellekallu Rajkiran 2022-08-23 12:25:26 +00:00 committed by Compute-Runtime-Automation
parent 13f1a61c34
commit 64626c0556
2 changed files with 57 additions and 66 deletions

View File

@ -22,6 +22,7 @@ const std::string realPathTelem2 = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a
const std::string realPathTelem3 = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem3";
const std::string realPathTelem4 = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem4";
const std::string realPathTelem5 = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem5";
const std::string invalidRealPath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8e:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1";
const std::string sysfsPahTelem1 = "/sys/class/intel_pmt/telem1";
const std::string sysfsPahTelem2 = "/sys/class/intel_pmt/telem2";
const std::string sysfsPahTelem3 = "/sys/class/intel_pmt/telem3";
@ -33,6 +34,14 @@ class PmtFsAccess : public FsAccess {};
template <>
struct Mock<PmtFsAccess> : public PmtFsAccess {
ze_result_t listDirectoryResult = ZE_RESULT_SUCCESS;
ze_result_t getRealPathResult = ZE_RESULT_SUCCESS;
ze_result_t readUnsignedResult = ZE_RESULT_SUCCESS;
ze_result_t readStringResult = ZE_RESULT_SUCCESS;
ze_bool_t returnTelemNodes = true;
ze_bool_t returnInvalidRealPath = false;
ze_bool_t readInvalidString = false;
Mock<PmtFsAccess>() {
baseTelemSysFSNodeForSubdevice0 = baseTelemSysFS + "/" + telemNodeForSubdevice0;
baseTelemSysFSNodeForSubdevice1 = baseTelemSysFS + "/" + telemNodeForSubdevice1;
@ -40,7 +49,16 @@ struct Mock<PmtFsAccess> : public PmtFsAccess {
telemetryDeviceEntryForSubdevice1 = baseTelemSysFSNodeForSubdevice1 + "/" + telem;
}
ze_result_t getValString(const std::string file, std::string &val) {
ze_result_t read(const std::string file, std::string &val) override {
if (readStringResult != ZE_RESULT_SUCCESS) {
return readStringResult;
}
if (readInvalidString) {
val = "";
return ZE_RESULT_SUCCESS;
}
std::string guidPathForSubdevice0 = baseTelemSysFSNodeForSubdevice0 + std::string("/guid");
std::string guidPathForSubdevice1 = baseTelemSysFSNodeForSubdevice1 + std::string("/guid");
if ((file.compare(guidPathForSubdevice0) == 0) ||
@ -51,7 +69,11 @@ struct Mock<PmtFsAccess> : public PmtFsAccess {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t getValUnsignedLong(const std::string file, uint64_t &val) {
ze_result_t read(const std::string file, uint64_t &val) override {
if (readUnsignedResult != ZE_RESULT_SUCCESS) {
return readUnsignedResult;
}
if ((file.compare(baseTelemSysFSNodeForSubdevice0 + std::string("/size")) == 0) ||
(file.compare(baseTelemSysFSNodeForSubdevice1 + std::string("/size")) == 0) ||
(file.compare(baseTelemSysFSNodeForSubdevice0 + std::string("/offset")) == 0) ||
@ -62,7 +84,7 @@ struct Mock<PmtFsAccess> : public PmtFsAccess {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
bool isFileExists(const std::string file) {
bool fileExists(const std::string file) override {
if ((file.compare(telemetryDeviceEntryForSubdevice0) == 0) ||
(file.compare(telemetryDeviceEntryForSubdevice1) == 0)) {
return true;
@ -71,7 +93,16 @@ struct Mock<PmtFsAccess> : public PmtFsAccess {
return false;
}
ze_result_t getRealPathSuccess(const std::string path, std::string &buf) {
ze_result_t getRealPath(const std::string path, std::string &buf) override {
if (getRealPathResult != ZE_RESULT_SUCCESS) {
return getRealPathResult;
}
if (returnInvalidRealPath) {
buf = invalidRealPath;
return ZE_RESULT_SUCCESS;
}
if (path.compare(sysfsPahTelem1) == 0) {
buf = realPathTelem1;
} else if (path.compare(sysfsPahTelem2) == 0) {
@ -89,35 +120,25 @@ struct Mock<PmtFsAccess> : public PmtFsAccess {
return ZE_RESULT_SUCCESS;
}
ze_result_t listDirectorySuccess(const std::string directory, std::vector<std::string> &listOfTelemNodes) {
ze_result_t listDirectory(const std::string directory, std::vector<std::string> &listOfTelemNodes) override {
if (listDirectoryResult != ZE_RESULT_SUCCESS) {
return listDirectoryResult;
}
if (directory.compare(baseTelemSysFS) == 0) {
listOfTelemNodes.push_back("crashlog2");
listOfTelemNodes.push_back("crashlog1");
listOfTelemNodes.push_back("telem3");
listOfTelemNodes.push_back("telem2");
listOfTelemNodes.push_back("telem1");
listOfTelemNodes.push_back("telem4");
listOfTelemNodes.push_back("telem5");
if (returnTelemNodes) {
listOfTelemNodes.push_back("telem3");
listOfTelemNodes.push_back("telem2");
listOfTelemNodes.push_back("telem1");
listOfTelemNodes.push_back("telem4");
listOfTelemNodes.push_back("telem5");
}
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t listDirectoryNoTelemNode(const std::string directory, std::vector<std::string> &listOfTelemNodes) {
if (directory.compare(baseTelemSysFS) == 0) {
listOfTelemNodes.push_back("crashlog2");
listOfTelemNodes.push_back("crashlog1");
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
MOCK_METHOD(ze_result_t, read, (const std::string file, std::string &val), (override));
MOCK_METHOD(ze_result_t, read, (const std::string file, uint64_t &val), (override));
MOCK_METHOD(ze_result_t, getRealPath, (const std::string path, std::string &buf), (override));
MOCK_METHOD(ze_result_t, listDirectory, (const std::string path, std::vector<std::string> &list), (override));
MOCK_METHOD(bool, fileExists, (const std::string file), (override));
std::string telemetryDeviceEntryForSubdevice0;
std::string telemetryDeviceEntryForSubdevice1;
std::string baseTelemSysFSNodeForSubdevice0;

View File

@ -40,17 +40,7 @@ class ZesPmtFixtureMultiDevice : public SysmanMultiDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pTestFsAccess = std::make_unique<NiceMock<Mock<PmtFsAccess>>>();
ON_CALL(*pTestFsAccess.get(), read(_, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::getValString));
ON_CALL(*pTestFsAccess.get(), read(_, Matcher<uint64_t &>(_)))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::getValUnsignedLong));
ON_CALL(*pTestFsAccess.get(), listDirectory(_, _))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::listDirectorySuccess));
ON_CALL(*pTestFsAccess.get(), getRealPath(_, _))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::getRealPathSuccess));
ON_CALL(*pTestFsAccess.get(), fileExists(_))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::isFileExists));
pTestFsAccess = std::make_unique<Mock<PmtFsAccess>>();
PlatformMonitoringTech::create(deviceHandles, pTestFsAccess.get(), gpuUpstreamPortPathInPmt, mapOfSubDeviceIdToPmtObject);
}
void TearDown() override {
@ -68,49 +58,41 @@ class ZesPmtFixtureMultiDevice : public SysmanMultiDeviceFixture {
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesThenValidPmtHandlesForAllSubdevicesWillBeCreated) {}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenenumerateRootTelemIndexThenCheckForErrorIflistDirectoryFails) {
EXPECT_CALL(*pTestFsAccess.get(), listDirectory(_, _))
.WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
pTestFsAccess->listDirectoryResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenenumerateRootTelemIndexThenCheckForErrorIfgetRealPathFails) {
EXPECT_CALL(*pTestFsAccess.get(), getRealPath(_, _))
.WillRepeatedly(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
pTestFsAccess->getRealPathResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenWhenenumerateRootTelemIndexThenCheckForErrorIfgetRealPathSuccessButNoTelemetryNodeAndGPUDeviceShareRootPciPort) {
EXPECT_CALL(*pTestFsAccess.get(), getRealPath(_, _))
.Times(5)
.WillRepeatedly(::testing::DoAll(::testing::SetArgReferee<1>("/sys/devices/pci0000:89/0000:89:02.0/0000:8e:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1"), Return(ZE_RESULT_SUCCESS)));
pTestFsAccess->returnInvalidRealPath = true;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenTelemDirectoryContainNowTelemEntryWhenenumerateRootTelemIndexThenCheckForError) {
ON_CALL(*pTestFsAccess.get(), listDirectory(_, _))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::listDirectoryNoTelemNode));
pTestFsAccess->returnTelemNodes = false;
EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt));
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesThenCheckForErrorThatCouldHappenDuringWhileValidatingTelemNode) {
EXPECT_CALL(*pTestFsAccess.get(), getRealPath(_, _))
.WillRepeatedly(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
pTestFsAccess->getRealPathResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt);
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesThenCheckForErrorThatCouldHappenDuringGUIDRead) {
EXPECT_CALL(*pTestFsAccess.get(), read(_, Matcher<std::string &>(_)))
.WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
pTestFsAccess->readStringResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt);
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt), ZE_RESULT_ERROR_NOT_AVAILABLE);
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesThenCheckForErrorIfGUIDReadValueIsNotSupported) {
EXPECT_CALL(*pTestFsAccess.get(), read(_, Matcher<std::string &>(_)))
.WillOnce(::testing::DoAll(::testing::SetArgReferee<1>(""), Return(ZE_RESULT_SUCCESS)));
pTestFsAccess->readInvalidString = true;
PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt);
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
@ -131,8 +113,7 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenSomeKeyWhenCallingreadValueWithUint32TypeT
}
TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesThenCheckForErrorThatCouldHappenDuringbaseOffsetRead) {
EXPECT_CALL(*pTestFsAccess.get(), read(_, Matcher<uint64_t &>(_)))
.WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
pTestFsAccess->readUnsignedResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), gpuUpstreamPortPathInPmt);
auto pPmt = std::make_unique<PublicPlatformMonitoringTech>(pTestFsAccess.get(), 1, 0);
EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt), ZE_RESULT_ERROR_NOT_AVAILABLE);
@ -255,8 +236,7 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenDoingPMTInitThenPMTmapOfS
TEST_F(ZesPmtFixtureMultiDevice, GivenBaseOffsetReadFailWhenDoingPMTInitThenPMTmapOfSubDeviceIdToPmtObjectWouldBeEmpty) {
std::map<uint32_t, L0::PlatformMonitoringTech *> mapOfSubDeviceIdToPmtObject;
EXPECT_CALL(*pTestFsAccess.get(), read(_, Matcher<uint64_t &>(_)))
.WillRepeatedly(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
pTestFsAccess->readUnsignedResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
for (const auto &deviceHandle : deviceHandles) {
ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES};
Device::fromHandle(deviceHandle)->getProperties(&deviceProperties);
@ -300,17 +280,7 @@ class ZesPmtFixtureNoSubDevice : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pTestFsAccess = std::make_unique<NiceMock<Mock<PmtFsAccess>>>();
ON_CALL(*pTestFsAccess.get(), read(_, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::getValString));
ON_CALL(*pTestFsAccess.get(), read(_, Matcher<uint64_t &>(_)))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::getValUnsignedLong));
ON_CALL(*pTestFsAccess.get(), listDirectory(_, _))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::listDirectorySuccess));
ON_CALL(*pTestFsAccess.get(), getRealPath(_, _))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::getRealPathSuccess));
ON_CALL(*pTestFsAccess.get(), fileExists(_))
.WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock<PmtFsAccess>::isFileExists));
pTestFsAccess = std::make_unique<Mock<PmtFsAccess>>();
PlatformMonitoringTech::create(deviceHandles, pTestFsAccess.get(), gpuUpstreamPortPathInPmt, mapOfSubDeviceIdToPmtObject);
}
void TearDown() override {