From 24a745f4bd5af67cbcc17d951d06691a78ee550c Mon Sep 17 00:00:00 2001 From: "Vilvaraj, T J Vivek" Date: Wed, 21 Apr 2021 04:12:31 +0000 Subject: [PATCH] sysman:add support for Diagnostis API. Signed-off-by: Vilvaraj, T J Vivek --- level_zero/CMakeLists.txt | 5 +- level_zero/api/sysman/zes_sysman.cpp | 4 +- .../source/sysman/diagnostics/diagnostics.cpp | 16 ++-- .../source/sysman/diagnostics/diagnostics.h | 7 +- .../sysman/diagnostics/diagnostics_imp.cpp | 13 +-- .../sysman/diagnostics/diagnostics_imp.h | 6 +- .../sysman/diagnostics/linux/CMakeLists.txt | 1 + .../linux/os_diagnostics_helper.cpp | 20 +++++ .../diagnostics/linux/os_diagnostics_imp.cpp | 30 ++++--- .../diagnostics/linux/os_diagnostics_imp.h | 12 ++- .../sysman/diagnostics/os_diagnostics.h | 7 +- .../windows/os_diagnostics_imp.cpp | 19 +++-- .../diagnostics/windows/os_diagnostics_imp.h | 3 +- .../sysman/linux/firmware_util/CMakeLists.txt | 12 +-- .../linux/firmware_util/firmware_util.h | 2 + .../linux/firmware_util/firmware_util_imp.cpp | 1 - .../linux/firmware_util/firmware_util_imp.h | 2 + .../firmware_util_imp_helper.cpp | 8 ++ .../test/black_box_tests/zello_sysman.cpp | 70 +++++++++++++++- .../sysman/diagnostics/linux/CMakeLists.txt | 2 +- .../linux/mock_zes_sysman_diagnostics.h | 41 +++++++--- .../linux/test_zes_sysman_diagnostics.cpp | 80 +++++++++++++++---- .../firmware/linux/mock_zes_sysman_firmware.h | 2 + .../linux/mock_global_operations.h | 2 + 24 files changed, 286 insertions(+), 79 deletions(-) create mode 100644 level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_helper.cpp diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index 13dda09833..e2d0956e73 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -88,9 +88,8 @@ if(BUILD_WITH_L0) # Firmware Update Library list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/source/sysman/linux/firmware_util${BRANCH_DIR_SUFFIX}") find_package(libigsc) - if(libigsc_LIBRARIES) - set(libigsc_FOUND TRUE) - add_definitions(-DIGSC_PRESENT=$(libigsc_FOUND)) + if(libigsc_FOUND) + add_definitions(-DIGSC_PRESENT=1) message(STATUS "libigsc Library headers directory: ${libigsc_INCLUDE_DIR}") message(STATUS "libigsc version: ${libigsc_VERSION}") else() diff --git a/level_zero/api/sysman/zes_sysman.cpp b/level_zero/api/sysman/zes_sysman.cpp index 1e1a7a504f..3fa39ab630 100644 --- a/level_zero/api/sysman/zes_sysman.cpp +++ b/level_zero/api/sysman/zes_sysman.cpp @@ -700,7 +700,7 @@ zesDiagnosticsGetTests( zes_diag_handle_t hDiagnostics, uint32_t *pCount, zes_diag_test_t *pTests) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetTests(pCount, pTests); } ZE_APIEXPORT ze_result_t ZE_APICALL @@ -709,7 +709,7 @@ zesDiagnosticsRunTests( uint32_t start, uint32_t end, zes_diag_result_t *pResult) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsRunTests(start, end, pResult); } ZE_APIEXPORT ze_result_t ZE_APICALL diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp b/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp index f67523e755..e3b58e3a6c 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp @@ -18,17 +18,17 @@ DiagnosticsHandleContext::~DiagnosticsHandleContext() { handleList.clear(); } -void DiagnosticsHandleContext::createHandle() { - Diagnostics *pDiagnostics = new DiagnosticsImp(pOsSysman); - if (pDiagnostics->isDiagnosticsEnabled == true) { - handleList.push_back(pDiagnostics); - } else { - delete pDiagnostics; - } +void DiagnosticsHandleContext::createHandle(const std::string &diagTests) { + Diagnostics *pDiagnostics = new DiagnosticsImp(pOsSysman, diagTests); + handleList.push_back(pDiagnostics); } void DiagnosticsHandleContext::init() { - createHandle(); + + OsDiagnostics::getSupportedDiagTests(supportedDiagTests, pOsSysman); + for (const std::string &diagTests : supportedDiagTests) { + createHandle(diagTests); + } } ze_result_t DiagnosticsHandleContext::diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) { diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics.h b/level_zero/tools/source/sysman/diagnostics/diagnostics.h index 2cbe22f4b3..f1ecda12e3 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics.h +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics.h @@ -23,12 +23,13 @@ class Diagnostics : _zes_diag_handle_t { public: virtual ~Diagnostics() {} virtual ze_result_t diagnosticsGetProperties(zes_diag_properties_t *pProperties) = 0; + virtual ze_result_t diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) = 0; + virtual ze_result_t diagnosticsRunTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) = 0; inline zes_diag_handle_t toHandle() { return this; } static Diagnostics *fromHandle(zes_diag_handle_t handle) { return static_cast(handle); } - bool isDiagnosticsEnabled = false; }; struct DiagnosticsHandleContext { @@ -38,12 +39,12 @@ struct DiagnosticsHandleContext { void init(); ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics); - + std::vector supportedDiagTests = {}; OsSysman *pOsSysman = nullptr; std::vector handleList = {}; private: - void createHandle(); + void createHandle(const std::string &DiagTests); }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.cpp b/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.cpp index cb01ed871a..8c6ac71a98 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.cpp +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.cpp @@ -20,14 +20,17 @@ ze_result_t DiagnosticsImp::diagnosticsGetProperties(zes_diag_properties_t *pPro return ZE_RESULT_SUCCESS; } -void DiagnosticsImp::init() { - this->isDiagnosticsEnabled = pOsDiagnostics->isDiagnosticsSupported(); +ze_result_t DiagnosticsImp::diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) { + return pOsDiagnostics->osGetDiagTests(pCount, pTests); } -DiagnosticsImp::DiagnosticsImp(OsSysman *pOsSysman) { - pOsDiagnostics = OsDiagnostics::create(pOsSysman); +ze_result_t DiagnosticsImp::diagnosticsRunTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) { + return pOsDiagnostics->osRunDiagTests(start, end, pResult); +} + +DiagnosticsImp::DiagnosticsImp(OsSysman *pOsSysman, const std::string &initalizedDiagTest) { + pOsDiagnostics = OsDiagnostics::create(pOsSysman, initalizedDiagTest); UNRECOVERABLE_IF(nullptr == pOsDiagnostics); - init(); } DiagnosticsImp::~DiagnosticsImp() { diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h b/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h index a378e0e26c..8c6b29b445 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h @@ -20,12 +20,12 @@ class OsDiagnostics; class DiagnosticsImp : public Diagnostics, NEO::NonCopyableOrMovableClass { public: ze_result_t diagnosticsGetProperties(zes_diag_properties_t *pProperties) override; + ze_result_t diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) override; + ze_result_t diagnosticsRunTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override; DiagnosticsImp() = default; - DiagnosticsImp(OsSysman *pOsSysman); + DiagnosticsImp(OsSysman *pOsSysman, const std::string &initalizedDiagTest); ~DiagnosticsImp() override; std::unique_ptr pOsDiagnostics = nullptr; - - void init(); }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/diagnostics/linux/CMakeLists.txt b/level_zero/tools/source/sysman/diagnostics/linux/CMakeLists.txt index d58c02f340..6d55419d44 100644 --- a/level_zero/tools/source/sysman/diagnostics/linux/CMakeLists.txt +++ b/level_zero/tools/source/sysman/diagnostics/linux/CMakeLists.txt @@ -8,6 +8,7 @@ set(L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/os_diagnostics_imp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_diagnostics_imp.h + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/os_diagnostics_helper.cpp ) if(UNIX) diff --git a/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_helper.cpp b/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_helper.cpp new file mode 100644 index 0000000000..0a38c2e7d7 --- /dev/null +++ b/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_helper.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/string.h" + +#include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h" + +namespace L0 { + +void OsDiagnostics::getSupportedDiagTestsFromFW(void *pFwInterface, std::vector &supportedDiagTests) { +} + +ze_result_t LinuxDiagnosticsImp::osRunDiagTestsinFW(zes_diag_result_t *pResult) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} +} // namespace L0 \ No newline at end of file diff --git a/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.cpp b/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.cpp index cd92702c3e..ea6685b2dd 100644 --- a/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.cpp +++ b/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.cpp @@ -11,25 +11,37 @@ namespace L0 { -bool LinuxDiagnosticsImp::isDiagnosticsSupported(void) { +void OsDiagnostics::getSupportedDiagTests(std::vector &supportedDiagTests, OsSysman *pOsSysman) { + LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); + FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); if (pFwInterface != nullptr) { - isFWInitalized = ((ZE_RESULT_SUCCESS == pFwInterface->fwDeviceInit()) ? true : false); - return this->isFWInitalized; + getSupportedDiagTestsFromFW(pFwInterface, supportedDiagTests); } - return false; } void LinuxDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties) { + pProperties->onSubdevice = false; + pProperties->haveTests = 0; // osGetDiagTests is Unsupported + strncpy_s(pProperties->name, ZES_STRING_PROPERTY_SIZE, osDiagType.c_str(), osDiagType.size()); return; } -LinuxDiagnosticsImp::LinuxDiagnosticsImp(OsSysman *pOsSysman) { - LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); - pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); +ze_result_t LinuxDiagnosticsImp::osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } -std::unique_ptr OsDiagnostics::create(OsSysman *pOsSysman) { - std::unique_ptr pLinuxDiagnosticsImp = std::make_unique(pOsSysman); +ze_result_t LinuxDiagnosticsImp::osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) { + return osRunDiagTestsinFW(pResult); +} + +LinuxDiagnosticsImp::LinuxDiagnosticsImp(OsSysman *pOsSysman, const std::string &diagTests) : osDiagType(diagTests) { + LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); + pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); + pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); +} + +std::unique_ptr OsDiagnostics::create(OsSysman *pOsSysman, const std::string &diagTests) { + std::unique_ptr pLinuxDiagnosticsImp = std::make_unique(pOsSysman, diagTests); return pLinuxDiagnosticsImp; } diff --git a/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h b/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h index 7183083142..6c05cbf50a 100644 --- a/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h +++ b/level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h @@ -16,15 +16,21 @@ namespace L0 { class LinuxDiagnosticsImp : public OsDiagnostics, NEO::NonCopyableOrMovableClass { public: - bool isDiagnosticsSupported(void) override; void osGetDiagProperties(zes_diag_properties_t *pProperties) override; + ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) override; + ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override; + ze_result_t osRunDiagTestsinFW(zes_diag_result_t *pResult); LinuxDiagnosticsImp() = default; - LinuxDiagnosticsImp(OsSysman *pOsSysman); + LinuxDiagnosticsImp(OsSysman *pOsSysman, const std::string &diagTests); ~LinuxDiagnosticsImp() override = default; + std::string osDiagType = "unknown"; protected: FirmwareUtil *pFwInterface = nullptr; - bool isFWInitalized = false; + SysfsAccess *pSysfsAccess = nullptr; + + private: + static const std::string quiescentGpuFile; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/diagnostics/os_diagnostics.h b/level_zero/tools/source/sysman/diagnostics/os_diagnostics.h index c380840489..59706f7dd1 100644 --- a/level_zero/tools/source/sysman/diagnostics/os_diagnostics.h +++ b/level_zero/tools/source/sysman/diagnostics/os_diagnostics.h @@ -18,9 +18,12 @@ namespace L0 { class OsDiagnostics { public: - virtual bool isDiagnosticsSupported(void) = 0; virtual void osGetDiagProperties(zes_diag_properties_t *pProperties) = 0; - static std::unique_ptr create(OsSysman *pOsSysman); + virtual ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) = 0; + virtual ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) = 0; + static std::unique_ptr create(OsSysman *pOsSysman, const std::string &DiagTests); + static void getSupportedDiagTestsFromFW(void *pFwInterface, std::vector &supportedDiagTests); + static void getSupportedDiagTests(std::vector &supportedDiagTests, OsSysman *pOsSysman); virtual ~OsDiagnostics() {} }; diff --git a/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.cpp b/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.cpp index 458ff0da7b..5d19192d93 100644 --- a/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.cpp +++ b/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.cpp @@ -9,15 +9,24 @@ namespace L0 { -bool WddmDiagnosticsImp::isDiagnosticsSupported(void) { - return false; -} - void WddmDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties){}; -std::unique_ptr OsDiagnostics::create(OsSysman *pOsSysman) { +ze_result_t WddmDiagnosticsImp::osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t WddmDiagnosticsImp::osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +std::unique_ptr OsDiagnostics::create(OsSysman *pOsSysman, const std::string &diagTests) { std::unique_ptr pWddmDiagnosticsImp = std::make_unique(); return pWddmDiagnosticsImp; } +void OsDiagnostics::getSupportedDiagTests(std::vector &supportedDiagTests, OsSysman *pOsSysman) { +} + +void OsDiagnostics::getSupportedDiagTestsFromFW(void *pFwInterface, std::vector &supportedDiagTests) { +} } // namespace L0 diff --git a/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.h b/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.h index d854369190..973fb7e724 100644 --- a/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.h +++ b/level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.h @@ -14,8 +14,9 @@ namespace L0 { class WddmDiagnosticsImp : public OsDiagnostics { public: - bool isDiagnosticsSupported(void) override; void osGetDiagProperties(zes_diag_properties_t *pProperties) override; + ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) override; + ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/linux/firmware_util/CMakeLists.txt b/level_zero/tools/source/sysman/linux/firmware_util/CMakeLists.txt index 15c36b4e2e..1209e4e9d8 100644 --- a/level_zero/tools/source/sysman/linux/firmware_util/CMakeLists.txt +++ b/level_zero/tools/source/sysman/linux/firmware_util/CMakeLists.txt @@ -10,14 +10,16 @@ if(libigsc_FOUND) ${CMAKE_CURRENT_SOURCE_DIR}/firmware_util_imp.h ${CMAKE_CURRENT_SOURCE_DIR}/firmware_util.h ) - if($(libigsc_VERSION) GREATER "2") - set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_HELPER - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/firmware_util_imp_helper.cpp - ) - else() + if(libigsc_VERSION VERSION_LESS 0.3) + message(STATUS "default libigsc version: ${libigsc_VERSION}") set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_HELPER ${CMAKE_CURRENT_SOURCE_DIR}/firmware_util_imp_helper.cpp ) + else() + message(STATUS "LIBIGSC version: ${libigsc_VERSION}") + set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_HELPER + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/firmware_util_imp_helper.cpp + ) endif() else() set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL diff --git a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util.h b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util.h index 2a0588c79b..79c1997a26 100644 --- a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util.h +++ b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util.h @@ -31,6 +31,8 @@ class FirmwareUtil { virtual ze_result_t fwFlashGSC(void *pImage, uint32_t size) = 0; virtual ze_result_t fwFlashOprom(void *pImage, uint32_t size) = 0; virtual ze_result_t fwIfrApplied(bool &ifrStatus) = 0; + virtual ze_result_t fwSupportedDiagTests(std::vector &supportedDiagTests) = 0; + virtual ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) = 0; virtual ~FirmwareUtil() = default; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.cpp b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.cpp index 3c0afc6e62..87048fe1e6 100644 --- a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.cpp +++ b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.cpp @@ -187,7 +187,6 @@ FirmwareUtil *FirmwareUtil::create() { delete pFwUtilImp; return nullptr; } - return static_cast(pFwUtilImp); } } // namespace L0 diff --git a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.h b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.h index f5dbd5a771..ce21e644b5 100644 --- a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.h +++ b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp.h @@ -68,6 +68,8 @@ class FirmwareUtilImp : public FirmwareUtil, NEO::NonCopyableOrMovableClass { ze_result_t fwFlashGSC(void *pImage, uint32_t size) override; ze_result_t fwFlashOprom(void *pImage, uint32_t size) override; ze_result_t fwIfrApplied(bool &ifrStatus) override; + ze_result_t fwSupportedDiagTests(std::vector &supportedDiagTests) override; + ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) override; template bool getSymbolAddr(const std::string name, T &proc); diff --git a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp_helper.cpp b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp_helper.cpp index 8d873779db..ba86e54d0b 100644 --- a/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp_helper.cpp +++ b/level_zero/tools/source/sysman/linux/firmware_util/firmware_util_imp_helper.cpp @@ -14,4 +14,12 @@ namespace L0 { ze_result_t FirmwareUtilImp::fwIfrApplied(bool &ifrStatus) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } + +ze_result_t FirmwareUtilImp::fwSupportedDiagTests(std::vector &supportedDiagTests) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +ze_result_t FirmwareUtilImp::fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} } // namespace L0 diff --git a/level_zero/tools/test/black_box_tests/zello_sysman.cpp b/level_zero/tools/test/black_box_tests/zello_sysman.cpp index 1a33d8fd0f..d0c8bb9b3c 100644 --- a/level_zero/tools/test/black_box_tests/zello_sysman.cpp +++ b/level_zero/tools/test/black_box_tests/zello_sysman.cpp @@ -96,6 +96,7 @@ void usage() { "\n -r, --reset force|noforce selectively run device reset test" "\n -i, --firmware selectively run device firmware test is the firmware binary needed to flash" "\n -F, --fabricport selectively run fabricport black box test" + "\n -d, --diagnostics selectively run diagnostics black box test" "\n -h, --help display help message" "\n" "\n All L0 Syman APIs that set values require root privileged execution" @@ -930,6 +931,66 @@ void testSysmanGlobalOperations(ze_device_handle_t &device) { } } } + +void testSysmanDiagnostics(ze_device_handle_t &device) { + std::cout << std::endl + << " ---- diagnostics tests ---- " << std::endl; + uint32_t count = 0; + uint32_t subTestCount = 0; + zes_diag_test_t tests = {}; + zes_diag_result_t results; + uint32_t start = 0, end = 0; + VALIDATECALL(zesDeviceEnumDiagnosticTestSuites(device, &count, nullptr)); + if (count == 0) { + std::cout << "Could not retrieve diagnostics domains" << std::endl; + return; + } + std::vector handles(count, nullptr); + VALIDATECALL(zesDeviceEnumDiagnosticTestSuites(device, &count, handles.data())); + + for (auto handle : handles) { + zes_diag_properties_t diagProperties = {}; + + VALIDATECALL(zesDiagnosticsGetProperties(handle, &diagProperties)); + if (verbose) { + std::cout << "diagnostics name = " << diagProperties.name << std::endl; + std::cout << "On Subdevice = " << diagProperties.onSubdevice << std::endl; + std::cout << "Subdevice Id = " << diagProperties.subdeviceId << std::endl; + std::cout << "diagnostics have sub tests = " << diagProperties.haveTests << std::endl; + } + if (diagProperties.haveTests != 0) { + VALIDATECALL(zesDiagnosticsGetTests(handle, &subTestCount, &tests)); + if (verbose) { + std::cout << "diagnostics subTestCount = " << subTestCount << "for " << diagProperties.name << std::endl; + for (uint32_t i = 0; i < subTestCount; i++) { + std::cout << "subTest#" << tests.index << " = " << tests.name << std::endl; + } + } + end = subTestCount - 1; + } + VALIDATECALL(zesDiagnosticsRunTests(handle, start, end, &results)); + if (verbose) { + switch (results) { + case ZES_DIAG_RESULT_NO_ERRORS: + std::cout << "No errors have occurred" << std::endl; + break; + case ZES_DIAG_RESULT_REBOOT_FOR_REPAIR: + std::cout << "diagnostics successful and repair applied, reboot needed" << std::endl; + break; + case ZES_DIAG_RESULT_FAIL_CANT_REPAIR: + std::cout << "diagnostics run, unable to fix" << std::endl; + break; + case ZES_DIAG_RESULT_ABORT: + std::cout << "diagnostics run fialed, unknown error" << std::endl; + break; + case ZES_DIAG_RESULT_FORCE_UINT32: + default: + std::cout << "undefined error" << std::endl; + } + } + } +} + bool validateGetenv(const char *name) { const char *env = getenv(name); if ((nullptr == env) || (0 == strcmp("0", env))) @@ -963,10 +1024,11 @@ int main(int argc, char *argv[]) { {"reset", required_argument, nullptr, 'r'}, {"fabricport", no_argument, nullptr, 'F'}, {"firmware", optional_argument, nullptr, 'i'}, + {"diagnostics", no_argument, nullptr, 'd'}, {0, 0, 0, 0}, }; bool force = false; - while ((opt = getopt_long(argc, argv, "hpfsectogmrFEi:", long_opts, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "hdpfsectogmrFEi:", long_opts, nullptr)) != -1) { switch (opt) { case 'h': usage(); @@ -1062,7 +1124,11 @@ int main(int argc, char *argv[]) { testSysmanFabricPort(device); }); break; - + case 'd': + std::for_each(devices.begin(), devices.end(), [&](auto device) { + testSysmanDiagnostics(device); + }); + break; default: usage(); exit(0); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/CMakeLists.txt b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/CMakeLists.txt index 5f6ebae215..b08c37a447 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/CMakeLists.txt @@ -9,6 +9,6 @@ if(UNIX) PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/mock_zes_sysman_diagnostics.h - ${CMAKE_CURRENT_SOURCE_DIR}/test_zes_sysman_diagnostics.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/test_zes_sysman_diagnostics.cpp ) endif() diff --git a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h index e0fdf9ba75..e187e4f3ba 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h @@ -13,7 +13,9 @@ namespace L0 { namespace ult { -constexpr uint32_t mockDiagHandleCount = 1; +constexpr uint32_t mockDiagHandleCount = 2; +const std::string mockQuiescentGpuFile("quiesce_gpu"); +const std::vector mockSupportedDiagTypes = {"MOCKSUITE1", "MOCKSUITE2"}; class DiagnosticsInterface : public FirmwareUtil {}; template <> @@ -25,20 +27,17 @@ struct Mock : public FirmwareUtil { ze_result_t mockFwDeviceInitFail(void) { return ZE_RESULT_ERROR_UNKNOWN; } - ze_result_t mockFwGetVersion(std::string &fwVersion) { - return ZE_RESULT_SUCCESS; - } - ze_result_t mockOpromGetVersion(std::string &fwVersion) { - return ZE_RESULT_SUCCESS; - } ze_result_t mockGetFirstDevice(igsc_device_info *info) { return ZE_RESULT_SUCCESS; } - ze_result_t mockFwFlash(void *pImage, uint32_t size) { + ze_result_t mockFwSupportedDiagTests(std::vector &supportedDiagTests) { + supportedDiagTests.push_back(mockSupportedDiagTypes[0]); + supportedDiagTests.push_back(mockSupportedDiagTypes[1]); return ZE_RESULT_SUCCESS; } - ze_result_t mockFwGetVersionFailed(std::string &fwVersion) { - return ZE_RESULT_ERROR_UNINITIALIZED; + ze_result_t mockFwRunDiagTestsReturnSuccess(std::string &osDiagType, zes_diag_result_t *pResult) { + *pResult = ZES_DIAG_RESULT_NO_ERRORS; + return ZE_RESULT_SUCCESS; } Mock() = default; @@ -50,6 +49,28 @@ struct Mock : public FirmwareUtil { MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override)); MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override)); MOCK_METHOD(ze_result_t, fwIfrApplied, (bool &ifrStatus), (override)); + MOCK_METHOD(ze_result_t, fwSupportedDiagTests, (std::vector & supportedDiagTests), (override)); + MOCK_METHOD(ze_result_t, fwRunDiagTests, (std::string & osDiagType, zes_diag_result_t *pResult), (override)); +}; + +class DiagSysfsAccess : public SysfsAccess {}; +template <> +struct Mock : public DiagSysfsAccess { + + ze_result_t mockwrite(const std::string file, const int val) { + if (std::string::npos != file.find(mockQuiescentGpuFile)) { + return ZE_RESULT_SUCCESS; + } else { + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + } + + ze_result_t mockwriteFails(const std::string file, const int val) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + Mock() = default; + + MOCK_METHOD(ze_result_t, write, (const std::string file, const int val), (override)); }; class PublicLinuxDiagnosticsImp : public L0::LinuxDiagnosticsImp { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp index 06cc678599..6243e883a0 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp @@ -26,16 +26,10 @@ class ZesDiagnosticsFixture : public SysmanDeviceFixture { pLinuxSysmanImp->pFwUtilInterface = pMockDiagInterface.get(); ON_CALL(*pMockDiagInterface.get(), fwDeviceInit()) .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockFwDeviceInit)); - ON_CALL(*pMockDiagInterface.get(), fwGetVersion(_)) - .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockFwGetVersion)); - ON_CALL(*pMockDiagInterface.get(), opromGetVersion(_)) - .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockOpromGetVersion)); ON_CALL(*pMockDiagInterface.get(), getFirstDevice(_)) .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockGetFirstDevice)); - ON_CALL(*pMockDiagInterface.get(), fwFlashGSC(_, _)) - .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockFwFlash)); - ON_CALL(*pMockDiagInterface.get(), fwFlashOprom(_, _)) - .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockFwFlash)); + ON_CALL(*pMockDiagInterface.get(), fwSupportedDiagTests(_)) + .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockFwSupportedDiagTests)); for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) { delete handle; } @@ -47,7 +41,7 @@ class ZesDiagnosticsFixture : public SysmanDeviceFixture { pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld; } - std::vector get_diagnostics_handles(uint32_t count) { + std::vector get_diagnostics_handles(uint32_t &count) { std::vector handles(count, nullptr); EXPECT_EQ(zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); return handles; @@ -61,7 +55,7 @@ TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDia ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(count, mockDiagHandleCount); + EXPECT_EQ(count, 0u); uint32_t testCount = count + 1; @@ -74,14 +68,14 @@ TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDia result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, diagnosticsHandle.data()); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(count, mockDiagHandleCount); + EXPECT_EQ(count, 0u); - DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman); + DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]); pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp); result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(count, mockDiagHandleCount); + EXPECT_EQ(count, 1u); testCount = count; @@ -90,7 +84,7 @@ TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDia EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(nullptr, diagnosticsHandle.data()); - EXPECT_EQ(testCount, mockDiagHandleCount); + EXPECT_EQ(testCount, 1u); pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back(); delete ptestDiagnosticsImp; @@ -109,6 +103,20 @@ TEST_F(ZesDiagnosticsFixture, GivenFailedFirmwareInitializationWhenInitializingD EXPECT_EQ(0u, pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.size()); } +TEST_F(ZesDiagnosticsFixture, GivenSupportedTestsWhenInitializingDiagnosticsContextThenexpectHandles) { + for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) { + delete handle; + } + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear(); + pSysmanDeviceImp->pDiagnosticsHandleContext->supportedDiagTests.push_back(mockSupportedDiagTypes[0]); + ON_CALL(*pMockDiagInterface.get(), fwDeviceInit()) + .WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock::mockFwDeviceInitFail)); + + pSysmanDeviceImp->pDiagnosticsHandleContext->init(); + + EXPECT_EQ(1u, pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.size()); +} + TEST_F(ZesDiagnosticsFixture, GivenFirmwareInitializationFailureThenCreateHandleMustFail) { for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) { delete handle; @@ -121,10 +129,50 @@ TEST_F(ZesDiagnosticsFixture, GivenFirmwareInitializationFailureThenCreateHandle } TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsPropertiesThenCallSucceeds) { - auto handles = get_diagnostics_handles(mockDiagHandleCount); + for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) { + delete handle; + } + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear(); + DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]); + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp); + auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle(); zes_diag_properties_t properties = {}; - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDiagnosticsGetProperties(handles[0], &properties)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDiagnosticsGetProperties(handle, &properties)); } + +TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsTestThenCallSucceeds) { + for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) { + delete handle; + } + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear(); + DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]); + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp); + + auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle(); + zes_diag_test_t tests = {}; + uint32_t count = 0; + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDiagnosticsGetTests(handle, &count, &tests)); + + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back(); + delete ptestDiagnosticsImp; +} + +TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenRunningDiagnosticsTestThenCallSucceeds) { + for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) { + delete handle; + } + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear(); + DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]); + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp); + + auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle(); + zes_diag_result_t results = ZES_DIAG_RESULT_FORCE_UINT32; + uint32_t start = 0, end = 0; + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDiagnosticsRunTests(handle, start, end, &results)); + pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back(); + delete ptestDiagnosticsImp; +} + } // namespace ult } // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h index c2ad7edad1..ed64a629a3 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/mock_zes_sysman_firmware.h @@ -71,6 +71,8 @@ struct Mock : public FirmwareUtil { MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override)); MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override)); MOCK_METHOD(ze_result_t, fwIfrApplied, (bool &ifrStatus), (override)); + MOCK_METHOD(ze_result_t, fwSupportedDiagTests, (std::vector & supportedDiagTests), (override)); + MOCK_METHOD(ze_result_t, fwRunDiagTests, (std::string & osDiagType, zes_diag_result_t *pResult), (override)); }; class PublicLinuxFirmwareImp : public L0::LinuxFirmwareImp { 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 fe83a4480e..5c40680944 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 @@ -426,6 +426,8 @@ struct Mock : public FirmwareUtil { MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override)); MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override)); MOCK_METHOD(ze_result_t, fwIfrApplied, (bool &ifrStatus), (override)); + MOCK_METHOD(ze_result_t, fwSupportedDiagTests, (std::vector & supportedDiagTests), (override)); + MOCK_METHOD(ze_result_t, fwRunDiagTests, (std::string & osDiagType, zes_diag_result_t *pResult), (override)); }; class PublicLinuxGlobalOperationsImp : public L0::LinuxGlobalOperationsImp {