diff --git a/level_zero/sysman/source/linux/pmt/sysman_pmt.cpp b/level_zero/sysman/source/linux/pmt/sysman_pmt.cpp index 575b2b0979..88dab57b3b 100644 --- a/level_zero/sysman/source/linux/pmt/sysman_pmt.cpp +++ b/level_zero/sysman/source/linux/pmt/sysman_pmt.cpp @@ -8,6 +8,7 @@ #include "level_zero/sysman/source/linux/pmt/sysman_pmt.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/os_interface/linux/file_descriptor.h" #include "level_zero/sysman/source/linux/zes_os_sysman_imp.h" #include "level_zero/sysman/source/sysman_device_imp.h" @@ -32,7 +33,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v if (offset == keyOffsetMap.end()) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } - int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY); + int fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY); if (fd == -1) { return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } @@ -41,11 +42,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v if (this->preadFunction(fd, &value, sizeof(uint32_t), baseOffset + offset->second) != sizeof(uint32_t)) { res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } - - if (this->closeFunction(fd) < 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return res; } @@ -54,7 +50,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v if (offset == keyOffsetMap.end()) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } - int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY); + int fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY); if (fd == -1) { return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } @@ -63,11 +59,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v if (this->preadFunction(fd, &value, sizeof(uint64_t), baseOffset + offset->second) != sizeof(uint64_t)) { res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } - - if (this->closeFunction(fd) < 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return res; } diff --git a/level_zero/sysman/source/linux/pmt/sysman_pmt.h b/level_zero/sysman/source/linux/pmt/sysman_pmt.h index 05443213ed..fb1514bde6 100644 --- a/level_zero/sysman/source/linux/pmt/sysman_pmt.h +++ b/level_zero/sysman/source/linux/pmt/sysman_pmt.h @@ -44,8 +44,6 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass { ze_result_t init(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, PRODUCT_FAMILY productFamily); static void doInitPmtObject(FsAccess *pFsAccess, uint32_t subdeviceId, PlatformMonitoringTech *pPmt, const std::string &gpuUpstreamPortPath, std::map &mapOfSubDeviceIdToPmtObject, PRODUCT_FAMILY productFamily); - decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open; - decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close; decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread; private: diff --git a/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.cpp b/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.cpp index daa3a239e8..6a4f4a0a1e 100644 --- a/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.cpp +++ b/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.cpp @@ -8,6 +8,7 @@ #include "level_zero/sysman/source/pci/linux/sysman_os_pci_imp.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/os_interface/linux/file_descriptor.h" #include "shared/source/utilities/directory.h" #include "level_zero/sysman/source/linux/sysman_fs_access.h" @@ -294,7 +295,7 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector & } int fd = -1; - fd = this->openFunction(pciPath.c_str(), O_RDONLY); + fd = NEO::FileDescriptor(pciPath.c_str(), O_RDONLY); if (fd < 0) { NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config File Open Failed \n", __FUNCTION__); return false; @@ -303,10 +304,6 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector & NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config Mem Read Failed \n", __FUNCTION__); return false; } - if (this->closeFunction(fd) < 0) { - NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config file close Failed \n", __FUNCTION__); - return false; - } return true; } diff --git a/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.h b/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.h index 0b472760f6..d6bbf0a9de 100644 --- a/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.h +++ b/level_zero/sysman/source/pci/linux/sysman_os_pci_imp.h @@ -40,8 +40,6 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass { L0::Sysman::SysfsAccess *pSysfsAccess = nullptr; L0::Sysman::LinuxSysmanImp *pLinuxSysmanImp = nullptr; bool getPciConfigMemory(std::string pciPath, std::vector &configMem); - decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open; - decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close; decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread; private: diff --git a/level_zero/sysman/test/unit_tests/sources/linux/pmt/mock_pmt.h b/level_zero/sysman/test/unit_tests/sources/linux/pmt/mock_pmt.h index 600b9f8aab..ccd18a2be2 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/pmt/mock_pmt.h +++ b/level_zero/sysman/test/unit_tests/sources/linux/pmt/mock_pmt.h @@ -146,11 +146,9 @@ struct MockPmtFsAccess : public L0::Sysman::FsAccess { class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { public: PublicPlatformMonitoringTech(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - using PlatformMonitoringTech::closeFunction; using PlatformMonitoringTech::doInitPmtObject; using PlatformMonitoringTech::init; using PlatformMonitoringTech::keyOffsetMap; - using PlatformMonitoringTech::openFunction; using PlatformMonitoringTech::preadFunction; using PlatformMonitoringTech::rootDeviceTelemNodeIndex; using PlatformMonitoringTech::telemetryDeviceEntry; diff --git a/level_zero/sysman/test/unit_tests/sources/linux/pmt/test_pmt.cpp b/level_zero/sysman/test/unit_tests/sources/linux/pmt/test_pmt.cpp index 8f429b04ba..d3ab985b65 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/pmt/test_pmt.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/pmt/test_pmt.cpp @@ -13,8 +13,6 @@ namespace L0 { namespace Sysman { namespace ult { -static int fakeFileDescriptor = 123; - const std::map dummyKeyOffsetMap = { {"DUMMY_KEY", 0x0}}; @@ -104,32 +102,12 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesTh EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt, productFamily), ZE_RESULT_ERROR_NOT_AVAILABLE); } -inline static int openMock(const char *pathname, int flags) { - if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) { - return fakeFileDescriptor; - } - if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) { - return fakeFileDescriptor; - } - return -1; -} - inline static int openMockReturnFailure(const char *pathname, int flags) { return -1; } -inline static int closeMock(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - -inline static int closeMockReturnFailure(int fd) { - return -1; -} - ssize_t preadMockPmt(int fd, void *buf, size_t count, off_t offset) { + *reinterpret_cast(buf) = 3u; return count; } @@ -139,52 +117,37 @@ ssize_t preadMockPmtFailure(int fd, void *buf, size_t count, off_t offset) { TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndOpenSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->openFunction = openMockReturnFailure; + VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); + VariableBackup preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt); uint32_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val)); } -TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndCloseSysCallFailsThenreadValueFails) { +TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint32TypeThenSuccessIsReturned) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; - pPmt->preadFunction = preadMockPmt; - pPmt->closeFunction = closeMockReturnFailure; + VariableBackup preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt); uint32_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val)); + EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val)); + EXPECT_EQ(val, 3u); } TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndOpenSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->openFunction = openMockReturnFailure; + VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); uint64_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val)); } -TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndCloseSysCallFailsThenreadValueFails) { - auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; - pPmt->preadFunction = preadMockPmt; - pPmt->closeFunction = closeMockReturnFailure; - - uint64_t val = 0; - pPmt->keyOffsetMap = dummyKeyOffsetMap; - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val)); -} - TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndPreadSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; pPmt->preadFunction = preadMockPmtFailure; - pPmt->closeFunction = closeMock; uint32_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; @@ -194,9 +157,7 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint3 TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndPreadSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; pPmt->preadFunction = preadMockPmtFailure; - pPmt->closeFunction = closeMock; uint64_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; diff --git a/level_zero/sysman/test/unit_tests/sources/pci/linux/mock_sysfs_pci.h b/level_zero/sysman/test/unit_tests/sources/pci/linux/mock_sysfs_pci.h index b040fcbd2f..a7c7315fc7 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/linux/mock_sysfs_pci.h +++ b/level_zero/sysman/test/unit_tests/sources/pci/linux/mock_sysfs_pci.h @@ -95,8 +95,6 @@ struct MockPciSysfsAccess : public L0::Sysman::SysfsAccess { class PublicLinuxPciImp : public L0::Sysman::LinuxPciImp { public: PublicLinuxPciImp(L0::Sysman::OsSysman *pOsSysman) : L0::Sysman::LinuxPciImp(pOsSysman) {} - using L0::Sysman::LinuxPciImp::closeFunction; - using L0::Sysman::LinuxPciImp::openFunction; using L0::Sysman::LinuxPciImp::preadFunction; using L0::Sysman::LinuxPciImp::pSysfsAccess; }; diff --git a/level_zero/sysman/test/unit_tests/sources/pci/linux/test_zes_pci.cpp b/level_zero/sysman/test/unit_tests/sources/pci/linux/test_zes_pci.cpp index fb69bcbf29..88e38ec26a 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/linux/test_zes_pci.cpp +++ b/level_zero/sysman/test/unit_tests/sources/pci/linux/test_zes_pci.cpp @@ -25,31 +25,11 @@ constexpr int convertMegabitsPerSecondToBytesPerSecond = 125000; constexpr int convertGigabitToMegabit = 1000; constexpr double encodingGen1Gen2 = 0.8; constexpr double encodingGen3andAbove = 0.98461538461; -static int fakeFileDescriptor = 123; - -inline static int openMock(const char *pathname, int flags) { - if ((strcmp(pathname, mockRealPathConfig.c_str()) == 0) || (strcmp(pathname, mockRealPath2LevelsUpConfig.c_str()) == 0)) { - return fakeFileDescriptor; - } - - return -1; -} inline static int openMockReturnFailure(const char *pathname, int flags) { return -1; } -inline static int closeMock(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - -inline static int closeMockReturnFailure(int fd) { - return -1; -} - ssize_t preadMock(int fd, void *buf, size_t count, off_t offset) { uint8_t *mockBuf = static_cast(buf); // Sample config values @@ -237,8 +217,6 @@ class ZesPciFixture : public SysmanDeviceFixture { pOsPciPrev = pPciImp->pOsPci; pPciImp->pOsPci = nullptr; PublicLinuxPciImp *pLinuxPciImp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImp->openFunction = openMock; - pLinuxPciImp->closeFunction = closeMock; pLinuxPciImp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImp); @@ -289,8 +267,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetS zes_pci_properties_t properties, propertiesBefore; L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -343,8 +319,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndCapabilityL double speed = 0; L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockInvalidPos; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -362,8 +336,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIExpressC double speed = 0; L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockLoop; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -381,8 +353,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndUserIsNonRo double speed = 0; L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMock; pSysfsAccess->isRootUserResult = false; @@ -402,27 +372,7 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigOpenFailsT double speed = 0; L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMockReturnFailure; - pLinuxPciImpTemp->closeFunction = closeMock; - pLinuxPciImpTemp->preadFunction = preadMock; - - pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); - pPciImp->pciGetStaticFields(); - pPciImp->pOsPci->getMaxLinkCaps(speed, width); - EXPECT_EQ(width, -1); - EXPECT_EQ(speed, 0); - - delete pLinuxPciImpTemp; - pPciImp->pOsPci = pOsPciOriginal; -} - -TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigCloseFailsThenInvalidSpeedAndWidthAreReturned) { - int32_t width = 0; - double speed = 0; - L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; - PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMockReturnFailure; + VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); pLinuxPciImpTemp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -440,8 +390,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIHeaderIs double speed = 0; L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -478,8 +426,7 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenFailsThenResizableBarSupportWillBeFalse) { L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMockReturnFailure; - pLinuxPciImpTemp->closeFunction = closeMock; + VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); pLinuxPciImpTemp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -494,8 +441,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadFailsThenResizableBarSupportWillBeFalse) { L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockFailure; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -510,8 +455,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadF TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderFieldNotPresentThenResizableBarSupportFalseReturned) { L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -526,8 +469,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderF TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabilityLinkListIsBrokenThenResizableBarSupportFalseReturned) { L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockInvalidPos; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -542,8 +483,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabil TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndIfRebarCapabilityNotPresentThenResizableBarSupportFalseReturned) { L0::Sysman::OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockLoop; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); diff --git a/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h b/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h index 0c5e80df58..a47463e6d4 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h +++ b/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h @@ -284,9 +284,7 @@ struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess { }; struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech { - using L0::Sysman::PlatformMonitoringTech::closeFunction; using L0::Sysman::PlatformMonitoringTech::keyOffsetMap; - using L0::Sysman::PlatformMonitoringTech::openFunction; using L0::Sysman::PlatformMonitoringTech::preadFunction; using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry; diff --git a/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power_prelim.h b/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power_prelim.h index 3f90da774c..e425fcb96c 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power_prelim.h +++ b/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power_prelim.h @@ -218,9 +218,7 @@ struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess { struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech { MockPowerPmt(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - using L0::Sysman::PlatformMonitoringTech::closeFunction; using L0::Sysman::PlatformMonitoringTech::keyOffsetMap; - using L0::Sysman::PlatformMonitoringTech::openFunction; using L0::Sysman::PlatformMonitoringTech::preadFunction; using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry; ~MockPowerPmt() override { diff --git a/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp b/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp index 00ba2c8150..2c44ed774a 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp +++ b/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp @@ -11,27 +11,9 @@ namespace L0 { namespace Sysman { namespace ult { -static int fakeFileDescriptor = 123; constexpr uint64_t convertJouleToMicroJoule = 1000000u; constexpr uint32_t powerHandleComponentCount = 1u; -inline static int openMockPower(const char *pathname, int flags) { - if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) { - return fakeFileDescriptor; - } - if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) { - return fakeFileDescriptor; - } - return -1; -} - -inline static int closeMockPower(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) { uint64_t *mockBuf = static_cast(buf); *mockBuf = setEnergyCounter; @@ -183,8 +165,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun uint32_t subdeviceId = 0; do { auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } while (++subdeviceId < subDeviceCount); @@ -506,8 +486,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun uint32_t subdeviceId = 0; do { auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } while (++subdeviceId < subDeviceCount); @@ -658,8 +636,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe uint32_t subdeviceId = 0; do { auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } while (++subdeviceId < subDeviceCount); diff --git a/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power_prelim.cpp b/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power_prelim.cpp index 74270c25f5..11dadbcb45 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power_prelim.cpp +++ b/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power_prelim.cpp @@ -11,27 +11,9 @@ namespace L0 { namespace Sysman { namespace ult { -static int fakeFileDescriptor = 123; constexpr uint64_t convertJouleToMicroJoule = 1000000u; constexpr uint32_t powerHandleComponentCount = 1u; -inline static int openMockPower(const char *pathname, int flags) { - if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) { - return fakeFileDescriptor; - } - if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) { - return fakeFileDescriptor; - } - return -1; -} - -inline static int closeMockPower(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) { uint64_t *mockBuf = static_cast(buf); *mockBuf = setEnergyCounter; @@ -190,8 +172,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun uint32_t subdeviceId = 0; do { auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } while (++subdeviceId < subDeviceCount); @@ -666,8 +646,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun uint32_t subdeviceId = 0; do { auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } while (++subdeviceId < subDeviceCount); @@ -778,8 +756,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe uint32_t subdeviceId = 0; do { auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } while (++subdeviceId < subDeviceCount); diff --git a/level_zero/sysman/test/unit_tests/sources/temperature/linux/mock_sysfs_temperature.h b/level_zero/sysman/test/unit_tests/sources/temperature/linux/mock_sysfs_temperature.h index 2c79fcdce9..ca975157b2 100644 --- a/level_zero/sysman/test/unit_tests/sources/temperature/linux/mock_sysfs_temperature.h +++ b/level_zero/sysman/test/unit_tests/sources/temperature/linux/mock_sysfs_temperature.h @@ -44,9 +44,7 @@ const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5"; struct MockTemperaturePmt : public L0::Sysman::PlatformMonitoringTech { MockTemperaturePmt(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - using L0::Sysman::PlatformMonitoringTech::closeFunction; using L0::Sysman::PlatformMonitoringTech::keyOffsetMap; - using L0::Sysman::PlatformMonitoringTech::openFunction; using L0::Sysman::PlatformMonitoringTech::preadFunction; using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry; @@ -175,4 +173,4 @@ class PublicLinuxTemperatureImp : public L0::Sysman::LinuxTemperatureImp { } // namespace ult } // namespace Sysman -} // namespace L0 \ No newline at end of file +} // namespace L0 diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp index 205b36adfd..0e10d8ae80 100644 --- a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp +++ b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp @@ -9,6 +9,7 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/helpers/debug_helpers.h" +#include "shared/source/os_interface/linux/file_descriptor.h" #include "level_zero/tools/source/sysman/sysman_imp.h" @@ -31,7 +32,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v if (offset == keyOffsetMap.end()) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } - int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY); + int fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY); if (fd == -1) { return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } @@ -40,11 +41,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &v if (this->preadFunction(fd, &value, sizeof(uint32_t), baseOffset + offset->second) != sizeof(uint32_t)) { res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } - - if (this->closeFunction(fd) < 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return res; } @@ -53,7 +49,7 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v if (offset == keyOffsetMap.end()) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } - int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY); + int fd = NEO::FileDescriptor(telemetryDeviceEntry.c_str(), O_RDONLY); if (fd == -1) { return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } @@ -63,10 +59,6 @@ ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &v res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE; } - if (this->closeFunction(fd) < 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return res; } diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt.h b/level_zero/tools/source/sysman/linux/pmt/pmt.h index e0ab07d25c..16d87779ee 100644 --- a/level_zero/tools/source/sysman/linux/pmt/pmt.h +++ b/level_zero/tools/source/sysman/linux/pmt/pmt.h @@ -42,8 +42,6 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass { ze_result_t init(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, PRODUCT_FAMILY productFamily); static void doInitPmtObject(FsAccess *pFsAccess, uint32_t subdeviceId, PlatformMonitoringTech *pPmt, const std::string &gpuUpstreamPortPath, std::map &mapOfSubDeviceIdToPmtObject, PRODUCT_FAMILY productFamily); - decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open; - decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close; decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread; private: diff --git a/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h b/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h index b221d3def8..0c032cd5bb 100644 --- a/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h +++ b/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h @@ -37,8 +37,6 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass { SysfsAccess *pSysfsAccess = nullptr; LinuxSysmanImp *pLinuxSysmanImp = nullptr; bool getPciConfigMemory(std::string pciPath, std::vector &configMem); - decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open; - decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close; decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread; private: diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h index 5aa66a2688..0b11590136 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h @@ -145,11 +145,9 @@ struct MockPmtFsAccess : public FsAccess { class PublicPlatformMonitoringTech : public L0::PlatformMonitoringTech { public: PublicPlatformMonitoringTech(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - using PlatformMonitoringTech::closeFunction; using PlatformMonitoringTech::doInitPmtObject; using PlatformMonitoringTech::init; using PlatformMonitoringTech::keyOffsetMap; - using PlatformMonitoringTech::openFunction; using PlatformMonitoringTech::preadFunction; using PlatformMonitoringTech::telemetryDeviceEntry; }; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp index b4df210559..8637c8aa06 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp @@ -5,6 +5,8 @@ * */ +#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h" + #include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h" #include "mock_pmt.h" @@ -13,7 +15,6 @@ extern bool sysmanUltsEnable; namespace L0 { namespace ult { -static int fakeFileDescriptor = 123; const std::map dummyKeyOffsetMap = { {"DUMMY_KEY", 0x0}}; @@ -119,32 +120,12 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesTh EXPECT_EQ(pPmt->init(pTestFsAccess.get(), gpuUpstreamPortPathInPmt, productFamily), ZE_RESULT_ERROR_NOT_AVAILABLE); } -inline static int openMock(const char *pathname, int flags) { - if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) { - return fakeFileDescriptor; - } - if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) { - return fakeFileDescriptor; - } - return -1; -} - inline static int openMockReturnFailure(const char *pathname, int flags) { return -1; } -inline static int closeMock(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - -inline static int closeMockReturnFailure(int fd) { - return -1; -} - ssize_t preadMockPmt(int fd, void *buf, size_t count, off_t offset) { + *reinterpret_cast(buf) = 3u; return count; } @@ -154,52 +135,37 @@ ssize_t preadMockPmtFailure(int fd, void *buf, size_t count, off_t offset) { TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndOpenSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->openFunction = openMockReturnFailure; + VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); + VariableBackup preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt); uint32_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val)); } -TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndCloseSysCallFailsThenreadValueFails) { +TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingReadValueWithUint32TypeThenSuccessIsReturned) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; - pPmt->preadFunction = preadMockPmt; - pPmt->closeFunction = closeMockReturnFailure; + VariableBackup preadBackup(&NEO::SysCalls::sysCallsPread, preadMockPmt); uint32_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val)); + EXPECT_EQ(ZE_RESULT_SUCCESS, pPmt->readValue("DUMMY_KEY", val)); + EXPECT_EQ(val, 3u); } TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndOpenSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->openFunction = openMockReturnFailure; + VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); uint64_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, pPmt->readValue("DUMMY_KEY", val)); } -TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndCloseSysCallFailsThenreadValueFails) { - auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); - pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; - pPmt->preadFunction = preadMockPmt; - pPmt->closeFunction = closeMockReturnFailure; - - uint64_t val = 0; - pPmt->keyOffsetMap = dummyKeyOffsetMap; - EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pPmt->readValue("DUMMY_KEY", val)); -} - TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint32TypeAndPreadSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; pPmt->preadFunction = preadMockPmtFailure; - pPmt->closeFunction = closeMock; uint32_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; @@ -209,9 +175,7 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint3 TEST_F(ZesPmtFixtureMultiDevice, GivenValidSyscallsWhenCallingreadValueWithUint64TypeAndPreadSysCallFailsThenreadValueFails) { auto pPmt = std::make_unique(pTestFsAccess.get(), 1, 0); pPmt->telemetryDeviceEntry = baseTelemSysFS + "/" + telemNodeForSubdevice0 + "/" + telem; - pPmt->openFunction = openMock; pPmt->preadFunction = preadMockPmtFailure; - pPmt->closeFunction = closeMock; uint64_t val = 0; pPmt->keyOffsetMap = dummyKeyOffsetMap; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/mock_sysfs_pci.h b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/mock_sysfs_pci.h index bcd14462b1..342bda7569 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/mock_sysfs_pci.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/mock_sysfs_pci.h @@ -92,8 +92,6 @@ struct MockPciSysfsAccess : public SysfsAccess { class PublicLinuxPciImp : public L0::LinuxPciImp { public: PublicLinuxPciImp(OsSysman *pOsSysman) : LinuxPciImp(pOsSysman) {} - using LinuxPciImp::closeFunction; - using LinuxPciImp::openFunction; using LinuxPciImp::preadFunction; using LinuxPciImp::pSysfsAccess; }; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp index 8761aa0258..e0b171d049 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp @@ -30,27 +30,11 @@ constexpr int convertMegabitsPerSecondToBytesPerSecond = 125000; constexpr int convertGigabitToMegabit = 1000; constexpr double encodingGen1Gen2 = 0.8; constexpr double encodingGen3andAbove = 0.98461538461; -static int fakeFileDescriptor = 123; - -inline static int openMock(const char *pathname, int flags) { - if ((strcmp(pathname, mockRealPathConfig.c_str()) == 0) || (strcmp(pathname, mockRealPath2LevelsUpConfig.c_str()) == 0)) { - return fakeFileDescriptor; - } - - return -1; -} inline static int openMockReturnFailure(const char *pathname, int flags) { return -1; } -inline static int closeMock(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - ssize_t preadMock(int fd, void *buf, size_t count, off_t offset) { uint8_t *mockBuf = static_cast(buf); // Sample config values @@ -252,8 +236,6 @@ class ZesPciFixture : public SysmanDeviceFixture { pPciImp->pOsPci = nullptr; memoryManager->localMemorySupported[0] = 0; PublicLinuxPciImp *pLinuxPciImp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImp->openFunction = openMock; - pLinuxPciImp->closeFunction = closeMock; pLinuxPciImp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImp); @@ -314,8 +296,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetS memoryManager->localMemorySupported[0] = 1; OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -369,8 +349,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndCapabilityL memoryManager->localMemorySupported[0] = 1; OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockInvalidPos; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -389,8 +367,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndUserIsNonRo memoryManager->localMemorySupported[0] = 1; OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMock; pSysfsAccess->isRootUserResult = false; @@ -411,8 +387,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIExpressC memoryManager->localMemorySupported[0] = 1; OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockLoop; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -432,7 +406,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigOpenFailsT OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -451,9 +424,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIHeaderIs memoryManager->localMemorySupported[0] = 1; OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; - pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); pPciImp->pciGetStaticFields(); @@ -490,7 +460,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); VariableBackup openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure); - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMock; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -505,8 +474,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadFailsThenResizableBarSupportWillBeFalse) { OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockFailure; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -521,8 +488,6 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadF TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderFieldNotPresentThenResizableBarSupportFalseReturned) { OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockHeaderFailure; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -537,8 +502,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderF TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabilityLinkListIsBrokenThenResizableBarSupportFalseReturned) { OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockInvalidPos; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); @@ -553,8 +516,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabil TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndIfRebarCapabilityNotPresentThenResizableBarSupportFalseReturned) { OsPci *pOsPciOriginal = pPciImp->pOsPci; PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman); - pLinuxPciImpTemp->openFunction = openMock; - pLinuxPciImpTemp->closeFunction = closeMock; pLinuxPciImpTemp->preadFunction = preadMockLoop; pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h index e13d79b2e1..01810251ff 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power.h @@ -282,9 +282,7 @@ struct MockPowerSysfsAccess : public SysfsAccess { }; struct MockPowerPmt : public PlatformMonitoringTech { - using PlatformMonitoringTech::closeFunction; using PlatformMonitoringTech::keyOffsetMap; - using PlatformMonitoringTech::openFunction; using PlatformMonitoringTech::preadFunction; using PlatformMonitoringTech::telemetryDeviceEntry; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power_prelim.h b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power_prelim.h index b37a261fe8..9b289c477a 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power_prelim.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/mock_sysfs_power_prelim.h @@ -216,9 +216,7 @@ struct MockPowerSysfsAccess : public SysfsAccess { struct MockPowerPmt : public PlatformMonitoringTech { MockPowerPmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - using PlatformMonitoringTech::closeFunction; using PlatformMonitoringTech::keyOffsetMap; - using PlatformMonitoringTech::openFunction; using PlatformMonitoringTech::preadFunction; using PlatformMonitoringTech::telemetryDeviceEntry; ~MockPowerPmt() override { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp index 0aa637c394..a9697cdbd0 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power.cpp @@ -11,27 +11,9 @@ namespace L0 { namespace ult { -static int fakeFileDescriptor = 123; constexpr uint64_t convertJouleToMicroJoule = 1000000u; constexpr uint32_t powerHandleComponentCount = 1u; -inline static int openMockPower(const char *pathname, int flags) { - if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) { - return fakeFileDescriptor; - } - if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) { - return fakeFileDescriptor; - } - return -1; -} - -inline static int closeMockPower(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) { uint64_t *mockBuf = static_cast(buf); *mockBuf = setEnergyCounter; @@ -184,8 +166,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } @@ -507,8 +487,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } @@ -657,8 +635,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp index 00d776f499..35cfe274ad 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp @@ -11,27 +11,9 @@ namespace L0 { namespace ult { -static int fakeFileDescriptor = 123; constexpr uint64_t convertJouleToMicroJoule = 1000000u; constexpr uint32_t powerHandleComponentCount = 1u; -inline static int openMockPower(const char *pathname, int flags) { - if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) { - return fakeFileDescriptor; - } - if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) { - return fakeFileDescriptor; - } - return -1; -} - -inline static int closeMockPower(int fd) { - if (fd == fakeFileDescriptor) { - return 0; - } - return -1; -} - ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) { uint64_t *mockBuf = static_cast(buf); *mockBuf = setEnergyCounter; @@ -191,8 +173,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } @@ -666,8 +646,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCoun ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } @@ -776,8 +754,6 @@ TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowe ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(deviceProperties.subdeviceId)); - pPmt->openFunction = openMockPower; - pPmt->closeFunction = closeMockPower; pPmt->preadFunction = preadMockPower; } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h b/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h index f6f883658d..8a3ce03809 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h @@ -41,9 +41,7 @@ const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5"; struct MockTemperaturePmt : public PlatformMonitoringTech { MockTemperaturePmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - using PlatformMonitoringTech::closeFunction; using PlatformMonitoringTech::keyOffsetMap; - using PlatformMonitoringTech::openFunction; using PlatformMonitoringTech::preadFunction; using PlatformMonitoringTech::telemetryDeviceEntry; @@ -170,4 +168,4 @@ class PublicLinuxTemperatureImp : public L0::LinuxTemperatureImp { using LinuxTemperatureImp::type; }; } // namespace ult -} // namespace L0 \ No newline at end of file +} // namespace L0