feature(sysman): Add support for the Diagnostics APIs

Added support for the Diagnostics APIs in the new sysman design
Added ULTs for the Diagnostics APIs in the new sysman design

Related-To: LOCI-4247

Signed-off-by: Bari, Pratik <pratik.bari@intel.com>
This commit is contained in:
Bari, Pratik 2023-04-11 15:33:13 +00:00 committed by Compute-Runtime-Automation
parent 64bd9e58a8
commit 112bbec6e9
19 changed files with 1550 additions and 15 deletions

View File

@ -942,20 +942,32 @@ ze_result_t zesDeviceEnumDiagnosticTestSuites(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_diag_handle_t *phDiagnostics) {
return L0::SysmanDevice::diagnosticsGet(hDevice, pCount, phDiagnostics);
if (L0::sysmanInitFromCore) {
return L0::SysmanDevice::diagnosticsGet(hDevice, pCount, phDiagnostics);
} else {
return L0::Sysman::SysmanDevice::diagnosticsGet(hDevice, pCount, phDiagnostics);
}
}
ze_result_t zesDiagnosticsGetProperties(
zes_diag_handle_t hDiagnostics,
zes_diag_properties_t *pProperties) {
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetProperties(pProperties);
if (L0::sysmanInitFromCore) {
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetProperties(pProperties);
} else {
return L0::Sysman::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetProperties(pProperties);
}
}
ze_result_t zesDiagnosticsGetTests(
zes_diag_handle_t hDiagnostics,
uint32_t *pCount,
zes_diag_test_t *pTests) {
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetTests(pCount, pTests);
if (L0::sysmanInitFromCore) {
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetTests(pCount, pTests);
} else {
return L0::Sysman::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetTests(pCount, pTests);
}
}
ze_result_t zesDiagnosticsRunTests(
@ -963,7 +975,11 @@ ze_result_t zesDiagnosticsRunTests(
uint32_t startIndex,
uint32_t endIndex,
zes_diag_result_t *pResult) {
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsRunTests(startIndex, endIndex, pResult);
if (L0::sysmanInitFromCore) {
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsRunTests(startIndex, endIndex, pResult);
} else {
return L0::Sysman::Diagnostics::fromHandle(hDiagnostics)->diagnosticsRunTests(startIndex, endIndex, pResult);
}
}
ze_result_t zesDeviceEnumPerformanceFactorDomains(

View File

@ -9,7 +9,9 @@ target_sources(${L0_STATIC_LIB_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/sysman_diagnostics.h
${CMAKE_CURRENT_SOURCE_DIR}/sysman_diagnostics.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sysman_diagnostics_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/sysman_diagnostics_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_diagnostics.h
)
add_subdirectories()

View File

@ -0,0 +1,14 @@
#
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(UNIX)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_diagnostics_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_diagnostics_imp.h
)
endif()

View File

@ -0,0 +1,145 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/diagnostics/linux/sysman_os_diagnostics_imp.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/sleep.h"
#include "shared/source/helpers/string.h"
#include "level_zero/sysman/source/firmware_util/sysman_firmware_util.h"
#include <linux/pci_regs.h>
namespace L0 {
namespace Sysman {
const std::string LinuxDiagnosticsImp::deviceDir("device");
// the sysfs node will be at /sys/class/drm/card<n>/invalidate_lmem_mmaps
const std::string LinuxDiagnosticsImp::invalidateLmemFile("invalidate_lmem_mmaps");
// the sysfs node will be at /sys/class/drm/card<n>/quiesce_gpu
const std::string LinuxDiagnosticsImp::quiescentGpuFile("quiesce_gpu");
void OsDiagnostics::getSupportedDiagTestsFromFW(void *pOsSysman, std::vector<std::string> &supportedDiagTests) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
if (IGFX_PVC == pLinuxSysmanImp->getProductFamily()) {
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
if (pFwInterface != nullptr) {
static_cast<FirmwareUtil *>(pFwInterface)->fwSupportedDiagTests(supportedDiagTests);
}
}
}
// before running diagnostics need to close all active workloads
// writing 1 to /sys/class/drm/card<n>/quiesce_gpu will signal KMD
// to close and clear all allocations,
// ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE will be sent till the kworker confirms that
// all allocations are closed and GPU is be wedged.
// GPU will only be unwedged after warm/cold reset
// writing 1 to /sys/class/drm/card<n>/invalidate_lmem_mmaps clears
// all memory mappings where LMEMBAR is being referenced are invalidated.
// Also prevents new ones from being created.
// It will invalidate LMEM memory mappings only when sysfs entry quiesce_gpu is set.
ze_result_t LinuxDiagnosticsImp::waitForQuiescentCompletion() {
uint32_t count = 0;
const int intVal = 1;
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
// limiting to 10 retries as we can endup going into a infinite loop if the cleanup and a process start are out of sync
do {
result = pSysfsAccess->write(quiescentGpuFile, intVal);
if (ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE == result) {
count++;
// Sleep for 1second every loop, gives enough time for KMD to clear all allocations and wedge the system
NEO::sleep(std::chrono::seconds(1));
auto processResult = pLinuxSysmanImp->gpuProcessCleanup();
if (ZE_RESULT_SUCCESS != processResult) {
return processResult;
}
} else if (ZE_RESULT_SUCCESS == result) {
break;
} else {
return result;
}
} while (count < 10);
result = pSysfsAccess->write(invalidateLmemFile, intVal);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): SysfsAccess->write() failed to write into %s and returning error:0x%x \n", __FUNCTION__, invalidateLmemFile.c_str(), result);
return result;
}
return result;
}
ze_result_t LinuxDiagnosticsImp::osRunDiagTestsinFW(zes_diag_result_t *pResult) {
pLinuxSysmanImp->diagnosticsReset = true;
pLinuxSysmanImp->releaseSysmanDeviceResources();
ze_result_t result = pLinuxSysmanImp->gpuProcessCleanup();
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): gpuProcessCleanup() failed and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
result = waitForQuiescentCompletion();
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): waitForQuiescentCompletion() failed and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
result = pFwInterface->fwRunDiagTests(osDiagType, pResult);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): fwRunDiagTests() failed and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
if (osDiagType == "MEMORY_PPR") {
pLinuxSysmanImp->isMemoryDiagnostics = true;
}
if (*pResult == ZES_DIAG_RESULT_REBOOT_FOR_REPAIR) {
result = pLinuxSysmanImp->osColdReset();
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): osColdReset() failed and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
} else {
result = pLinuxSysmanImp->osWarmReset(); // we need to at least do a Warm reset to bring the machine out of wedged state
if (result != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): osWarmReset() failed and returning error:0x%x \n", __FUNCTION__, result);
return result;
}
}
return pLinuxSysmanImp->reInitSysmanDeviceResources();
}
void LinuxDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
pProperties->haveTests = 0; // osGetDiagTests is Unsupported
strncpy_s(pProperties->name, ZES_STRING_PROPERTY_SIZE, osDiagType.c_str(), osDiagType.size());
return;
}
ze_result_t LinuxDiagnosticsImp::osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() returning UNSUPPORTED_FEATURE \n", __FUNCTION__);
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
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) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
}
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman, const std::string &diagTests) {
std::unique_ptr<LinuxDiagnosticsImp> pLinuxDiagnosticsImp = std::make_unique<LinuxDiagnosticsImp>(pOsSysman, diagTests);
return pLinuxDiagnosticsImp;
}
} // namespace Sysman
} // namespace L0

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "level_zero/sysman/source/diagnostics/sysman_diagnostics_imp.h"
#include "level_zero/sysman/source/diagnostics/sysman_os_diagnostics.h"
#include "level_zero/sysman/source/linux/sysman_fs_access.h"
#include "level_zero/sysman/source/linux/zes_os_sysman_imp.h"
namespace L0 {
namespace Sysman {
class FirmwareUtil;
class LinuxDiagnosticsImp : public OsDiagnostics, NEO::NonCopyableOrMovableClass {
public:
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, const std::string &diagTests);
~LinuxDiagnosticsImp() override = default;
std::string osDiagType = "unknown";
protected:
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
FirmwareUtil *pFwInterface = nullptr;
SysfsAccess *pSysfsAccess = nullptr;
FsAccess *pFsAccess = nullptr;
ze_result_t gpuProcessCleanup();
ze_result_t waitForQuiescentCompletion();
private:
static const std::string quiescentGpuFile;
bool isSubdevice = false;
uint32_t subdeviceId = 0;
static const std::string invalidateLmemFile;
static const std::string deviceDir;
};
} // namespace Sysman
} // namespace L0

View File

@ -9,21 +9,32 @@
#include "shared/source/helpers/basic_math.h"
#include "level_zero/sysman/source/diagnostics/sysman_diagnostics_imp.h"
#include "level_zero/sysman/source/diagnostics/sysman_os_diagnostics.h"
#include "level_zero/sysman/source/os_sysman.h"
namespace L0 {
namespace Sysman {
class OsDiagnostics;
DiagnosticsHandleContext::~DiagnosticsHandleContext() {
releaseDiagnosticsHandles();
}
void DiagnosticsHandleContext::releaseDiagnosticsHandles() {
for (Diagnostics *pDiagnostics : handleList) {
delete pDiagnostics;
}
handleList.clear();
}
void DiagnosticsHandleContext::createHandle(const std::string &diagTests) {
std::unique_ptr<Diagnostics> pDiagnostics = std::make_unique<DiagnosticsImp>(pOsSysman, diagTests);
handleList.push_back(std::move(pDiagnostics));
}
void DiagnosticsHandleContext::init() {
OsDiagnostics::getSupportedDiagTestsFromFW(pOsSysman, supportedDiagTests);
for (const std::string &diagTests : supportedDiagTests) {
createHandle(diagTests);
}
}
ze_result_t DiagnosticsHandleContext::diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) {

View File

@ -9,13 +9,13 @@
#include "level_zero/api/sysman/zes_handles_struct.h"
#include <level_zero/zes_api.h>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace L0 {
namespace Sysman {
struct OsSysman;
class Diagnostics : _zes_diag_handle_t {
@ -41,7 +41,7 @@ struct DiagnosticsHandleContext {
ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics);
std::vector<std::string> supportedDiagTests = {};
OsSysman *pOsSysman = nullptr;
std::vector<Diagnostics *> handleList = {};
std::vector<std::unique_ptr<Diagnostics>> handleList = {};
bool isDiagnosticsInitDone() {
return diagnosticsInitDone;
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/diagnostics/sysman_diagnostics_imp.h"
#include "shared/source/helpers/debug_helpers.h"
#include "level_zero/sysman/source/diagnostics/sysman_os_diagnostics.h"
namespace L0 {
namespace Sysman {
ze_result_t DiagnosticsImp::diagnosticsGetProperties(zes_diag_properties_t *pProperties) {
pOsDiagnostics->osGetDiagProperties(pProperties);
return ZE_RESULT_SUCCESS;
}
ze_result_t DiagnosticsImp::diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) {
return pOsDiagnostics->osGetDiagTests(pCount, pTests);
}
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);
}
DiagnosticsImp::~DiagnosticsImp() {
}
} // namespace Sysman
} // namespace L0

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2023 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/sysman/source/diagnostics/sysman_diagnostics.h"
#include "level_zero/sysman/source/diagnostics/sysman_os_diagnostics.h"
#include <level_zero/zes_api.h>
namespace L0 {
namespace Sysman {
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, const std::string &initalizedDiagTest);
~DiagnosticsImp() override;
std::unique_ptr<OsDiagnostics> pOsDiagnostics = nullptr;
};
} // namespace Sysman
} // namespace L0

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/sysman/source/os_sysman.h"
#include <level_zero/zes_api.h>
#include <memory>
#include <string>
#include <vector>
namespace L0 {
namespace Sysman {
class OsDiagnostics {
public:
virtual void osGetDiagProperties(zes_diag_properties_t *pProperties) = 0;
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<OsDiagnostics> create(OsSysman *pOsSysman, const std::string &diagTests);
static void getSupportedDiagTestsFromFW(void *pOsSysman, std::vector<std::string> &supportedDiagTests);
virtual ~OsDiagnostics() {}
};
} // namespace Sysman
} // namespace L0

View File

@ -0,0 +1,14 @@
#
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(WIN32)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_diagnostics_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_diagnostics_imp.h
)
endif()

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/diagnostics/windows/sysman_os_diagnostics_imp.h"
namespace L0 {
namespace Sysman {
void WddmDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties){};
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> OsDiagnostics::create(OsSysman *pOsSysman, const std::string &diagTests) {
std::unique_ptr<WddmDiagnosticsImp> pWddmDiagnosticsImp = std::make_unique<WddmDiagnosticsImp>();
return pWddmDiagnosticsImp;
}
void OsDiagnostics::getSupportedDiagTestsFromFW(void *pOsSysman, std::vector<std::string> &supportedDiagTests) {
supportedDiagTests.clear();
}
} // namespace Sysman
} // namespace L0

View File

@ -0,0 +1,24 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "level_zero/sysman/source/diagnostics/sysman_os_diagnostics.h"
#include "level_zero/sysman/source/windows/zes_os_sysman_imp.h"
namespace L0 {
namespace Sysman {
class WddmDiagnosticsImp : public OsDiagnostics {
public:
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 Sysman
} // namespace L0

View File

@ -307,7 +307,9 @@ void LinuxSysmanImp::releaseSysmanDeviceResources() {
ze_result_t LinuxSysmanImp::reInitSysmanDeviceResources() {
createPmtHandles();
if (!diagnosticsReset) {
createFwUtilInterface();
if (pFwUtilInterface == nullptr) {
createFwUtilInterface();
}
}
if (getSysmanDeviceImp()->pRasHandleContext->isRasInitDone()) {
getSysmanDeviceImp()->pRasHandleContext->init(getSubDeviceCount());
@ -320,7 +322,8 @@ ze_result_t LinuxSysmanImp::reInitSysmanDeviceResources() {
getSysmanDeviceImp()->pDiagnosticsHandleContext->init();
}
}
this->diagnosticsReset = false;
diagnosticsReset = false;
isMemoryDiagnostics = false;
if (getSysmanDeviceImp()->pFirmwareHandleContext->isFirmwareInitDone()) {
getSysmanDeviceImp()->pFirmwareHandleContext->init();
}
@ -429,7 +432,18 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
NEO::sleep(std::chrono::seconds(10)); // Sleep for 10seconds just to make sure the change is propagated.
this->pwriteFunction(fd, &value, 0x01, offset);
NEO::sleep(std::chrono::seconds(10)); // Sleep for 10seconds to make sure the change is propagated. before rescan is done.
if (isMemoryDiagnostics) {
int32_t delayDurationForPPR = 6; // Sleep for 6 minutes to allow PPR to complete.
if (NEO::DebugManager.flags.DebugSetMemoryDiagnosticsDelay.get() != -1) {
delayDurationForPPR = NEO::DebugManager.flags.DebugSetMemoryDiagnosticsDelay.get();
}
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
"Delay of %d mins introduced to allow HBM IFR to complete\n", delayDurationForPPR);
NEO::sleep(std::chrono::seconds(delayDurationForPPR * 60));
} else {
NEO::sleep(std::chrono::seconds(10)); // Sleep for 10 seconds to make sure writing to bridge control offset is propagated.
}
result = pFsAccess->write(rootPortPath + '/' + "rescan", "1");
if (ZE_RESULT_SUCCESS != result) {
return result;

View File

@ -53,8 +53,8 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
SysmanHwDeviceIdDrm *getSysmanHwDeviceId();
NEO::Drm *getDrm();
void releasePmtObject();
void releaseSysmanDeviceResources();
ze_result_t reInitSysmanDeviceResources();
MOCKABLE_VIRTUAL void releaseSysmanDeviceResources();
MOCKABLE_VIRTUAL ze_result_t reInitSysmanDeviceResources();
MOCKABLE_VIRTUAL void getPidFdsForOpenDevice(ProcfsAccess *, SysfsAccess *, const ::pid_t, std::vector<int> &);
MOCKABLE_VIRTUAL ze_result_t osWarmReset();
MOCKABLE_VIRTUAL ze_result_t osColdReset();
@ -71,6 +71,7 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
uint32_t rootDeviceIndex;
bool diagnosticsReset = false;
bool isMemoryDiagnostics = false;
std::string gtDevicePath;
protected:

View File

@ -0,0 +1,11 @@
#
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
)
add_subdirectories()

View File

@ -0,0 +1,18 @@
#
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(L0_TESTS_SYSMAN_DIAGNOSTICS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_sysman_diagnostics.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_zes_sysman_diagnostics.h
)
if(UNIX)
target_sources(${TARGET_NAME}
PRIVATE
${L0_TESTS_SYSMAN_DIAGNOSTICS_LINUX}
)
endif()

View File

@ -0,0 +1,264 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/sysman/source/diagnostics/linux/sysman_os_diagnostics_imp.h"
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h"
namespace L0 {
namespace ult {
uint32_t mockDiagHandleCount = 2;
const std::string mockQuiescentGpuFile("quiesce_gpu");
const std::string mockinvalidateLmemFile("invalidate_lmem_mmaps");
const std::vector<std::string> mockSupportedDiagTypes = {"MOCKSUITE1", "MOCKSUITE2"};
const std::string deviceDirDiag("device");
const std::string mockRealPathConfig("/sys/devices/pci0000:89/0000:89:02.0/config");
const std::string mockdeviceDirDiag("/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0");
const std::string mockdeviceDirConfig("/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0/config");
const std::string mockDeviceName("/MOCK_DEVICE_NAME");
const std::string mockRemove("remove");
const std::string mockRescan("rescan");
const std::string mockSlotPath("/sys/bus/pci/slots/");
const std::string mockSlotPath1("/sys/bus/pci/slots/1/");
const std::string mockCorrectRootAddress("0000:8a:00.0");
const std::string mockWrongRootAddress("0000:7a:00.0");
struct MockDiagnosticsFwInterface : public L0::Sysman::FirmwareUtil {
zes_diag_result_t mockDiagResult = ZES_DIAG_RESULT_NO_ERRORS;
ze_result_t mockFwInitResult = ZE_RESULT_SUCCESS;
ze_result_t mockFwRunDiagTestsResult = ZE_RESULT_SUCCESS;
ze_result_t fwDeviceInit(void) override {
return mockFwInitResult;
}
void setFwInitRetVal(ze_result_t val) {
mockFwInitResult = val;
}
ze_result_t getFirstDevice(igsc_device_info *info) override {
return ZE_RESULT_SUCCESS;
}
ze_result_t fwSupportedDiagTests(std::vector<std::string> &supportedDiagTests) override {
supportedDiagTests.push_back(mockSupportedDiagTypes[0]);
supportedDiagTests.push_back(mockSupportedDiagTypes[1]);
return ZE_RESULT_SUCCESS;
}
ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pResult) override {
*pResult = mockDiagResult;
return mockFwRunDiagTestsResult;
}
void setDiagResult(zes_diag_result_t result) {
mockDiagResult = result;
}
MockDiagnosticsFwInterface() = default;
ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion));
ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size));
ADDMETHOD_NOBASE(fwIfrApplied, ze_result_t, ZE_RESULT_SUCCESS, (bool &ifrStatus));
ADDMETHOD_NOBASE(fwGetMemoryErrorCount, ze_result_t, ZE_RESULT_SUCCESS, (zes_ras_error_type_t category, uint32_t subDeviceCount, uint32_t subDeviceId, uint64_t &count));
ADDMETHOD_NOBASE(fwGetEccConfig, ze_result_t, ZE_RESULT_SUCCESS, (uint8_t * currentState, uint8_t *pendingState));
ADDMETHOD_NOBASE(fwSetEccConfig, ze_result_t, ZE_RESULT_SUCCESS, (uint8_t newState, uint8_t *currentState, uint8_t *pendingState));
ADDMETHOD_NOBASE_VOIDRETURN(getDeviceSupportedFwTypes, (std::vector<std::string> & fwTypes));
ADDMETHOD_NOBASE_VOIDRETURN(fwGetMemoryHealthIndicator, (zes_mem_health_t * health));
};
struct MockGlobalOperationsEngineHandleContext : public L0::Sysman::EngineHandleContext {
MockGlobalOperationsEngineHandleContext(L0::Sysman::OsSysman *pOsSysman) : L0::Sysman::EngineHandleContext(pOsSysman) {}
void init(uint32_t subDeviceCount) override {}
};
struct MockDiagFsAccess : public L0::Sysman::FsAccess {
ze_result_t mockReadError = ZE_RESULT_SUCCESS;
ze_result_t mockWriteError = ZE_RESULT_SUCCESS;
ze_result_t mockListDirError = ZE_RESULT_SUCCESS;
int checkErrorAfterCount = 0;
std::string mockRootAddress = mockCorrectRootAddress;
ze_result_t write(const std::string file, std::string val) override {
if (checkErrorAfterCount) {
checkErrorAfterCount--;
} else {
if (mockWriteError != ZE_RESULT_SUCCESS) {
return mockWriteError;
}
}
if (!file.compare(mockSlotPath1 + "power")) {
return ZE_RESULT_SUCCESS;
}
if (std::string::npos != file.find(mockRemove)) {
return ZE_RESULT_SUCCESS;
} else if (std::string::npos != file.find(mockRescan)) {
return ZE_RESULT_SUCCESS;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
}
ze_result_t listDirectory(const std::string directory, std::vector<std::string> &listOfslots) override {
if (mockListDirError != ZE_RESULT_SUCCESS) {
return mockListDirError;
}
if (directory.compare(mockSlotPath) == 0) {
listOfslots.push_back("1");
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
ze_result_t read(const std::string file, std::string &val) override {
if (mockReadError != ZE_RESULT_SUCCESS) {
return mockReadError;
}
if (file.compare(mockSlotPath1)) {
val = mockRootAddress;
return ZE_RESULT_SUCCESS;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
}
void setWrongMockAddress() {
mockRootAddress = mockWrongRootAddress;
}
MockDiagFsAccess() = default;
};
struct MockDiagSysfsAccess : public L0::Sysman::SysfsAccess {
ze_result_t mockError = ZE_RESULT_SUCCESS;
int checkErrorAfterCount = 0;
ze_result_t getRealPath(const std::string file, std::string &val) override {
if (mockError != ZE_RESULT_SUCCESS) {
return mockError;
}
if (file.compare(deviceDirDiag) == 0) {
val = mockdeviceDirDiag;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t write(const std::string file, const int val) override {
if (checkErrorAfterCount) {
checkErrorAfterCount--;
} else {
if (mockError != ZE_RESULT_SUCCESS) {
return mockError;
}
}
if (std::string::npos != file.find(mockQuiescentGpuFile)) {
if (checkErrorAfterCount) {
return mockError;
}
return ZE_RESULT_SUCCESS;
} else if (std::string::npos != file.find(mockinvalidateLmemFile)) {
if (checkErrorAfterCount) {
return mockError;
}
return ZE_RESULT_SUCCESS;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
}
bool isMyDeviceFile(const std::string dev) override {
if (dev.compare(mockDeviceName) == 0) {
return true;
}
return false;
}
void setMockError(ze_result_t result) {
mockError = result;
}
void setErrorAfterCount(int count, ze_result_t result) {
checkErrorAfterCount = count;
setMockError(result);
}
MockDiagSysfsAccess() = default;
};
struct MockDiagProcfsAccess : public L0::Sysman::ProcfsAccess {
std::vector<::pid_t> pidList = {1, 2, 3};
::pid_t ourDevicePid = 0;
ze_result_t mockError = ZE_RESULT_SUCCESS;
ze_result_t listProcesses(std::vector<::pid_t> &list) override {
if (mockError != ZE_RESULT_SUCCESS) {
return mockError;
}
list = pidList;
if (ourDevicePid) {
list.push_back(ourDevicePid);
}
return ZE_RESULT_SUCCESS;
}
::pid_t myProcessId() override {
return ::getpid();
}
void kill(const ::pid_t pid) override {
ourDevicePid = 0;
}
void setMockError(ze_result_t result) {
mockError = result;
}
MockDiagProcfsAccess() = default;
};
struct MockDiagLinuxSysmanImp : public L0::Sysman::LinuxSysmanImp {
using L0::Sysman::LinuxSysmanImp::pProcfsAccess;
MockDiagLinuxSysmanImp(L0::Sysman::SysmanDeviceImp *pParentSysmanDeviceImp) : L0::Sysman::LinuxSysmanImp(pParentSysmanDeviceImp) {}
std::vector<int> fdList = {0, 1, 2};
::pid_t ourDevicePid = 0;
int ourDeviceFd = 0;
ze_result_t mockError = ZE_RESULT_SUCCESS;
ze_result_t mockReInitSysmanDeviceError = ZE_RESULT_SUCCESS;
void getPidFdsForOpenDevice(L0::Sysman::ProcfsAccess *pProcfsAccess, L0::Sysman::SysfsAccess *pSysfsAccess, const ::pid_t pid, std::vector<int> &deviceFds) override {
if (ourDevicePid) {
deviceFds.push_back(ourDeviceFd);
}
}
void releaseSysmanDeviceResources(void) override {}
ze_result_t reInitSysmanDeviceResources() override {
if (mockReInitSysmanDeviceError != ZE_RESULT_SUCCESS) {
return mockReInitSysmanDeviceError;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t osWarmReset() override {
if (mockError != ZE_RESULT_SUCCESS) {
return mockError;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t osColdReset() override {
if (mockError != ZE_RESULT_SUCCESS) {
return mockError;
}
return ZE_RESULT_SUCCESS;
}
void setMockError(ze_result_t result) {
mockError = result;
}
void setMockReInitSysmanDeviceError(ze_result_t result) {
mockReInitSysmanDeviceError = result;
}
};
class PublicLinuxDiagnosticsImp : public L0::Sysman::LinuxDiagnosticsImp {
public:
using L0::Sysman::LinuxDiagnosticsImp::gpuProcessCleanup;
using L0::Sysman::LinuxDiagnosticsImp::pFwInterface;
using L0::Sysman::LinuxDiagnosticsImp::pLinuxSysmanImp;
using L0::Sysman::LinuxDiagnosticsImp::pSysfsAccess;
using L0::Sysman::LinuxDiagnosticsImp::waitForQuiescentCompletion;
};
} // namespace ult
} // namespace L0

View File

@ -0,0 +1,819 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/helpers/ult_hw_config.h"
#include "level_zero/sysman/test/unit_tests/sources/diagnostics/linux/mock_zes_sysman_diagnostics.h"
namespace L0 {
namespace ult {
static int mockFileDescriptor = 123;
static int mockGtPciConfigFd = 124;
inline static int openMockDiag(const char *pathname, int flags) {
if (strcmp(pathname, mockRealPathConfig.c_str()) == 0) {
return mockFileDescriptor;
} else if (strcmp(pathname, mockdeviceDirConfig.c_str()) == 0) {
return mockGtPciConfigFd;
}
return -1;
}
void mockSleepFunctionSecs(int64_t secs) {
return;
}
inline static int openMockDiagFail(const char *pathname, int flags) {
return -1;
}
inline static int gtPciConfigOpenFail(const char *pathname, int flags) {
if (strcmp(pathname, mockRealPathConfig.c_str()) == 0) {
return mockFileDescriptor;
} else {
return -1;
}
}
inline static int closeMockDiag(int fd) {
if ((fd == mockFileDescriptor) || (fd == mockGtPciConfigFd)) {
return 0;
}
return -1;
}
inline static int closeMockDiagFail(int fd) {
return -1;
}
inline static int mockGtConfigcloseFail(int fd) {
if (fd == mockGtPciConfigFd) {
return -1;
}
return 0;
}
ssize_t preadMockDiag(int fd, void *buf, size_t count, off_t offset) {
uint8_t *mockBuf = static_cast<uint8_t *>(buf);
if (fd == mockGtPciConfigFd) {
mockBuf[0x006] = 0x24;
mockBuf[0x034] = 0x40;
mockBuf[0x040] = 0x0d;
mockBuf[0x041] = 0x50;
mockBuf[0x050] = 0x10;
mockBuf[0x051] = 0x70;
mockBuf[0x052] = 0x90;
mockBuf[0x070] = 0x10;
mockBuf[0x071] = 0xac;
mockBuf[0x072] = 0xa0;
mockBuf[0x0ac] = 0x10;
mockBuf[0x0b8] = 0x11;
mockBuf[0x100] = 0x0e;
mockBuf[0x102] = 0x24;
mockBuf[0x103] = 0x42;
mockBuf[0x420] = 0x15;
mockBuf[0x422] = 0x01;
mockBuf[0x423] = 0x22;
mockBuf[0x425] = 0xf0;
mockBuf[0x426] = 0x3f;
mockBuf[0x428] = 0x22;
mockBuf[0x429] = 0x11;
mockBuf[0x220] = 0x24;
mockBuf[0x222] = 0x24;
mockBuf[0x223] = 0x24;
mockBuf[0x320] = 0x10;
mockBuf[0x322] = 0x01;
mockBuf[0x323] = 0x40;
mockBuf[0x400] = 0x18;
mockBuf[0x402] = 0x01;
}
return count;
}
ssize_t mockGtConfigPreadInvalid(int fd, void *buf, size_t count, off_t offset) {
return count;
}
ssize_t mockGtConfigPreadFail(int fd, void *buf, size_t count, off_t offset) {
if (fd == mockGtPciConfigFd) {
return -1;
}
return count;
}
ssize_t mockGtConfigPwriteFail(int fd, const void *buf, size_t count, off_t offset) {
if (fd == mockGtPciConfigFd) {
return -1;
}
return count;
}
ssize_t pwriteMockDiag(int fd, const void *buf, size_t count, off_t offset) {
return count;
}
class ZesDiagnosticsFixture : public SysmanDeviceFixture {
protected:
zes_diag_handle_t hSysmanDiagnostics = {};
std::unique_ptr<MockDiagnosticsFwInterface> pMockDiagFwInterface;
std::unique_ptr<MockDiagSysfsAccess> pMockSysfsAccess;
std::unique_ptr<MockDiagFsAccess> pMockFsAccess;
std::unique_ptr<MockDiagProcfsAccess> pMockDiagProcfsAccess;
std::unique_ptr<MockGlobalOperationsEngineHandleContext> pEngineHandleContext;
std::unique_ptr<MockDiagLinuxSysmanImp> pMockDiagLinuxSysmanImp;
L0::Sysman::FirmwareUtil *pFwUtilInterfaceOld = nullptr;
L0::Sysman::SysfsAccess *pSysfsAccessOld = nullptr;
L0::Sysman::FsAccess *pFsAccessOld = nullptr;
L0::Sysman::ProcfsAccess *pProcfsAccessOld = nullptr;
L0::Sysman::EngineHandleContext *pEngineHandleContextOld = nullptr;
L0::Sysman::SysmanDevice *device = nullptr;
void SetUp() override {
SysmanDeviceFixture::SetUp();
device = pSysmanDevice;
pEngineHandleContextOld = pSysmanDeviceImp->pEngineHandleContext;
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess;
pFsAccessOld = pLinuxSysmanImp->pFsAccess;
pProcfsAccessOld = pLinuxSysmanImp->pProcfsAccess;
pFwUtilInterfaceOld = pLinuxSysmanImp->pFwUtilInterface;
pEngineHandleContext = std::make_unique<MockGlobalOperationsEngineHandleContext>(pOsSysman);
pMockDiagFwInterface = std::make_unique<MockDiagnosticsFwInterface>();
pMockSysfsAccess = std::make_unique<MockDiagSysfsAccess>();
pMockFsAccess = std::make_unique<MockDiagFsAccess>();
pMockDiagProcfsAccess = std::make_unique<MockDiagProcfsAccess>();
pMockDiagLinuxSysmanImp = std::make_unique<MockDiagLinuxSysmanImp>(pLinuxSysmanImp->getSysmanDeviceImp());
pSysmanDeviceImp->pEngineHandleContext = pEngineHandleContext.get();
pLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pLinuxSysmanImp->pSysfsAccess = pMockSysfsAccess.get();
pLinuxSysmanImp->pFsAccess = pMockFsAccess.get();
pLinuxSysmanImp->pFwUtilInterface = pMockDiagFwInterface.get();
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
}
void TearDown() override {
pSysmanDeviceImp->pEngineHandleContext = pEngineHandleContextOld;
pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld;
pLinuxSysmanImp->pFsAccess = pFsAccessOld;
pLinuxSysmanImp->pProcfsAccess = pProcfsAccessOld;
SysmanDeviceFixture::TearDown();
}
void clearAndReinitHandles() {
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
pSysmanDeviceImp->pDiagnosticsHandleContext->supportedDiagTests.clear();
}
};
HWTEST2_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDiagnosticTestSuitesThenZeroCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesCallSucceeds, IsPVC) {
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);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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();
}
HWTEST2_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDiagnosticTestSuitesThenZeroCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesCallSucceeds, IsNotPVC) {
mockDiagHandleCount = 0;
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);
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsPropertiesThenCallSucceeds) {
clearAndReinitHandles();
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(ptestDiagnosticsImp));
auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle();
zes_diag_properties_t properties = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDiagnosticsGetProperties(handle, &properties));
EXPECT_EQ(properties.haveTests, 0);
EXPECT_FALSE(properties.onSubdevice);
EXPECT_EQ(properties.name, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDevicePointerWhenGettingDiagnosticsPropertiesThenValidDiagPropertiesRetrieved) {
zes_diag_properties_t properties = {};
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
uint32_t subdeviceId = 0;
std::unique_ptr<L0::Sysman::LinuxDiagnosticsImp> pLinuxDiagnosticsImp = std::make_unique<L0::Sysman::LinuxDiagnosticsImp>(pOsSysman, mockSupportedDiagTypes[0]);
pLinuxDiagnosticsImp->osGetDiagProperties(&properties);
EXPECT_EQ(properties.subdeviceId, subdeviceId);
EXPECT_EQ(properties.onSubdevice, onSubdevice);
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsTestThenCallSucceeds) {
clearAndReinitHandles();
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenRunningDiagnosticsTestThenCallSucceeds) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
pPublicLinuxDiagnosticsImp->osDiagType = "MEMORY_PPR";
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_SUCCESS, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_NO_ERRORS);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenRunningDiagnosticsTestAndFwRunDiagTestFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockDiagFwInterface->setDiagResult(ZES_DIAG_RESULT_FORCE_UINT32);
pMockDiagFwInterface->mockFwRunDiagTestsResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_FORCE_UINT32);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenListProcessFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockDiagProcfsAccess->setMockError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_FORCE_UINT32);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenQuiescentingFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockSysfsAccess->setMockError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_FORCE_UINT32);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenInvalidateLmemFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockSysfsAccess->setMockError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_FORCE_UINT32);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenColdResetFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockDiagFwInterface->setDiagResult(ZES_DIAG_RESULT_REBOOT_FOR_REPAIR);
pMockDiagLinuxSysmanImp->setMockError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_REBOOT_FOR_REPAIR);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenWarmResetFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockDiagLinuxSysmanImp->setMockError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_NO_ERRORS);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenWarmResetSucceedsAndInitDeviceFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockDiagLinuxSysmanImp->setMockReInitSysmanDeviceError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_NO_ERRORS);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenColdResetSucceedsAndInitDeviceFailsThenCallFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockDiagFwInterface->setDiagResult(ZES_DIAG_RESULT_REBOOT_FOR_REPAIR);
pMockDiagLinuxSysmanImp->setMockReInitSysmanDeviceError(ZE_RESULT_ERROR_NOT_AVAILABLE);
std::unique_ptr<L0::Sysman::DiagnosticsImp> ptestDiagnosticsImp = std::make_unique<L0::Sysman::DiagnosticsImp>(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
std::unique_ptr<L0::Sysman::OsDiagnostics> pOsDiagnosticsPrev = std::move(ptestDiagnosticsImp->pOsDiagnostics);
ptestDiagnosticsImp->pOsDiagnostics = std::move(pPublicLinuxDiagnosticsImp);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(std::move(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_NOT_AVAILABLE, zesDiagnosticsRunTests(handle, start, end, &results));
EXPECT_EQ(results, ZES_DIAG_RESULT_REBOOT_FOR_REPAIR);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGPUProcessCleanupSucceedsThenCallSucceeds) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
pMockDiagProcfsAccess->ourDevicePid = getpid();
pMockDiagLinuxSysmanImp->ourDevicePid = getpid();
pMockDiagLinuxSysmanImp->ourDeviceFd = NEO::SysCalls::open("/dev/null", 0);
EXPECT_EQ(ZE_RESULT_SUCCESS, pPublicLinuxDiagnosticsImp->pLinuxSysmanImp->gpuProcessCleanup());
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGPUProcessCleanupFailsThenWaitForQuiescentCompletionsFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockSysfsAccess->setMockError(ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE);
pMockDiagProcfsAccess->setMockError(ZE_RESULT_ERROR_NOT_AVAILABLE);
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pPublicLinuxDiagnosticsImp->waitForQuiescentCompletion());
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenQuiescentFailsContinuouslyFailsThenWaitForQuiescentCompletionsFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockSysfsAccess->setErrorAfterCount(12, ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE);
EXPECT_EQ(ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, pPublicLinuxDiagnosticsImp->waitForQuiescentCompletion());
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenInvalidateLmemFailsThenWaitForQuiescentCompletionsFails) {
clearAndReinitHandles();
std::unique_ptr<PublicLinuxDiagnosticsImp> pPublicLinuxDiagnosticsImp = std::make_unique<PublicLinuxDiagnosticsImp>();
pPublicLinuxDiagnosticsImp->pSysfsAccess = pMockSysfsAccess.get();
pPublicLinuxDiagnosticsImp->pFwInterface = pMockDiagFwInterface.get();
pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get();
VariableBackup<L0::Sysman::ProcfsAccess *> backup(&pMockDiagLinuxSysmanImp->pProcfsAccess);
pMockDiagLinuxSysmanImp->pProcfsAccess = pMockDiagProcfsAccess.get();
pMockSysfsAccess->setErrorAfterCount(1, ZE_RESULT_ERROR_NOT_AVAILABLE);
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pPublicLinuxDiagnosticsImp->waitForQuiescentCompletion());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetThenCallSucceeds) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtPciConfigOpenFailsThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = gtPciConfigOpenFail;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndConfigHeaderIsInvalidThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = mockGtConfigPreadInvalid;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigPreadFailsThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = mockGtConfigPreadFail;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigPwriteFailsThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = mockGtConfigPwriteFail;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndGtConfigCloseFailsThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = mockGtConfigcloseFail;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndCardBusRemoveFailsThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pMockFsAccess->checkErrorAfterCount = 2;
pMockFsAccess->mockWriteError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetAndRootPortRescanFailsThenCallReturnsFailure) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pMockFsAccess->checkErrorAfterCount = 3;
pMockFsAccess->mockWriteError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndVfBarIsResizedWhenCallingWarmResetThenCallSucceeds) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetfromDiagnosticsThenCallSucceeds) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pLinuxSysmanImp->diagnosticsReset = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetfromHBMDiagnosticsThenCallSucceeds) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pLinuxSysmanImp->diagnosticsReset = true;
pLinuxSysmanImp->isMemoryDiagnostics = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerAndDelayForPPRWhenCallingWarmResetfromHBMDiagnosticsThenCallSucceeds) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.DebugSetMemoryDiagnosticsDelay.set(7);
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pLinuxSysmanImp->diagnosticsReset = true;
pLinuxSysmanImp->isMemoryDiagnostics = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndRootPortConfigFileFailsToOpenThenCallFails) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiagFail;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndRootPortConfigFileFailsToCloseThenCallFails) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiagFail;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndCardbusRemoveFailsThenCallFails) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pMockFsAccess->mockWriteError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingWarmResetAndRootPortRescanFailsThenCallFails) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.VfBarResourceAllocationWa.set(false);
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pLinuxSysmanImp->openFunction = openMockDiag;
pLinuxSysmanImp->closeFunction = closeMockDiag;
pLinuxSysmanImp->preadFunction = preadMockDiag;
pLinuxSysmanImp->pwriteFunction = pwriteMockDiag;
pMockFsAccess->checkErrorAfterCount = 1;
pMockFsAccess->mockWriteError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osWarmReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingColdResetThenCallSucceeds) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->osColdReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingColdResetAndListDirFailsThenCallFails) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pMockFsAccess->mockListDirError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osColdReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingColdResetAndReadSlotAddressFailsThenCallFails) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pMockFsAccess->mockReadError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osColdReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingColdResetandWriteFailsThenCallFails) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pMockFsAccess->mockWriteError = ZE_RESULT_ERROR_NOT_AVAILABLE;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osColdReset());
pMockFsAccess->checkErrorAfterCount = 1;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxSysmanImp->osColdReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingColdResetandWrongSlotAddressIsReturnedThenCallFails) {
pLinuxSysmanImp->gtDevicePath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0";
pMockFsAccess->setWrongMockAddress();
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, pLinuxSysmanImp->osColdReset());
}
TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingReleaseSysmanResourcesAndReInitSysmanDeviceThenCallSucceeds) {
pLinuxSysmanImp->diagnosticsReset = true;
pLinuxSysmanImp->releaseSysmanDeviceResources();
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->reInitSysmanDeviceResources());
}
HWTEST2_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleAndHandleCountZeroWhenCallingReInitThenValidCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesSucceeds, IsPVC) {
uint32_t count = 0;
ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
pSysmanDeviceImp->pDiagnosticsHandleContext->supportedDiagTests.clear();
pLinuxSysmanImp->diagnosticsReset = false;
pLinuxSysmanImp->reInitSysmanDeviceResources();
count = 0;
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
}
HWTEST2_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleAndHandleCountZeroWhenCallingReInitThenValidCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesSucceeds, IsNotPVC) {
uint32_t count = 0;
mockDiagHandleCount = 0;
ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
pSysmanDeviceImp->pDiagnosticsHandleContext->supportedDiagTests.clear();
pLinuxSysmanImp->diagnosticsReset = false;
pLinuxSysmanImp->reInitSysmanDeviceResources();
count = 0;
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
}
}; // namespace ult
}; // namespace L0