diff --git a/level_zero/tools/source/sysman/linux/fs_access.cpp b/level_zero/tools/source/sysman/linux/fs_access.cpp index 51fab819dd..624d72a379 100644 --- a/level_zero/tools/source/sysman/linux/fs_access.cpp +++ b/level_zero/tools/source/sysman/linux/fs_access.cpp @@ -22,7 +22,7 @@ static ze_result_t getResult(int err) { if ((EPERM == err) || (EACCES == err)) { return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS; } else if (ENOENT == err) { - return ZE_RESULT_ERROR_UNKNOWN; + return ZE_RESULT_ERROR_NOT_AVAILABLE; } else { return ZE_RESULT_ERROR_UNKNOWN; } @@ -172,7 +172,7 @@ ze_result_t FsAccess::listDirectory(const std::string path, std::vectord_name)); } ::closedir(procDir); + // Check if in above while loop, readdir encountered any error. + if (errno != 0) { + list.clear(); + return getResult(errno); + } return ZE_RESULT_SUCCESS; } diff --git a/level_zero/tools/source/sysman/sysman_device/linux/os_sysman_device_imp.cpp b/level_zero/tools/source/sysman/sysman_device/linux/os_sysman_device_imp.cpp index a59c7662dc..1f537d571f 100644 --- a/level_zero/tools/source/sysman/sysman_device/linux/os_sysman_device_imp.cpp +++ b/level_zero/tools/source/sysman/sysman_device/linux/os_sysman_device_imp.cpp @@ -244,7 +244,11 @@ ze_result_t LinuxSysmanDeviceImp::scanProcessesState(std::vectorread(realClientPidPath, pid); if (ZE_RESULT_SUCCESS != result) { - return result; + if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) { + continue; + } else { + return result; + } } // Traverse the clients//busy directory to get accelerator engines used by process @@ -252,7 +256,11 @@ ze_result_t LinuxSysmanDeviceImp::scanProcessesState(std::vectorscanDirEntries(busyDirForEngines, engineNums); if (ZE_RESULT_SUCCESS != result) { - return result; + if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) { + continue; + } else { + return result; + } } int64_t engineType = 0; // Scan all engine files present in /sys/class/drm/card0/clients//busy and check @@ -262,7 +270,11 @@ ze_result_t LinuxSysmanDeviceImp::scanProcessesState(std::vectorread(engine, timeSpent); if (ZE_RESULT_SUCCESS != result) { - return result; + if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) { + continue; + } else { + return result; + } } if (timeSpent > 0) { int i915EnginNumber = stoi(engineNum); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/mock_sysfs_sysman_device.h b/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/mock_sysfs_sysman_device.h index faa550b1f2..95da80aae1 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/mock_sysfs_sysman_device.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/mock_sysfs_sysman_device.h @@ -12,11 +12,6 @@ #include "sysman/linux/fs_access.h" #include "sysman/sysman.h" -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winconsistent-missing-override" -#endif - using ::testing::_; namespace L0 { @@ -50,12 +45,12 @@ struct Mock : public SysfsAccess { ze_result_t getValString(const std::string file, std::string &val) { if (file.compare(subsystemVendorFile) == 0) { val = "0x8086"; - } - if (file.compare(deviceFile) == 0) { + } else if (file.compare(deviceFile) == 0) { val = "0x3ea5"; - } - if (file.compare(vendorFile) == 0) { + } else if (file.compare(vendorFile) == 0) { val = "0x8086"; + } else { + return ZE_RESULT_ERROR_NOT_AVAILABLE; } return ZE_RESULT_SUCCESS; } @@ -63,12 +58,18 @@ struct Mock : public SysfsAccess { ze_result_t getValUnsignedLong(const std::string file, uint64_t &val) { if ((file.compare("clients/4/pid") == 0) || (file.compare("clients/5/pid") == 0)) { val = pid1; - } - if (file.compare("clients/6/pid") == 0) { + } else if (file.compare("clients/6/pid") == 0) { val = pid2; - } - if ((file.compare("clients/4/busy/0") == 0) || (file.compare("clients/4/busy/3") == 0) || (file.compare("clients/5/busy/1") == 0) || (file.compare("clients/6/busy/0") == 0)) { + } else if ((file.compare("clients/4/busy/0") == 0) || (file.compare("clients/4/busy/3") == 0) || + (file.compare("clients/5/busy/1") == 0) || (file.compare("clients/6/busy/0") == 0)) { val = engineTimeSpent; + } else if ((file.compare("clients/4/busy/1") == 0) || (file.compare("clients/4/busy/2") == 0) || + (file.compare("clients/5/busy/0") == 0) || (file.compare("clients/5/busy/2") == 0) || + (file.compare("clients/5/busy/3") == 0) || (file.compare("clients/6/busy/1") == 0) || + (file.compare("clients/6/busy/2") == 0) || (file.compare("clients/6/busy/3") == 0)) { + val = 0; + } else { + return ZE_RESULT_ERROR_NOT_AVAILABLE; } return ZE_RESULT_SUCCESS; } @@ -78,12 +79,14 @@ struct Mock : public SysfsAccess { list.push_back(clientId1); list.push_back(clientId2); list.push_back(clientId3); - } - if ((path.compare("clients/4/busy") == 0) || (path.compare("clients/5/busy") == 0) || (path.compare("clients/6/busy") == 0)) { + } else if ((path.compare("clients/4/busy") == 0) || (path.compare("clients/5/busy") == 0) || + (path.compare("clients/6/busy") == 0)) { list.push_back(engine0); list.push_back(engine1); list.push_back(engine2); list.push_back(engine3); + } else { + return ZE_RESULT_ERROR_NOT_AVAILABLE; } return ZE_RESULT_SUCCESS; } @@ -91,9 +94,9 @@ struct Mock : public SysfsAccess { Mock() = default; ~Mock() override = default; - MOCK_METHOD2(read, ze_result_t(const std::string file, std::string &val)); - MOCK_METHOD2(read, ze_result_t(const std::string file, uint64_t &val)); - MOCK_METHOD2(scanDirEntries, ze_result_t(const std::string path, std::vector &list)); + MOCK_METHOD(ze_result_t, read, (const std::string file, std::string &val), (override)); + MOCK_METHOD(ze_result_t, read, (const std::string file, uint64_t &val), (override)); + MOCK_METHOD(ze_result_t, scanDirEntries, (const std::string path, std::vector &list), (override)); }; class PublicLinuxSysmanDeviceImp : public L0::LinuxSysmanDeviceImp { @@ -103,8 +106,4 @@ class PublicLinuxSysmanDeviceImp : public L0::LinuxSysmanDeviceImp { }; } // namespace ult -} // namespace L0 - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif \ No newline at end of file +} // namespace L0 \ No newline at end of file diff --git a/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/test_sysman_device.cpp b/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/test_sysman_device.cpp index 6421045d05..fe086b996b 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/test_sysman_device.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/sysman_device/linux/test_sysman_device.cpp @@ -109,5 +109,10 @@ TEST_F(SysmanSysmanDeviceFixture, GivenValidSysmanHandleWhileRetrievingInformati EXPECT_EQ(processes[1].memSize, memSize2); } +TEST_F(SysmanSysmanDeviceFixture, GivenValidSysmanHandleWhileReadingNonExistingFileThenErrorIsReturned) { + std::vector engineEntries; + EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pSysfsAccess->scanDirEntries("clients/7/busy", engineEntries)); +} + } // namespace ult } // namespace L0 \ No newline at end of file