fix: add FileDescriptor class to ensure file descriptor is closed
Related-To: NEO-9038 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
parent
c2d69e5857
commit
099a3f30e3
|
@ -12,6 +12,7 @@
|
|||
#include "shared/source/helpers/sleep.h"
|
||||
#include "shared/source/os_interface/driver_info.h"
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
#include "shared/source/os_interface/linux/file_descriptor.h"
|
||||
#include "shared/source/os_interface/linux/pci_path.h"
|
||||
#include "shared/source/os_interface/linux/system_info.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
|
@ -370,8 +371,7 @@ ze_result_t LinuxSysmanImp::resizeVfBar(uint8_t size) {
|
|||
std::string pciConfigNode;
|
||||
pciConfigNode = gtDevicePath + "/config";
|
||||
|
||||
int fdConfig = -1;
|
||||
fdConfig = this->openFunction(pciConfigNode.c_str(), O_RDWR);
|
||||
auto fdConfig = NEO::FileDescriptor(pciConfigNode.c_str(), O_RDWR);
|
||||
if (fdConfig < 0) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
|
||||
"Config node open failed\n");
|
||||
|
@ -397,11 +397,6 @@ ze_result_t LinuxSysmanImp::resizeVfBar(uint8_t size) {
|
|||
"Write to change VF bar size failed\n");
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
if (this->closeFunction(fdConfig) < 0) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
|
||||
"Config node close failed\n");
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -414,9 +409,8 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
|
|||
std::string rootPortPath;
|
||||
rootPortPath = getPciRootPortDirectoryPath(gtDevicePath);
|
||||
|
||||
int fd = 0;
|
||||
std::string configFilePath = rootPortPath + '/' + "config";
|
||||
fd = this->openFunction(configFilePath.c_str(), O_RDWR);
|
||||
auto fd = NEO::FileDescriptor(configFilePath.c_str(), O_RDWR);
|
||||
if (fd < 0) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
@ -458,11 +452,6 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
|
|||
}
|
||||
NEO::sleep(std::chrono::seconds(10)); // Sleep for 10seconds, allows the rescan to complete on all devices attached to the root port.
|
||||
|
||||
int ret = this->closeFunction(fd);
|
||||
if (ret < 0) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
// PCIe port driver uses the BIOS allocated VF bars on bootup. A known bug exists in pcie port driver
|
||||
// and is causing VF bar allocation failure in PCIe port driver after an SBR - https://bugzilla.kernel.org/show_bug.cgi?id=216795
|
||||
|
||||
|
|
|
@ -64,8 +64,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
|||
MOCKABLE_VIRTUAL ze_result_t osColdReset();
|
||||
ze_result_t gpuProcessCleanup();
|
||||
std::string getAddressFromPath(std::string &rootPortPath);
|
||||
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
|
||||
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
|
||||
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
|
||||
decltype(&NEO::SysCalls::pwrite) pwriteFunction = NEO::SysCalls::pwrite;
|
||||
ze_result_t createPmtHandles();
|
||||
|
|
|
@ -40,23 +40,6 @@ inline static int gtPciConfigOpenFail(const char *pathname, int flags) {
|
|||
}
|
||||
}
|
||||
|
||||
inline static int closeMockDiag(int fd) {
|
||||
if ((fd == mockFileDescriptor) || (fd == mockGtPciConfigFd)) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
inline static int closeMockDiagFail(int fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline static int mockGtConfigcloseFail(int fd) {
|
||||
if (fd == mockGtPciConfigFd) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t preadMockDiag(int fd, void *buf, size_t count, off_t offset) {
|
||||
uint8_t *mockBuf = static_cast<uint8_t *>(buf);
|
||||
if (fd == mockGtPciConfigFd) {
|
||||
|
@ -555,8 +538,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetThen
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -565,8 +547,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetThen
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtPciConfigOpenFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = gtPciConfigOpenFail;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, gtPciConfigOpenFail);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -575,8 +556,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndConfigHeaderIsInvalidThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = mockGtConfigPreadInvalid;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -585,8 +565,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigPreadFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = mockGtConfigPreadFail;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -595,28 +574,16 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigPwriteFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = mockGtConfigPwriteFail;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigCloseFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = mockGtConfigcloseFail;
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndCardBusRemoveFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -628,8 +595,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndRootPortRescanFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -641,8 +607,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetThenCallSucceeds) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -653,8 +618,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetfrom
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
pLinuxSysmanImp->diagnosticsReset = true;
|
||||
|
@ -666,8 +630,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetfrom
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
pLinuxSysmanImp->diagnosticsReset = true;
|
||||
|
@ -681,8 +644,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndDelayForPPRWhenCallin
|
|||
DebugManager.flags.DebugSetMemoryDiagnosticsDelay.set(7);
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
pLinuxSysmanImp->diagnosticsReset = true;
|
||||
|
@ -695,20 +657,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndR
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiagFail;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndRootPortConfigFileFailsToCloseThenCallFails) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiagFail;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiagFail);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -719,8 +668,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndC
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -732,8 +680,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndR
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "shared/source/helpers/sleep.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/source/os_interface/linux/file_descriptor.h"
|
||||
#include "shared/source/os_interface/linux/system_info.h"
|
||||
|
||||
#include "level_zero/core/source/device/device_imp.h"
|
||||
|
@ -391,8 +392,7 @@ ze_result_t LinuxSysmanImp::resizeVfBar(uint8_t size) {
|
|||
std::string pciConfigNode;
|
||||
pciConfigNode = gtDevicePath + "/config";
|
||||
|
||||
int fdConfig = -1;
|
||||
fdConfig = this->openFunction(pciConfigNode.c_str(), O_RDWR);
|
||||
auto fdConfig = NEO::FileDescriptor(pciConfigNode.c_str(), O_RDWR);
|
||||
if (fdConfig < 0) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
|
||||
"Config node open failed\n");
|
||||
|
@ -418,11 +418,6 @@ ze_result_t LinuxSysmanImp::resizeVfBar(uint8_t size) {
|
|||
"Write to change VF bar size failed\n");
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
if (this->closeFunction(fdConfig) < 0) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
|
||||
"Config node close failed\n");
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -435,9 +430,8 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
|
|||
std::string rootPortPath;
|
||||
rootPortPath = getPciRootPortDirectoryPath(gtDevicePath);
|
||||
|
||||
int fd = 0;
|
||||
std::string configFilePath = rootPortPath + '/' + "config";
|
||||
fd = this->openFunction(configFilePath.c_str(), O_RDWR);
|
||||
auto fd = NEO::FileDescriptor(configFilePath.c_str(), O_RDWR);
|
||||
if (fd < 0) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
@ -479,11 +473,6 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
|
|||
}
|
||||
NEO::sleep(std::chrono::seconds(10)); // Sleep for 10seconds, allows the rescan to complete on all devices attached to the root port.
|
||||
|
||||
int ret = this->closeFunction(fd);
|
||||
if (ret < 0) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
// PCIe port driver uses the BIOS allocated VF bars on bootup. A known bug exists in pcie port driver
|
||||
// and is causing VF bar allocation failure in PCIe port driver after an SBR - https://bugzilla.kernel.org/show_bug.cgi?id=216795
|
||||
|
||||
|
|
|
@ -75,8 +75,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
|||
MOCKABLE_VIRTUAL ze_result_t osColdReset();
|
||||
ze_result_t gpuProcessCleanup();
|
||||
std::string getAddressFromPath(std::string &rootPortPath);
|
||||
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
|
||||
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
|
||||
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
|
||||
decltype(&NEO::SysCalls::pwrite) pwriteFunction = NEO::SysCalls::pwrite;
|
||||
std::string devicePciBdf = "";
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
#include "shared/source/os_interface/linux/file_descriptor.h"
|
||||
#include "shared/source/utilities/directory.h"
|
||||
|
||||
#include "level_zero/core/source/driver/driver_handle.h"
|
||||
|
@ -294,8 +295,7 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &
|
|||
return false;
|
||||
}
|
||||
|
||||
int fd = -1;
|
||||
fd = this->openFunction(pciPath.c_str(), O_RDONLY);
|
||||
auto 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;
|
||||
|
@ -304,10 +304,6 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "shared/test/common/helpers/ult_hw_config.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h"
|
||||
|
||||
|
@ -40,23 +41,6 @@ inline static int gtPciConfigOpenFail(const char *pathname, int flags) {
|
|||
}
|
||||
}
|
||||
|
||||
inline static int closeMockDiag(int fd) {
|
||||
if ((fd == mockFileDescriptor) || (fd == mockGtPciConfigFd)) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
inline static int closeMockDiagFail(int fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline static int mockGtConfigcloseFail(int fd) {
|
||||
if (fd == mockGtPciConfigFd) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t preadMockDiag(int fd, void *buf, size_t count, off_t offset) {
|
||||
uint8_t *mockBuf = static_cast<uint8_t *>(buf);
|
||||
if (fd == mockGtPciConfigFd) {
|
||||
|
@ -592,8 +576,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetThen
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -602,8 +585,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetThen
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtPciConfigOpenFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = gtPciConfigOpenFail;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, gtPciConfigOpenFail);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -612,8 +594,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndConfigHeaderIsInvalidThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = mockGtConfigPreadInvalid;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -622,8 +603,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigPreadFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = mockGtConfigPreadFail;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -632,28 +612,16 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigPwriteFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = mockGtConfigPwriteFail;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigCloseFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = mockGtConfigcloseFail;
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndCardBusRemoveFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -665,8 +633,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndRootPortRescanFailsThenCallReturnsFailure) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -678,8 +645,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCal
|
|||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetThenCallSucceeds) {
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -690,8 +656,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetfrom
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
pLinuxSysmanImp->diagnosticsReset = true;
|
||||
|
@ -703,8 +668,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetfrom
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
pLinuxSysmanImp->diagnosticsReset = true;
|
||||
|
@ -718,8 +682,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndDelayForPPRWhenCallin
|
|||
DebugManager.flags.DebugSetMemoryDiagnosticsDelay.set(7);
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
pLinuxSysmanImp->diagnosticsReset = true;
|
||||
|
@ -732,20 +695,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndR
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiagFail;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndRootPortConfigFileFailsToCloseThenCallFails) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiagFail;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiagFail);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -756,8 +706,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndC
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
@ -769,8 +718,7 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndR
|
|||
DebugManagerStateRestore dbgRestore;
|
||||
DebugManager.flags.VfBarResourceAllocationWa.set(false);
|
||||
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
|
||||
pLinuxSysmanImp->openFunction = openMockDiag;
|
||||
pLinuxSysmanImp->closeFunction = closeMockDiag;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockDiag);
|
||||
pLinuxSysmanImp->preadFunction = preadMockDiag;
|
||||
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
|
||||
#include "level_zero/tools/source/sysman/pci/pci_utils.h"
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
|
||||
|
@ -49,10 +51,6 @@ inline static int closeMock(int fd) {
|
|||
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<uint8_t *>(buf);
|
||||
// Sample config values
|
||||
|
@ -433,7 +431,7 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigOpenFailsT
|
|||
memoryManager->localMemorySupported[0] = 1;
|
||||
OsPci *pOsPciOriginal = pPciImp->pOsPci;
|
||||
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
|
||||
pLinuxPciImpTemp->openFunction = openMockReturnFailure;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
|
||||
pLinuxPciImpTemp->closeFunction = closeMock;
|
||||
pLinuxPciImpTemp->preadFunction = preadMock;
|
||||
|
||||
|
@ -447,26 +445,6 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigOpenFailsT
|
|||
pPciImp->pOsPci = pOsPciOriginal;
|
||||
}
|
||||
|
||||
TEST_F(ZesPciFixture, GivenSysmanHandleWhenInitializingPciAndPciConfigCloseFailsThenInvalidSpeedAndWidthAreReturned) {
|
||||
int32_t width = 0;
|
||||
double speed = 0;
|
||||
memoryManager->localMemorySupported[0] = 1;
|
||||
OsPci *pOsPciOriginal = pPciImp->pOsPci;
|
||||
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
|
||||
pLinuxPciImpTemp->openFunction = openMock;
|
||||
pLinuxPciImpTemp->closeFunction = closeMockReturnFailure;
|
||||
pLinuxPciImpTemp->preadFunction = preadMock;
|
||||
|
||||
pPciImp->pOsPci = static_cast<OsPci *>(pLinuxPciImpTemp);
|
||||
pPciImp->pciGetStaticFields();
|
||||
pPciImp->pOsPci->getMaxLinkCaps(speed, width);
|
||||
EXPECT_EQ(width, -1);
|
||||
EXPECT_EQ(speed, 0);
|
||||
|
||||
delete pLinuxPciImpTemp;
|
||||
pPciImp->pOsPci = pOsPciOriginal;
|
||||
}
|
||||
|
||||
TEST_F(ZesPciFixture, GivenSysmanHandleWhenGettingPCIWidthAndSpeedAndPCIHeaderIsAbsentThenInvalidValuesAreReturned) {
|
||||
int32_t width = 0;
|
||||
double speed = 0;
|
||||
|
@ -511,7 +489,7 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe
|
|||
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenFailsThenResizableBarSupportWillBeFalse) {
|
||||
OsPci *pOsPciOriginal = pPciImp->pOsPci;
|
||||
PublicLinuxPciImp *pLinuxPciImpTemp = new PublicLinuxPciImp(pOsSysman);
|
||||
pLinuxPciImpTemp->openFunction = openMockReturnFailure;
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> openBackup(&NEO::SysCalls::sysCallsOpen, openMockReturnFailure);
|
||||
pLinuxPciImpTemp->closeFunction = closeMock;
|
||||
pLinuxPciImpTemp->preadFunction = preadMock;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/drm_wrappers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_wrappers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_drm.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_descriptor.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kmd_notify_properties_linux.cpp
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class FileDescriptor : NonCopyableOrMovableClass {
|
||||
public:
|
||||
FileDescriptor(const char *file, int flags) : handle(SysCalls::open(file, flags)) {}
|
||||
|
||||
~FileDescriptor() {
|
||||
if (handle >= 0) {
|
||||
[[maybe_unused]] auto retVal = SysCalls::close(handle);
|
||||
DEBUG_BREAK_IF(retVal != 0);
|
||||
}
|
||||
}
|
||||
operator int() const {
|
||||
return handle;
|
||||
}
|
||||
|
||||
protected:
|
||||
const int handle;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "shared/source/os_interface/linux/pmt_util.h"
|
||||
|
||||
#include "shared/source/os_interface/linux/file_descriptor.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
#include "shared/source/utilities/directory.h"
|
||||
|
||||
|
@ -53,13 +54,12 @@ void PmtUtil::getTelemNodesInPciPath(std::string_view rootPciPath, std::map<uint
|
|||
bool PmtUtil::readGuid(std::string_view telemDir, std::array<char, PmtUtil::guidStringSize> &guidString) {
|
||||
std::ostringstream guidFilename;
|
||||
guidFilename << telemDir << "/guid";
|
||||
int fd = SysCalls::open(guidFilename.str().c_str(), O_RDONLY);
|
||||
if (fd <= 0) {
|
||||
return false;
|
||||
auto fd = FileDescriptor(guidFilename.str().c_str(), O_RDONLY);
|
||||
ssize_t bytesRead = 0;
|
||||
if (fd > 0) {
|
||||
guidString.fill('\0');
|
||||
bytesRead = SysCalls::pread(fd, guidString.data(), guidString.size() - 1, 0);
|
||||
}
|
||||
guidString.fill('\0');
|
||||
ssize_t bytesRead = SysCalls::pread(fd, guidString.data(), guidString.size() - 1, 0);
|
||||
SysCalls::close(fd);
|
||||
if (bytesRead <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -71,18 +71,19 @@ bool PmtUtil::readOffset(std::string_view telemDir, uint64_t &offset) {
|
|||
|
||||
std::ostringstream offsetFilename;
|
||||
offsetFilename << telemDir << "/offset";
|
||||
int fd = SysCalls::open(offsetFilename.str().c_str(), O_RDONLY);
|
||||
if (fd <= 0) {
|
||||
auto fd = FileDescriptor(offsetFilename.str().c_str(), O_RDONLY);
|
||||
ssize_t bytesRead = 0;
|
||||
std::array<char, 16> offsetString = {'\0'};
|
||||
if (fd > 0) {
|
||||
offset = ULONG_MAX;
|
||||
bytesRead = SysCalls::pread(fd, offsetString.data(), offsetString.size() - 1, 0);
|
||||
}
|
||||
if (bytesRead <= 0) {
|
||||
return false;
|
||||
}
|
||||
offset = ULONG_MAX;
|
||||
std::array<char, 16> offsetString = {'\0'};
|
||||
ssize_t bytesRead = SysCalls::pread(fd, offsetString.data(), offsetString.size() - 1, 0);
|
||||
if (bytesRead > 0) {
|
||||
std::replace(offsetString.begin(), offsetString.end(), '\n', '\0');
|
||||
offset = std::strtoul(offsetString.data(), nullptr, 10);
|
||||
}
|
||||
SysCalls::close(fd);
|
||||
|
||||
std::replace(offsetString.begin(), offsetString.end(), '\n', '\0');
|
||||
offset = std::strtoul(offsetString.data(), nullptr, 10);
|
||||
|
||||
if (offset == ULONG_MAX) {
|
||||
return false;
|
||||
|
@ -99,10 +100,9 @@ ssize_t PmtUtil::readTelem(std::string_view telemDir, const std::size_t count, c
|
|||
ssize_t bytesRead = 0;
|
||||
std::ostringstream telemFilename;
|
||||
telemFilename << telemDir << "/telem";
|
||||
int fd = SysCalls::open(telemFilename.str().c_str(), O_RDONLY);
|
||||
auto fd = FileDescriptor(telemFilename.str().c_str(), O_RDONLY);
|
||||
if (fd > 0) {
|
||||
bytesRead = SysCalls::pread(fd, data, count, static_cast<off_t>(offset));
|
||||
SysCalls::close(fd);
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace NEO {
|
|||
namespace SysCalls {
|
||||
uint32_t closeFuncCalled = 0u;
|
||||
uint32_t openFuncCalled = 0u;
|
||||
int openFuncRetVal = 0;
|
||||
int closeFuncArgPassed = 0;
|
||||
int closeFuncRetVal = 0;
|
||||
int dlOpenFlags = 0;
|
||||
|
@ -145,7 +146,7 @@ int open(const char *file, int flags) {
|
|||
return fakeFileDescriptor;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return openFuncRetVal;
|
||||
}
|
||||
|
||||
int openWithMode(const char *file, int flags, int mode) {
|
||||
|
|
|
@ -48,6 +48,8 @@ extern int (*sysCallsClosedir)(DIR *dir);
|
|||
extern int (*sysCallsGetDevicePath)(int deviceFd, char *buf, size_t &bufSize);
|
||||
|
||||
extern int flockRetVal;
|
||||
extern int openFuncRetVal;
|
||||
extern uint32_t openFuncCalled;
|
||||
extern int closeFuncRetVal;
|
||||
extern int closeFuncArgPassed;
|
||||
extern const char *drmVersion;
|
||||
|
|
|
@ -35,6 +35,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_uuid_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_linux_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/product_helper_linux_tests.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_descriptor_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_interface_linux_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux_tests.cpp
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/file_descriptor.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(FileDescriptorTest, whenOpeningFileReturnsNonNegativeFileDescriptorThenCloseIsCalled) {
|
||||
int mockHandle = 12345;
|
||||
VariableBackup<decltype(SysCalls::openFuncRetVal)> openRetValBackup(&SysCalls::openFuncRetVal, mockHandle);
|
||||
VariableBackup<decltype(SysCalls::openFuncCalled)> openCalledBackup(&SysCalls::openFuncCalled, 0u);
|
||||
VariableBackup<decltype(SysCalls::closeFuncCalled)> closeCalledBackup(&SysCalls::closeFuncCalled, 0u);
|
||||
|
||||
{
|
||||
auto fileDescriptor = FileDescriptor("", 0);
|
||||
EXPECT_EQ(SysCalls::openFuncRetVal, fileDescriptor);
|
||||
EXPECT_EQ(1u, SysCalls::openFuncCalled);
|
||||
SysCalls::closeFuncArgPassed = 0;
|
||||
}
|
||||
EXPECT_EQ(1u, SysCalls::closeFuncCalled);
|
||||
EXPECT_EQ(SysCalls::openFuncRetVal, SysCalls::closeFuncArgPassed);
|
||||
|
||||
SysCalls::openFuncRetVal = -1;
|
||||
|
||||
{
|
||||
auto fileDescriptor = FileDescriptor("", 0);
|
||||
EXPECT_EQ(SysCalls::openFuncRetVal, fileDescriptor);
|
||||
EXPECT_EQ(2u, SysCalls::openFuncCalled);
|
||||
SysCalls::closeFuncArgPassed = 0;
|
||||
}
|
||||
|
||||
EXPECT_EQ(1u, SysCalls::closeFuncCalled);
|
||||
}
|
Loading…
Reference in New Issue