Skip to content

Commit 908ddd0

Browse files
Removal of MOCK_METHODS from Sysman PCI API ULTs
The gmock macros in the PCI API ULTS have been replaced Related-To: LOCI-3217 Signed-off-by: Bari, Pratik <[email protected]>
1 parent da6dfa4 commit 908ddd0

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

level_zero/tools/test/unit_tests/sources/sysman/pci/linux/mock_sysfs_pci.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ class PciSysfsAccess : public SysfsAccess {};
4343

4444
template <>
4545
struct Mock<PciSysfsAccess> : public PciSysfsAccess {
46-
MOCK_METHOD(ze_result_t, read, (const std::string file, std::vector<std::string> &val), (override));
47-
MOCK_METHOD(ze_result_t, readSymLink, (const std::string file, std::string &buf), (override));
48-
MOCK_METHOD(ze_result_t, getRealPath, (const std::string file, std::string &buf), (override));
49-
MOCK_METHOD(bool, isRootUser, (), (override));
5046

51-
bool checkRootUser() {
47+
bool isStringSymLinkEmpty = false;
48+
49+
bool isRootUser() override {
5250
return true;
5351
}
5452

@@ -60,15 +58,21 @@ struct Mock<PciSysfsAccess> : public PciSysfsAccess {
6058
return ZE_RESULT_ERROR_NOT_AVAILABLE;
6159
}
6260

63-
ze_result_t getValStringSymLink(const std::string file, std::string &val) {
61+
ze_result_t readSymLink(const std::string file, std::string &val) override {
6462
if (file.compare(deviceDir) == 0) {
63+
64+
if (isStringSymLinkEmpty == true) {
65+
return getValStringSymLinkEmpty(file, val);
66+
}
67+
6568
val = mockBdf;
6669
return ZE_RESULT_SUCCESS;
6770
}
71+
6872
return ZE_RESULT_ERROR_NOT_AVAILABLE;
6973
}
7074

71-
ze_result_t getValStringRealPath(const std::string file, std::string &val) {
75+
ze_result_t getRealPath(const std::string file, std::string &val) override {
7276
if (file.compare(deviceDir) == 0) {
7377
val = mockRealPath;
7478
return ZE_RESULT_SUCCESS;
@@ -80,7 +84,7 @@ struct Mock<PciSysfsAccess> : public PciSysfsAccess {
8084
return ZE_RESULT_ERROR_NOT_AVAILABLE;
8185
}
8286

83-
ze_result_t getValVector(const std::string file, std::vector<std::string> &val) {
87+
ze_result_t read(const std::string file, std::vector<std::string> &val) override {
8488
if (file.compare(resourceFile) == 0) {
8589
val = mockReadBytes;
8690
return ZE_RESULT_SUCCESS;

level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,6 @@ class ZesPciFixture : public SysmanDeviceFixture {
251251
pOriginalSysfsAccess = pLinuxSysmanImp->pSysfsAccess;
252252
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
253253

254-
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<std::vector<std::string> &>(_)))
255-
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PciSysfsAccess>::getValVector));
256-
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
257-
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PciSysfsAccess>::getValStringSymLink));
258-
ON_CALL(*pSysfsAccess.get(), getRealPath(_, _))
259-
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PciSysfsAccess>::getValStringRealPath));
260-
ON_CALL(*pSysfsAccess.get(), isRootUser())
261-
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PciSysfsAccess>::checkRootUser));
262-
263254
pPciImp = static_cast<L0::PciImp *>(pSysmanDeviceImp->pPci);
264255
pOsPciPrev = pPciImp->pOsPci;
265256
pPciImp->pOsPci = nullptr;
@@ -369,8 +360,8 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetS
369360

370361
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropertiesAndBdfStringIsEmptyThenVerifyApiCallSucceeds) {
371362
zes_pci_properties_t properties;
372-
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
373-
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PciSysfsAccess>::getValStringSymLinkEmpty));
363+
364+
pSysfsAccess->isStringSymLinkEmpty = true;
374365

375366
ze_result_t result = zesDevicePciGetProperties(device, &properties);
376367

0 commit comments

Comments
 (0)