From 29254cb6835b0c263fc65181dff08baf2584dc47 Mon Sep 17 00:00:00 2001 From: Mayank Raghuwanshi Date: Fri, 20 Nov 2020 17:16:23 +0530 Subject: [PATCH] update case for zetSysmanProcessesGetState Signed-off-by: Mayank Raghuwanshi --- .../linux/os_global_operations_imp.cpp | 10 ++++++++ .../linux/mock_global_operations.h | 25 ++++++++++++++----- .../linux/test_zes_global_operations.cpp | 9 ++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp index f6ac032e35..9c9c4410b5 100644 --- a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp +++ b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp @@ -278,6 +278,16 @@ ze_result_t LinuxGlobalOperationsImp::scanProcessesState(std::vectorread(realClientPidPath, pid); + if (ZE_RESULT_SUCCESS != result) { + std::string bPidString; + result = pSysfsAccess->read(realClientPidPath, bPidString); + if (result == ZE_RESULT_SUCCESS) { + size_t start = bPidString.find("<"); + size_t end = bPidString.find(">"); + std::string bPid = bPidString.substr(start + 1, end - start - 1); + pid = std::stoull(bPid, nullptr, 10); + } + } if (ZE_RESULT_SUCCESS != result) { if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) { continue; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/mock_global_operations.h b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/mock_global_operations.h index f345f42084..b7fd8b76a9 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/mock_global_operations.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/mock_global_operations.h @@ -28,11 +28,15 @@ const std::string clientsDir("clients"); constexpr uint64_t pid1 = 1711u; constexpr uint64_t pid2 = 1722u; constexpr uint64_t pid3 = 1723u; +constexpr uint64_t pid4 = 1733u; +const std::string bPid4 = "<1733>"; constexpr uint64_t engineTimeSpent = 123456u; const std::string clientId1("4"); const std::string clientId2("5"); const std::string clientId3("6"); const std::string clientId4("7"); +const std::string clientId5("8"); +const std::string clientId6("10"); const std::string engine0("0"); const std::string engine1("1"); const std::string engine2("2"); @@ -66,6 +70,8 @@ struct Mock : public GlobalOperationsSysfsAccess { val = "0x3ea5"; } else if (file.compare(vendorFile) == 0) { val = "0x8086"; + } else if (file.compare("clients/8/pid") == 0) { + val = bPid4; } else { return ZE_RESULT_ERROR_NOT_AVAILABLE; } @@ -80,21 +86,25 @@ struct Mock : public GlobalOperationsSysfsAccess { } else if (file.compare("clients/7/pid") == 0) { val = pid3; } 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)) { + (file.compare("clients/5/busy/1") == 0) || (file.compare("clients/6/busy/0") == 0) || + (file.compare("clients/8/busy/1") == 0) || (file.compare("clients/8/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/7/busy/0") == 0) || (file.compare("clients/7/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)) { + (file.compare("clients/6/busy/2") == 0) || (file.compare("clients/6/busy/3") == 0) || + (file.compare("clients/8/busy/2") == 0) || (file.compare("clients/8/busy/3") == 0)) { val = 0; } else if ((file.compare("clients/4/total_device_memory_buffer_objects/created_bytes") == 0) || (file.compare("clients/5/total_device_memory_buffer_objects/created_bytes") == 0) || - (file.compare("clients/6/total_device_memory_buffer_objects/created_bytes") == 0)) { + (file.compare("clients/6/total_device_memory_buffer_objects/created_bytes") == 0) || + (file.compare("clients/8/total_device_memory_buffer_objects/created_bytes") == 0)) { val = 1024; } else if ((file.compare("clients/4/total_device_memory_buffer_objects/imported_bytes") == 0) || (file.compare("clients/5/total_device_memory_buffer_objects/imported_bytes") == 0) || - (file.compare("clients/6/total_device_memory_buffer_objects/imported_bytes") == 0)) { + (file.compare("clients/6/total_device_memory_buffer_objects/imported_bytes") == 0) || + (file.compare("clients/8/total_device_memory_buffer_objects/imported_bytes") == 0)) { val = 512; } else if (file.compare("clients/7/total_device_memory_buffer_objects/created_bytes") == 0) { return ZE_RESULT_ERROR_UNKNOWN; @@ -112,8 +122,10 @@ struct Mock : public GlobalOperationsSysfsAccess { list.push_back(clientId2); list.push_back(clientId3); list.push_back(clientId4); + list.push_back(clientId5); + list.push_back(clientId6); } else if ((path.compare("clients/4/busy") == 0) || (path.compare("clients/5/busy") == 0) || - (path.compare("clients/6/busy") == 0) || (path.compare("clients/7/busy") == 0)) { + (path.compare("clients/6/busy") == 0) || (path.compare("clients/7/busy") == 0) || (path.compare("clients/8/busy") == 0)) { list.push_back(engine0); list.push_back(engine1); list.push_back(engine2); @@ -129,8 +141,9 @@ struct Mock : public GlobalOperationsSysfsAccess { list.push_back(clientId1); list.push_back(clientId2); list.push_back(clientId3); + list.push_back(clientId5); } else if ((path.compare("clients/4/busy") == 0) || (path.compare("clients/5/busy") == 0) || - (path.compare("clients/6/busy") == 0)) { + (path.compare("clients/6/busy") == 0) || (path.compare("clients/8/busy") == 0)) { list.push_back(engine0); list.push_back(engine1); list.push_back(engine2); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp index 33bb2ce89d..c40c24d161 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp @@ -16,8 +16,10 @@ namespace ult { constexpr uint64_t memSize1 = 2048; constexpr uint64_t memSize2 = 1024; +constexpr uint64_t memSize4 = 1024; constexpr uint64_t sharedMemSize1 = 1024; constexpr uint64_t sharedMemSize2 = 512; +constexpr uint64_t sharedMemSize4 = 512; // In mock function getValUnsignedLong, we have set the engines used as 0, 3 and 1. // Hence, expecting 28 as engine field because 28 in binary would be 00011100 // This indicates bit number 2, 3 and 4 are set, thus this indicates, this process @@ -27,7 +29,8 @@ constexpr int64_t engines1 = 28u; // 4 in binary 0100, as 2nd bit is set, hence it indicates, process used ZES_ENGINE_TYPE_FLAG_3D // Corresponding i915 mapped value in mocked getValUnsignedLong() is 0. constexpr int64_t engines2 = 4u; -constexpr uint32_t totalProcessStates = 2u; // Two process States for two pids +constexpr int64_t engines4 = 20u; +constexpr uint32_t totalProcessStates = 3u; // Three process States for three pids const std::string expectedModelName("0x3ea5"); class SysmanGlobalOperationsFixture : public SysmanDeviceFixture { protected: @@ -155,6 +158,10 @@ TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhileRetrievingInfor EXPECT_EQ(processes[1].engines, engines2); EXPECT_EQ(processes[1].memSize, memSize2); EXPECT_EQ(processes[1].sharedSize, sharedMemSize2); + EXPECT_EQ(processes[2].processId, pid4); + EXPECT_EQ(processes[2].engines, engines4); + EXPECT_EQ(processes[2].memSize, memSize4); + EXPECT_EQ(processes[2].sharedSize, sharedMemSize4); } TEST_F(SysmanGlobalOperationsFixture, GivenValidDeviceHandleWhileRetrievingInformationAboutHostProcessesUsingFaultyClientFileThenFailureIsReturned) {