sysman: add ULT to check Device Reset

Signed-off-by: Vilvaraj, T J Vivek <t.j.vivek.vilvaraj@intel.com>
This commit is contained in:
Vilvaraj, T J Vivek
2021-03-10 14:07:45 +05:30
committed by Compute-Runtime-Automation
parent 457d05420d
commit 9ed68131c3
3 changed files with 56 additions and 2 deletions

View File

@@ -278,6 +278,7 @@ ze_result_t LinuxGlobalOperationsImp::scanProcessesState(std::vector<zes_process
std::string realClientPidPath = clientsDir + "/" + clientId + "/" + "pid";
uint64_t pid;
result = pSysfsAccess->read(realClientPidPath, pid);
if (ZE_RESULT_SUCCESS != result) {
std::string bPidString;
result = pSysfsAccess->read(realClientPidPath, bPidString);
@@ -288,20 +289,29 @@ ze_result_t LinuxGlobalOperationsImp::scanProcessesState(std::vector<zes_process
pid = std::stoull(bPid, nullptr, 10);
}
}
if (ZE_RESULT_SUCCESS != result) {
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
//update the result as Success as ZE_RESULT_ERROR_NOT_AVAILABLE is expected if the "realClientPidPath" folder is empty
//this condition(when encountered) must not prevent the information accumulated for other clientIds
//this situation occurs when there is no call modifying result,
result = ZE_RESULT_SUCCESS;
continue;
} else {
return result;
}
}
// Traverse the clients/<clientId>/busy directory to get accelerator engines used by process
std::vector<std::string> engineNums;
std::string busyDirForEngines = clientsDir + "/" + clientId + "/" + "busy";
result = pSysfsAccess->scanDirEntries(busyDirForEngines, engineNums);
if (ZE_RESULT_SUCCESS != result) {
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
//update the result as Success as ZE_RESULT_ERROR_NOT_AVAILABLE is expected if the "realClientPidPath" folder is empty
//this condition(when encountered) must not prevent the information accumulated for other clientIds
//this situation occurs when there is no call modifying result,
//Here its seen when the last element of clientIds returns ZE_RESULT_ERROR_NOT_AVAILABLE for some reason.
result = ZE_RESULT_SUCCESS;
continue;
} else {
return result;
@@ -339,6 +349,7 @@ ze_result_t LinuxGlobalOperationsImp::scanProcessesState(std::vector<zes_process
result = pSysfsAccess->read(realClientTotalMemoryPath, memSize);
if (ZE_RESULT_SUCCESS != result) {
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
result = ZE_RESULT_SUCCESS;
continue;
} else {
return result;
@@ -350,6 +361,7 @@ ze_result_t LinuxGlobalOperationsImp::scanProcessesState(std::vector<zes_process
result = pSysfsAccess->read(realClientTotalSharedMemoryPath, sharedMemSize);
if (ZE_RESULT_SUCCESS != result) {
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
result = ZE_RESULT_SUCCESS;
continue;
} else {
return result;

View File

@@ -271,6 +271,12 @@ struct Mock<GlobalOperationsProcfsAccess> : public GlobalOperationsProcfsAccess
return ZE_RESULT_SUCCESS;
}
ze_result_t getMockFileDescriptorsFailure(const ::pid_t pid, std::vector<int> &list) {
//return failure to verify the error condition check
list.clear();
return ZE_RESULT_ERROR_UNKNOWN;
}
ze_result_t getMockFileName(const ::pid_t pid, const int fd, std::string &val) {
if (pid == ourDevicePid && fd == ourDeviceFd) {
val = mockDeviceName;

View File

@@ -190,7 +190,7 @@ TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhileRetrievingInfor
TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhileRetrievingInformationAboutHostProcessesUsingDeviceThenSuccessIsReturnedEvenwithFaultyClient) {
uint32_t count = 0;
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::getScannedDirEntries));
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::getScannedDir4Entries));
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::getValUnsignedLongCreatedBytesSuccess));
@@ -515,5 +515,41 @@ TEST_F(SysmanGlobalOperationsFixture, GivenProcessWontDieWhenCallingResetThenZeR
EXPECT_EQ(ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, result);
}
TEST_F(SysmanGlobalOperationsFixture, GivenProcessStartsMidResetWhenCallingResetAndGetFileDescriptorsFailsThenSuccessIsReturned) {
// Pretend another process has the device open
pProcfsAccess->ourDevicePid = getpid() + 1; // make sure it isn't our process id
pProcfsAccess->ourDeviceFd = pProcfsAccess->extraFd;
ON_CALL(*pSysfsAccess.get(), getRealPath(_, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::getRealPathVal));
ON_CALL(*pFsAccess.get(), canWrite(Matcher<std::string>(mockFunctionResetPath)))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<GlobalOperationsFsAccess>::getSuccess));
// Return process list without open fd on first call, but with open fd on subsequent calls
ON_CALL(*pProcfsAccess.get(), listProcesses(Matcher<std::vector<::pid_t> &>(_)))
.WillByDefault(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::mockProcessListDeviceInUse));
ON_CALL(*pProcfsAccess.get(), isAlive(_))
.WillByDefault(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::mockIsAlive));
ON_CALL(*pProcfsAccess.get(), myProcessId())
.WillByDefault(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::getMockMyProcessId));
EXPECT_CALL(*pProcfsAccess.get(), getFileDescriptors(_, Matcher<std::vector<int> &>(_)))
.WillOnce(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::getMockFileDescriptorsFailure))
.WillRepeatedly(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::getMockFileDescriptors));
ON_CALL(*pProcfsAccess.get(), getFileName(_, _, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::getMockFileNameReturnError));
ON_CALL(*pSysfsAccess.get(), isMyDeviceFile(_))
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::mockIsMyDeviceFile));
ON_CALL(*pProcfsAccess.get(), kill(pProcfsAccess->ourDevicePid))
.WillByDefault(::testing::Invoke(pProcfsAccess.get(), &Mock<GlobalOperationsProcfsAccess>::mockKill));
EXPECT_CALL(*pSysfsAccess.get(), unbindDevice(_))
.WillOnce(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::mockDeviceOpSuccess));
EXPECT_CALL(*pFsAccess.get(), write(mockFunctionResetPath, std::string("1")))
.WillOnce(::testing::Invoke(pFsAccess.get(), &Mock<GlobalOperationsFsAccess>::writeSuccess));
EXPECT_CALL(*pSysfsAccess.get(), bindDevice(_))
.WillOnce(::testing::Invoke(pSysfsAccess.get(), &Mock<GlobalOperationsSysfsAccess>::mockDeviceOpSuccess));
pGlobalOperationsImp->init();
ze_result_t result = zesDeviceReset(device, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
}
} // namespace ult
} // namespace L0