From 77649243875351f8d757c0db68e13cc0f120695e Mon Sep 17 00:00:00 2001 From: Pichika Uday Kiran Date: Wed, 24 Nov 2021 09:25:05 +0000 Subject: [PATCH] sysman: Avoid creating the IGSC libary handle in ULTs - Contains the changes to avoid invoking IGSC library during ULT execution. Related-To: LOCI-2719 Signed-off-by: Pichika Uday Kiran --- level_zero/CMakeLists.txt | 10 +++++++++- .../source/sysman/diagnostics/diagnostics.h | 4 ++-- .../tools/source/sysman/firmware/firmware.h | 4 ++-- .../linux/os_global_operations_imp.cpp | 1 - .../source/sysman/linux/os_sysman_imp.cpp | 6 +++--- .../linux/test_zes_sysman_firmware.cpp | 17 ---------------- .../linux/mock_global_operations.h | 20 +++++++++++++++++++ .../linux/test_zes_global_operations.cpp | 16 +++++++++++++++ .../sources/sysman/linux/test_sysman.cpp | 11 ---------- 9 files changed, 52 insertions(+), 37 deletions(-) diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index fb1bb80fcd..324a15021d 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -77,9 +77,17 @@ if(BUILD_WITH_L0) if(UNIX) # Firmware Update Library - find_package(igsc) + get_filename_component(IGSC_DIR_tmp "${NEO_SOURCE_DIR}/../igsc" ABSOLUTE) + if(EXISTS "${IGSC_DIR_tmp}/lib/cmake") + find_package(igsc HINTS "${IGSC_DIR_tmp}/lib/cmake") + else() + find_package(igsc) + endif() if(igsc_FOUND) add_definitions(-DIGSC_PRESENT=1) + if(EXISTS "${IGSC_DIR_tmp}/lib/cmake") + get_filename_component(igsc_INCLUDE_DIR "${NEO_SOURCE_DIR}/../igsc/include" ABSOLUTE) + endif() message(STATUS "igsc Library headers directory: ${igsc_INCLUDE_DIR}") message(STATUS "igsc version: ${igsc_VERSION}") include_directories(SYSTEM ${igsc_INCLUDE_DIR}) diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics.h b/level_zero/tools/source/sysman/diagnostics/diagnostics.h index f459d6bfae..dc627bb17d 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics.h +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics.h @@ -36,9 +36,9 @@ class Diagnostics : _zes_diag_handle_t { struct DiagnosticsHandleContext { DiagnosticsHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; void releaseDiagnosticsHandles(); - ~DiagnosticsHandleContext(); + MOCKABLE_VIRTUAL ~DiagnosticsHandleContext(); - void init(std::vector &deviceHandles); + MOCKABLE_VIRTUAL void init(std::vector &deviceHandles); ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics); std::vector supportedDiagTests = {}; diff --git a/level_zero/tools/source/sysman/firmware/firmware.h b/level_zero/tools/source/sysman/firmware/firmware.h index cf809e04d9..4071c062d5 100644 --- a/level_zero/tools/source/sysman/firmware/firmware.h +++ b/level_zero/tools/source/sysman/firmware/firmware.h @@ -35,10 +35,10 @@ class Firmware : _zes_firmware_handle_t { struct FirmwareHandleContext { FirmwareHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; - ~FirmwareHandleContext(); + MOCKABLE_VIRTUAL ~FirmwareHandleContext(); void releaseFwHandles(); - void init(); + MOCKABLE_VIRTUAL void init(); ze_result_t firmwareGet(uint32_t *pCount, zes_firmware_handle_t *phFirmware); 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 7a35718d2b..5c206f51f0 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 @@ -143,7 +143,6 @@ void LinuxGlobalOperationsImp::releaseDeviceResources() { void LinuxGlobalOperationsImp::reInitSysmanDeviceResources() { pLinuxSysmanImp->getSysmanDeviceImp()->updateSubDeviceHandlesLocally(); pLinuxSysmanImp->createPmtHandles(); - pLinuxSysmanImp->createFwUtilInterface(); pLinuxSysmanImp->getSysmanDeviceImp()->pRasHandleContext->init(pLinuxSysmanImp->getSysmanDeviceImp()->deviceHandles); pLinuxSysmanImp->getSysmanDeviceImp()->pEngineHandleContext->init(); pLinuxSysmanImp->getSysmanDeviceImp()->pDiagnosticsHandleContext->init(pLinuxSysmanImp->getSysmanDeviceImp()->deviceHandles); diff --git a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp index d7f18e43a3..e42f571caf 100644 --- a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp +++ b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp @@ -42,9 +42,6 @@ ze_result_t LinuxSysmanImp::init() { DEBUG_BREAK_IF(nullptr == pPmuInterface); - if (pFwUtilInterface == nullptr) { - createFwUtilInterface(); - } return createPmtHandles(); } @@ -75,6 +72,9 @@ PmuInterface *LinuxSysmanImp::getPmuInterface() { } FirmwareUtil *LinuxSysmanImp::getFwUtilInterface() { + if (pFwUtilInterface == nullptr) { + createFwUtilInterface(); + } return pFwUtilInterface; } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp index 9a292a25d5..41696a39f1 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp @@ -237,14 +237,6 @@ TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleFirmwareLibraryCallFailureWhe EXPECT_STREQ("unknown", properties.version); } -TEST_F(ZesFirmwareFixture, GivenFwUtilInterfaceNullWhenCreatingFirmwareImpThenIsFirmwareSupportedShouldFail) { - pLinuxSysmanImp->pFwUtilInterface = nullptr; - FirmwareImp *ptestFirmwareImp = new FirmwareImp(pSysmanDeviceImp->pFirmwareHandleContext->pOsSysman, mockSupportedFwTypes[0]); - EXPECT_EQ(nullptr, pLinuxSysmanImp->pFwUtilInterface); - delete ptestFirmwareImp; - pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface.get(); -} - class ZesFirmwareUninitializedFixture : public SysmanDeviceFixture { protected: @@ -278,14 +270,5 @@ class ZesFirmwareUninitializedFixture : public SysmanDeviceFixture { } }; -TEST_F(ZesFirmwareUninitializedFixture, GivenFirmwareLibraryMissingThenCreateHandleMustFail) { - for (const auto &handle : pSysmanDeviceImp->pFirmwareHandleContext->handleList) { - delete handle; - } - pSysmanDeviceImp->pFirmwareHandleContext->handleList.clear(); - pSysmanDeviceImp->pFirmwareHandleContext->init(); - EXPECT_EQ(0u, pSysmanDeviceImp->pFirmwareHandleContext->handleList.size()); -} - } // namespace ult } // namespace L0 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 cd28f3811d..cb1e206754 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 @@ -62,6 +62,26 @@ struct Mock : public GlobalOperationsEngine MOCK_METHOD(void, init, (), (override)); }; +struct GlobalOperationsDiagnosticsHandleContext : public DiagnosticsHandleContext { + GlobalOperationsDiagnosticsHandleContext(OsSysman *pOsSysman) : DiagnosticsHandleContext(pOsSysman) {} +}; +template <> +struct Mock : public GlobalOperationsDiagnosticsHandleContext { + void initMock(std::vector &deviceHandles) {} + Mock(OsSysman *pOsSysman) : GlobalOperationsDiagnosticsHandleContext(pOsSysman) {} + MOCK_METHOD(void, init, (std::vector & deviceHandles), (override)); +}; + +struct GlobalOperationsFirmwareHandleContext : public FirmwareHandleContext { + GlobalOperationsFirmwareHandleContext(OsSysman *pOsSysman) : FirmwareHandleContext(pOsSysman) {} +}; +template <> +struct Mock : public GlobalOperationsFirmwareHandleContext { + void initMock() {} + Mock(OsSysman *pOsSysman) : GlobalOperationsFirmwareHandleContext(pOsSysman) {} + MOCK_METHOD(void, init, (), (override)); +}; + class GlobalOperationsSysfsAccess : public SysfsAccess {}; template <> 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 26bd5bda11..c974774ffb 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 @@ -45,10 +45,14 @@ constexpr uint32_t totalProcessStatesForFaultyClients = 3u; class SysmanGlobalOperationsFixture : public SysmanDeviceFixture { protected: std::unique_ptr> pEngineHandleContext; + std::unique_ptr> pDiagnosticsHandleContext; + std::unique_ptr> pFirmwareHandleContext; std::unique_ptr> pSysfsAccess; std::unique_ptr> pProcfsAccess; std::unique_ptr> pFsAccess; EngineHandleContext *pEngineHandleContextOld = nullptr; + DiagnosticsHandleContext *pDiagnosticsHandleContextOld = nullptr; + FirmwareHandleContext *pFirmwareHandleContextOld = nullptr; SysfsAccess *pSysfsAccessOld = nullptr; ProcfsAccess *pProcfsAccessOld = nullptr; FsAccess *pFsAccessOld = nullptr; @@ -63,6 +67,8 @@ class SysmanGlobalOperationsFixture : public SysmanDeviceFixture { } SysmanDeviceFixture::SetUp(); pEngineHandleContextOld = pSysmanDeviceImp->pEngineHandleContext; + pDiagnosticsHandleContextOld = pSysmanDeviceImp->pDiagnosticsHandleContext; + pFirmwareHandleContextOld = pSysmanDeviceImp->pFirmwareHandleContext; pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; pProcfsAccessOld = pLinuxSysmanImp->pProcfsAccess; pFsAccessOld = pLinuxSysmanImp->pFsAccess; @@ -71,14 +77,22 @@ class SysmanGlobalOperationsFixture : public SysmanDeviceFixture { pSysfsAccess = std::make_unique>>(); pProcfsAccess = std::make_unique>>(); pFsAccess = std::make_unique>>(); + pDiagnosticsHandleContext = std::make_unique>>(pOsSysman); + pFirmwareHandleContext = std::make_unique>>(pOsSysman); pSysmanDeviceImp->pEngineHandleContext = pEngineHandleContext.get(); pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); pLinuxSysmanImp->pProcfsAccess = pProcfsAccess.get(); pLinuxSysmanImp->pFsAccess = pFsAccess.get(); + pSysmanDeviceImp->pDiagnosticsHandleContext = pDiagnosticsHandleContext.get(); + pSysmanDeviceImp->pFirmwareHandleContext = pFirmwareHandleContext.get(); ON_CALL(*pEngineHandleContext.get(), init()) .WillByDefault(::testing::Invoke(pEngineHandleContext.get(), &Mock::initMock)); + ON_CALL(*pDiagnosticsHandleContext.get(), init(_)) + .WillByDefault(::testing::Invoke(pDiagnosticsHandleContext.get(), &Mock::initMock)); + ON_CALL(*pFirmwareHandleContext.get(), init()) + .WillByDefault(::testing::Invoke(pFirmwareHandleContext.get(), &Mock::initMock)); ON_CALL(*pSysfsAccess.get(), read(_, Matcher(_))) .WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock::getValString)); ON_CALL(*pSysfsAccess.get(), read(_, Matcher(_))) @@ -124,6 +138,8 @@ class SysmanGlobalOperationsFixture : public SysmanDeviceFixture { pGlobalOperationsImp->pOsGlobalOperations = pOsGlobalOperationsPrev; pGlobalOperationsImp = nullptr; pSysmanDeviceImp->pEngineHandleContext = pEngineHandleContextOld; + pSysmanDeviceImp->pDiagnosticsHandleContext = pDiagnosticsHandleContextOld; + pSysmanDeviceImp->pFirmwareHandleContext = pFirmwareHandleContextOld; SysmanDeviceFixture::TearDown(); pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; pLinuxSysmanImp->pProcfsAccess = pProcfsAccessOld; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp index 3b7e439bbc..9a17c2fb45 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/test_sysman.cpp @@ -288,17 +288,6 @@ TEST_F(SysmanDeviceFixture, GivenPmuInterfaceHandleWhenCallinggetPmuInterfaceThe EXPECT_EQ(pLinuxSysmanImp->getPmuInterface(), pLinuxSysmanImp->pPmuInterface); } -TEST_F(SysmanDeviceFixture, GivenFwUtilInterfaceHandleWhenCallinggetFwUtilInterfaceThenCreatedFwUtilInterfaceHandleWillBeRetrieved) { - if (pLinuxSysmanImp->pFwUtilInterface != nullptr) { - //delete previously allocated FwUtilInterface - delete pLinuxSysmanImp->pFwUtilInterface; - pLinuxSysmanImp->pFwUtilInterface = nullptr; - } - const std::string mockBdf = "0000:00:02.0"; - pLinuxSysmanImp->pFwUtilInterface = FirmwareUtil::create(mockBdf); - EXPECT_EQ(pLinuxSysmanImp->getFwUtilInterface(), pLinuxSysmanImp->pFwUtilInterface); -} - TEST_F(SysmanDeviceFixture, GivenValidPciPathWhileGettingRootPciPortThenReturnedPathIs2LevelUpThenTheCurrentPath) { const std::string mockBdf = "0000:00:02.0"; const std::string mockRealPath = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/" + mockBdf;