mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-29 09:03:14 +08:00
sysman: add diagnostics boilerplate code
Signed-off-by: Vilvaraj, T J Vivek <t.j.vivek.vilvaraj@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
d264dc858f
commit
457d05420d
@@ -674,14 +674,14 @@ zesDeviceEnumDiagnosticTestSuites(
|
||||
zes_device_handle_t hDevice,
|
||||
uint32_t *pCount,
|
||||
zes_diag_handle_t *phDiagnostics) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
return L0::SysmanDevice::fromHandle(hDevice)->diagnosticsGet(pCount, phDiagnostics);
|
||||
}
|
||||
|
||||
ZE_APIEXPORT ze_result_t ZE_APICALL
|
||||
zesDiagnosticsGetProperties(
|
||||
zes_diag_handle_t hDiagnostics,
|
||||
zes_diag_properties_t *pProperties) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetProperties(pProperties);
|
||||
}
|
||||
|
||||
ZE_APIEXPORT ze_result_t ZE_APICALL
|
||||
|
||||
25
level_zero/tools/source/sysman/diagnostics/CMakeLists.txt
Normal file
25
level_zero/tools/source/sysman/diagnostics/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/diagnostics.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/diagnostics.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/diagnostics_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/diagnostics_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_diagnostics.h
|
||||
)
|
||||
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS ${L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS})
|
||||
|
||||
47
level_zero/tools/source/sysman/diagnostics/diagnostics.cpp
Normal file
47
level_zero/tools/source/sysman/diagnostics/diagnostics.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/helpers/basic_math.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
class OsDiagnostics;
|
||||
DiagnosticsHandleContext::~DiagnosticsHandleContext() {
|
||||
for (Diagnostics *pDiagnostics : handleList) {
|
||||
delete pDiagnostics;
|
||||
}
|
||||
handleList.clear();
|
||||
}
|
||||
|
||||
void DiagnosticsHandleContext::createHandle() {
|
||||
Diagnostics *pDiagnostics = new DiagnosticsImp(pOsSysman);
|
||||
if (pDiagnostics->isDiagnosticsEnabled == true) {
|
||||
handleList.push_back(pDiagnostics);
|
||||
} else {
|
||||
delete pDiagnostics;
|
||||
}
|
||||
}
|
||||
|
||||
void DiagnosticsHandleContext::init() {
|
||||
createHandle();
|
||||
}
|
||||
|
||||
ze_result_t DiagnosticsHandleContext::diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) {
|
||||
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
|
||||
uint32_t numToCopy = std::min(*pCount, handleListSize);
|
||||
if (0 == *pCount || *pCount > handleListSize) {
|
||||
*pCount = handleListSize;
|
||||
}
|
||||
if (nullptr != phDiagnostics) {
|
||||
for (uint32_t i = 0; i < numToCopy; i++) {
|
||||
phDiagnostics[i] = handleList[i]->toHandle();
|
||||
}
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
} // namespace L0
|
||||
49
level_zero/tools/source/sysman/diagnostics/diagnostics.h
Normal file
49
level_zero/tools/source/sysman/diagnostics/diagnostics.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct _zes_diag_handle_t {
|
||||
virtual ~_zes_diag_handle_t() = default;
|
||||
};
|
||||
|
||||
namespace L0 {
|
||||
|
||||
struct OsSysman;
|
||||
|
||||
class Diagnostics : _zes_diag_handle_t {
|
||||
public:
|
||||
virtual ~Diagnostics() {}
|
||||
virtual ze_result_t diagnosticsGetProperties(zes_diag_properties_t *pProperties) = 0;
|
||||
inline zes_diag_handle_t toHandle() { return this; }
|
||||
|
||||
static Diagnostics *fromHandle(zes_diag_handle_t handle) {
|
||||
return static_cast<Diagnostics *>(handle);
|
||||
}
|
||||
bool isDiagnosticsEnabled = false;
|
||||
};
|
||||
|
||||
struct DiagnosticsHandleContext {
|
||||
DiagnosticsHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
|
||||
~DiagnosticsHandleContext();
|
||||
|
||||
void init();
|
||||
|
||||
ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics);
|
||||
|
||||
OsSysman *pOsSysman = nullptr;
|
||||
std::vector<Diagnostics *> handleList = {};
|
||||
|
||||
private:
|
||||
void createHandle();
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "diagnostics_imp.h"
|
||||
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
|
||||
#include "os_diagnostics.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t DiagnosticsImp::diagnosticsGetProperties(zes_diag_properties_t *pProperties) {
|
||||
pOsDiagnostics->osGetDiagProperties(pProperties);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void DiagnosticsImp::init() {
|
||||
this->isDiagnosticsEnabled = pOsDiagnostics->isDiagnosticsSupported();
|
||||
}
|
||||
|
||||
DiagnosticsImp::DiagnosticsImp(OsSysman *pOsSysman) {
|
||||
pOsDiagnostics = OsDiagnostics::create(pOsSysman);
|
||||
UNRECOVERABLE_IF(nullptr == pOsDiagnostics);
|
||||
init();
|
||||
}
|
||||
|
||||
DiagnosticsImp::~DiagnosticsImp() {
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
31
level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h
Normal file
31
level_zero/tools/source/sysman/diagnostics/diagnostics_imp.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/diagnostics/diagnostics.h"
|
||||
#include "level_zero/tools/source/sysman/diagnostics/os_diagnostics.h"
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class OsDiagnostics;
|
||||
|
||||
class DiagnosticsImp : public Diagnostics, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t diagnosticsGetProperties(zes_diag_properties_t *pProperties) override;
|
||||
DiagnosticsImp() = default;
|
||||
DiagnosticsImp(OsSysman *pOsSysman);
|
||||
~DiagnosticsImp() override;
|
||||
std::unique_ptr<OsDiagnostics> pOsDiagnostics = nullptr;
|
||||
|
||||
void init();
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_LINUX}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_LINUX ${L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_LINUX})
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h"
|
||||
|
||||
#include "shared/source/helpers/string.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
bool LinuxDiagnosticsImp::isDiagnosticsSupported(void) {
|
||||
if (pFwInterface != nullptr) {
|
||||
isFWInitalized = ((ZE_RESULT_SUCCESS == pFwInterface->fwDeviceInit()) ? true : false);
|
||||
return this->isFWInitalized;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LinuxDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinuxDiagnosticsImp::LinuxDiagnosticsImp(OsSysman *pOsSysman) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
|
||||
}
|
||||
|
||||
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman) {
|
||||
std::unique_ptr<LinuxDiagnosticsImp> pLinuxDiagnosticsImp = std::make_unique<LinuxDiagnosticsImp>(pOsSysman);
|
||||
return pLinuxDiagnosticsImp;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "sysman/diagnostics/diagnostics_imp.h"
|
||||
#include "sysman/diagnostics/os_diagnostics.h"
|
||||
#include "sysman/linux/os_sysman_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class LinuxDiagnosticsImp : public OsDiagnostics, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
bool isDiagnosticsSupported(void) override;
|
||||
void osGetDiagProperties(zes_diag_properties_t *pProperties) override;
|
||||
LinuxDiagnosticsImp() = default;
|
||||
LinuxDiagnosticsImp(OsSysman *pOsSysman);
|
||||
~LinuxDiagnosticsImp() override = default;
|
||||
|
||||
protected:
|
||||
FirmwareUtil *pFwInterface = nullptr;
|
||||
bool isFWInitalized = false;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
27
level_zero/tools/source/sysman/diagnostics/os_diagnostics.h
Normal file
27
level_zero/tools/source/sysman/diagnostics/os_diagnostics.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "level_zero/tools/source/sysman/os_sysman.h"
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class OsDiagnostics {
|
||||
public:
|
||||
virtual bool isDiagnosticsSupported(void) = 0;
|
||||
virtual void osGetDiagProperties(zes_diag_properties_t *pProperties) = 0;
|
||||
static std::unique_ptr<OsDiagnostics> create(OsSysman *pOsSysman);
|
||||
virtual ~OsDiagnostics() {}
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_diagnostics_imp.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_WINDOWS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_WINDOWS ${L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_WINDOWS})
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/source/sysman/diagnostics/windows/os_diagnostics_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
bool WddmDiagnosticsImp::isDiagnosticsSupported(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WddmDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties){};
|
||||
|
||||
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman) {
|
||||
std::unique_ptr<WddmDiagnosticsImp> pWddmDiagnosticsImp = std::make_unique<WddmDiagnosticsImp>();
|
||||
return pWddmDiagnosticsImp;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "sysman/diagnostics/os_diagnostics.h"
|
||||
#include "sysman/windows/os_sysman_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
class WddmDiagnosticsImp : public OsDiagnostics {
|
||||
public:
|
||||
bool isDiagnosticsSupported(void) override;
|
||||
void osGetDiagProperties(zes_diag_properties_t *pProperties) override;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/tools/source/sysman/diagnostics/diagnostics.h"
|
||||
#include "level_zero/tools/source/sysman/engine/engine.h"
|
||||
#include "level_zero/tools/source/sysman/events/events.h"
|
||||
#include "level_zero/tools/source/sysman/fabric_port/fabric_port.h"
|
||||
@@ -50,6 +51,7 @@ struct SysmanDevice : _ze_device_handle_t {
|
||||
virtual ze_result_t rasGet(uint32_t *pCount, zes_ras_handle_t *phRas) = 0;
|
||||
virtual ze_result_t memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory) = 0;
|
||||
virtual ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) = 0;
|
||||
virtual ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) = 0;
|
||||
virtual ze_result_t firmwareGet(uint32_t *pCount, zes_firmware_handle_t *phFirmware) = 0;
|
||||
virtual ze_result_t deviceEventRegister(zes_event_type_flags_t events) = 0;
|
||||
virtual bool deviceEventListen(zes_event_type_flags_t &pEvent, uint32_t timeout) = 0;
|
||||
|
||||
@@ -36,11 +36,13 @@ SysmanDeviceImp::SysmanDeviceImp(ze_device_handle_t hDevice) {
|
||||
pEvents = new EventsImp(pOsSysman);
|
||||
pFanHandleContext = new FanHandleContext(pOsSysman);
|
||||
pFirmwareHandleContext = new FirmwareHandleContext(pOsSysman);
|
||||
pDiagnosticsHandleContext = new DiagnosticsHandleContext(pOsSysman);
|
||||
pPerformanceHandleContext = new PerformanceHandleContext(pOsSysman);
|
||||
}
|
||||
|
||||
SysmanDeviceImp::~SysmanDeviceImp() {
|
||||
freeResource(pPerformanceHandleContext);
|
||||
freeResource(pDiagnosticsHandleContext);
|
||||
freeResource(pFirmwareHandleContext);
|
||||
freeResource(pFanHandleContext);
|
||||
freeResource(pEvents);
|
||||
@@ -112,6 +114,9 @@ void SysmanDeviceImp::init() {
|
||||
if (pFirmwareHandleContext) {
|
||||
pFirmwareHandleContext->init();
|
||||
}
|
||||
if (pDiagnosticsHandleContext) {
|
||||
pDiagnosticsHandleContext->init();
|
||||
}
|
||||
if (pPerformanceHandleContext) {
|
||||
pPerformanceHandleContext->init(deviceHandles);
|
||||
}
|
||||
@@ -193,6 +198,10 @@ ze_result_t SysmanDeviceImp::firmwareGet(uint32_t *pCount, zes_firmware_handle_t
|
||||
return pFirmwareHandleContext->firmwareGet(pCount, phFirmware);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDeviceImp::diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) {
|
||||
return pDiagnosticsHandleContext->diagnosticsGet(pCount, phDiagnostics);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDeviceImp::memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory) {
|
||||
return pMemoryHandleContext->memoryGet(pCount, phMemory);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
|
||||
MemoryHandleContext *pMemoryHandleContext = nullptr;
|
||||
FanHandleContext *pFanHandleContext = nullptr;
|
||||
FirmwareHandleContext *pFirmwareHandleContext = nullptr;
|
||||
DiagnosticsHandleContext *pDiagnosticsHandleContext = nullptr;
|
||||
PerformanceHandleContext *pPerformanceHandleContext = nullptr;
|
||||
|
||||
ze_result_t performanceGet(uint32_t *pCount, zes_perf_handle_t *phPerformance) override;
|
||||
@@ -62,6 +63,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
|
||||
ze_result_t rasGet(uint32_t *pCount, zes_ras_handle_t *phRas) override;
|
||||
ze_result_t memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory) override;
|
||||
ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) override;
|
||||
ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phFirmware) override;
|
||||
ze_result_t firmwareGet(uint32_t *pCount, zes_firmware_handle_t *phFirmware) override;
|
||||
ze_result_t deviceEventRegister(zes_event_type_flags_t events) override;
|
||||
bool deviceEventListen(zes_event_type_flags_t &pEvent, uint32_t timeout) override;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME}
|
||||
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
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h"
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
constexpr uint32_t mockDiagHandleCount = 1;
|
||||
class DiagnosticsInterface : public FirmwareUtil {};
|
||||
|
||||
template <>
|
||||
struct Mock<DiagnosticsInterface> : public FirmwareUtil {
|
||||
|
||||
ze_result_t mockFwDeviceInit(void) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
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) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
ze_result_t mockFwGetVersionFailed(std::string &fwVersion) {
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
Mock<DiagnosticsInterface>() = default;
|
||||
|
||||
MOCK_METHOD(ze_result_t, fwDeviceInit, (), (override));
|
||||
MOCK_METHOD(ze_result_t, fwGetVersion, (std::string & fwVersion), (override));
|
||||
MOCK_METHOD(ze_result_t, opromGetVersion, (std::string & fwVersion), (override));
|
||||
MOCK_METHOD(ze_result_t, getFirstDevice, (igsc_device_info * info), (override));
|
||||
MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override));
|
||||
MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override));
|
||||
};
|
||||
|
||||
class PublicLinuxDiagnosticsImp : public L0::LinuxDiagnosticsImp {
|
||||
public:
|
||||
using LinuxDiagnosticsImp::pFwInterface;
|
||||
};
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h"
|
||||
|
||||
using ::testing::_;
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
class ZesDiagnosticsFixture : public SysmanDeviceFixture {
|
||||
|
||||
protected:
|
||||
zes_diag_handle_t hSysmanDiagnostics = {};
|
||||
std::unique_ptr<Mock<DiagnosticsInterface>> pMockDiagInterface;
|
||||
FirmwareUtil *pFwUtilInterfaceOld = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
SysmanDeviceFixture::SetUp();
|
||||
|
||||
pFwUtilInterfaceOld = pLinuxSysmanImp->pFwUtilInterface;
|
||||
pMockDiagInterface = std::make_unique<NiceMock<Mock<DiagnosticsInterface>>>();
|
||||
pLinuxSysmanImp->pFwUtilInterface = pMockDiagInterface.get();
|
||||
ON_CALL(*pMockDiagInterface.get(), fwDeviceInit())
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwDeviceInit));
|
||||
ON_CALL(*pMockDiagInterface.get(), fwGetVersion(_))
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwGetVersion));
|
||||
ON_CALL(*pMockDiagInterface.get(), opromGetVersion(_))
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockOpromGetVersion));
|
||||
ON_CALL(*pMockDiagInterface.get(), getFirstDevice(_))
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockGetFirstDevice));
|
||||
ON_CALL(*pMockDiagInterface.get(), fwFlashGSC(_, _))
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwFlash));
|
||||
ON_CALL(*pMockDiagInterface.get(), fwFlashOprom(_, _))
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwFlash));
|
||||
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->init();
|
||||
}
|
||||
void TearDown() override {
|
||||
SysmanDeviceFixture::TearDown();
|
||||
pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
|
||||
}
|
||||
|
||||
std::vector<zes_diag_handle_t> get_diagnostics_handles(uint32_t count) {
|
||||
std::vector<zes_diag_handle_t> handles(count, nullptr);
|
||||
EXPECT_EQ(zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
|
||||
return handles;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDiagnosticTestSuitesThenZeroCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesCallSucceeds) {
|
||||
std::vector<zes_diag_handle_t> diagnosticsHandle{};
|
||||
uint32_t count = 0;
|
||||
|
||||
ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(count, mockDiagHandleCount);
|
||||
|
||||
uint32_t testCount = count + 1;
|
||||
|
||||
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &testCount, nullptr);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(testCount, count);
|
||||
|
||||
diagnosticsHandle.resize(count);
|
||||
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, diagnosticsHandle.data());
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(count, mockDiagHandleCount);
|
||||
|
||||
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman);
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp);
|
||||
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(count, mockDiagHandleCount);
|
||||
|
||||
testCount = count;
|
||||
|
||||
diagnosticsHandle.resize(testCount);
|
||||
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &testCount, diagnosticsHandle.data());
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_NE(nullptr, diagnosticsHandle.data());
|
||||
EXPECT_EQ(testCount, mockDiagHandleCount);
|
||||
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
|
||||
delete ptestDiagnosticsImp;
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenFailedFirmwareInitializationWhenInitializingDiagnosticsContextThenexpectNoHandles) {
|
||||
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
|
||||
ON_CALL(*pMockDiagInterface.get(), fwDeviceInit())
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwDeviceInitFail));
|
||||
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->init();
|
||||
|
||||
EXPECT_EQ(0u, pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.size());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenFirmwareInitializationFailureThenCreateHandleMustFail) {
|
||||
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
|
||||
ON_CALL(*pMockDiagInterface.get(), fwDeviceInit())
|
||||
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwDeviceInitFail));
|
||||
pSysmanDeviceImp->pDiagnosticsHandleContext->init();
|
||||
EXPECT_EQ(0u, pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.size());
|
||||
}
|
||||
|
||||
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsPropertiesThenCallSucceeds) {
|
||||
auto handles = get_diagnostics_handles(mockDiagHandleCount);
|
||||
|
||||
zes_diag_properties_t properties = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDiagnosticsGetProperties(handles[0], &properties));
|
||||
}
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user