Add Ecc support for sysman windows

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
Mayank Raghuwanshi
2022-06-24 11:20:48 +00:00
committed by Compute-Runtime-Automation
parent afb57636b0
commit db20000450
17 changed files with 478 additions and 277 deletions

View File

@@ -8,7 +8,6 @@ set(L0_SRCS_TOOLS_SYSMAN_ECC
${CMAKE_CURRENT_SOURCE_DIR}/ecc.h
${CMAKE_CURRENT_SOURCE_DIR}/ecc_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ecc_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc.h
)
target_include_directories(${L0_STATIC_LIB_NAME}

View File

@@ -7,34 +7,116 @@
#include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h"
namespace L0 {
zes_device_ecc_state_t EccImp::getEccState(uint8_t state) {
switch (state) {
case eccStateEnable:
return ZES_DEVICE_ECC_STATE_ENABLED;
case eccStateDisable:
return ZES_DEVICE_ECC_STATE_DISABLED;
default:
return ZES_DEVICE_ECC_STATE_UNAVAILABLE;
}
}
ze_result_t EccImp::getEccFwUtilInterface(FirmwareUtil *&pFwUtil) {
pFwUtil = getFirmwareUtilInterface(pOsSysman);
if (pFwUtil == nullptr) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t result = pFwUtil->fwDeviceInit();
if (result != ZE_RESULT_SUCCESS) {
pFwUtil = nullptr;
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t EccImp::deviceEccAvailable(ze_bool_t *pAvailable) {
return pOsEcc->deviceEccAvailable(pAvailable);
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
}
*pAvailable = false;
uint8_t currentState = 0;
uint8_t pendingState = 0;
ze_result_t result = pFwInterface->fwGetEccConfig(&currentState, &pendingState);
if (ZE_RESULT_SUCCESS == result) {
if ((currentState != eccStateNone) && (pendingState != eccStateNone)) {
*pAvailable = true;
}
}
return result;
}
ze_result_t EccImp::deviceEccConfigurable(ze_bool_t *pConfigurable) {
return pOsEcc->deviceEccConfigurable(pConfigurable);
return deviceEccAvailable(pConfigurable);
}
ze_result_t EccImp::getEccState(zes_device_ecc_properties_t *pState) {
return pOsEcc->getEccState(pState);
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
}
uint8_t currentState = 0;
uint8_t pendingState = 0;
ze_result_t result = pFwInterface->fwGetEccConfig(&currentState, &pendingState);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
pState->currentState = getEccState(currentState);
pState->pendingState = getEccState(pendingState);
pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET;
if (pState->currentState == pState->pendingState) {
pState->pendingAction = ZES_DEVICE_ACTION_NONE;
}
return result;
}
ze_result_t EccImp::setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) {
return pOsEcc->setEccState(newState, pState);
}
void EccImp::init() {
if (pOsEcc == nullptr) {
pOsEcc = OsEcc::create(pOsSysman);
if (pFwInterface == nullptr) {
ze_result_t result = getEccFwUtilInterface(pFwInterface);
if (result != ZE_RESULT_SUCCESS) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
}
}
EccImp::~EccImp() {
if (nullptr != pOsEcc) {
delete pOsEcc;
uint8_t state = 0;
uint8_t currentState = 0;
uint8_t pendingState = 0;
if (newState->state == ZES_DEVICE_ECC_STATE_ENABLED) {
state = eccStateEnable;
} else if (newState->state == ZES_DEVICE_ECC_STATE_DISABLED) {
state = eccStateDisable;
} else {
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
ze_result_t result = pFwInterface->fwSetEccConfig(state, &currentState, &pendingState);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
pState->currentState = getEccState(currentState);
pState->pendingState = getEccState(pendingState);
pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET;
if (pState->currentState == pState->pendingState) {
pState->pendingAction = ZES_DEVICE_ACTION_NONE;
}
return result;
}
} // namespace L0

View File

@@ -9,24 +9,31 @@
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "level_zero/tools/source/sysman/ecc/ecc.h"
#include "level_zero/tools/source/sysman/ecc/os_ecc.h"
namespace L0 {
class FirmwareUtil;
struct OsSysman;
class EccImp : public Ecc, NEO::NonCopyableOrMovableClass {
public:
void init() override;
void init() override {}
ze_result_t deviceEccAvailable(ze_bool_t *pAvailable) override;
ze_result_t deviceEccConfigurable(ze_bool_t *pConfigurable) override;
ze_result_t getEccState(zes_device_ecc_properties_t *pState) override;
ze_result_t setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) override;
OsEcc *pOsEcc = nullptr;
EccImp(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
~EccImp() override;
~EccImp() override {}
private:
OsSysman *pOsSysman = nullptr;
FirmwareUtil *pFwInterface = nullptr;
static constexpr uint8_t eccStateDisable = 0;
static constexpr uint8_t eccStateEnable = 1;
static constexpr uint8_t eccStateNone = 0xFF;
zes_device_ecc_state_t getEccState(uint8_t state);
static FirmwareUtil *getFirmwareUtilInterface(OsSysman *pOsSysman);
ze_result_t getEccFwUtilInterface(FirmwareUtil *&pFwUtil);
};
} // namespace L0

View File

@@ -6,8 +6,7 @@
set(L0_SRCS_TOOLS_SYSMAN_ECC_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc.cpp
)
if(UNIX)

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h"
namespace L0 {
class LinuxSysmanImp;
class FirmwareUtil;
FirmwareUtil *EccImp::getFirmwareUtilInterface(OsSysman *pOsSysman) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
return pLinuxSysmanImp->getFwUtilInterface();
}
} // namespace L0

View File

@@ -1,114 +0,0 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/ecc/linux/os_ecc_imp.h"
#include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h"
namespace L0 {
zes_device_ecc_state_t LinuxEccImp::getEccState(uint8_t state) {
switch (state) {
case eccStateEnable:
return ZES_DEVICE_ECC_STATE_ENABLED;
case eccStateDisable:
return ZES_DEVICE_ECC_STATE_DISABLED;
default:
return ZES_DEVICE_ECC_STATE_UNAVAILABLE;
}
}
ze_result_t LinuxEccImp::deviceEccAvailable(ze_bool_t *pAvailable) {
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
if (pFwInterface == nullptr) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
*pAvailable = false;
uint8_t currentState = 0;
uint8_t pendingState = 0;
ze_result_t result = pFwInterface->fwGetEccConfig(&currentState, &pendingState);
if (ZE_RESULT_SUCCESS == result) {
if ((currentState != eccStateNone) && (pendingState != eccStateNone)) {
*pAvailable = true;
}
}
return result;
}
ze_result_t LinuxEccImp::deviceEccConfigurable(ze_bool_t *pConfigurable) {
return deviceEccAvailable(pConfigurable);
}
ze_result_t LinuxEccImp::getEccState(zes_device_ecc_properties_t *pState) {
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
if (pFwInterface == nullptr) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
uint8_t currentState = 0;
uint8_t pendingState = 0;
ze_result_t result = pFwInterface->fwGetEccConfig(&currentState, &pendingState);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
pState->currentState = getEccState(currentState);
pState->pendingState = getEccState(pendingState);
pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET;
if (pState->currentState == pState->pendingState) {
pState->pendingAction = ZES_DEVICE_ACTION_NONE;
}
return result;
}
ze_result_t LinuxEccImp::setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) {
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
if (pFwInterface == nullptr) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
uint8_t state = 0;
uint8_t currentState = 0;
uint8_t pendingState = 0;
if (newState->state == ZES_DEVICE_ECC_STATE_ENABLED) {
state = eccStateEnable;
} else if (newState->state == ZES_DEVICE_ECC_STATE_DISABLED) {
state = eccStateDisable;
} else {
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
}
ze_result_t result = pFwInterface->fwSetEccConfig(state, &currentState, &pendingState);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
pState->currentState = getEccState(currentState);
pState->pendingState = getEccState(pendingState);
pState->pendingAction = ZES_DEVICE_ACTION_WARM_CARD_RESET;
if (pState->currentState == pState->pendingState) {
pState->pendingAction = ZES_DEVICE_ACTION_NONE;
}
return result;
}
LinuxEccImp::LinuxEccImp(OsSysman *pOsSysman) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
}
OsEcc *OsEcc::create(OsSysman *pOsSysman) {
LinuxEccImp *pLinuxEccImp = new LinuxEccImp(pOsSysman);
return static_cast<OsEcc *>(pLinuxEccImp);
}
} // namespace L0

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/tools/source/sysman/ecc/os_ecc.h"
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h"
namespace L0 {
class LinuxSysmanImp;
class FirmwareUtil;
class LinuxEccImp : public OsEcc, NEO::NonCopyableOrMovableClass {
public:
ze_result_t deviceEccAvailable(ze_bool_t *pAvailable) override;
ze_result_t deviceEccConfigurable(ze_bool_t *pConfigurable) override;
ze_result_t getEccState(zes_device_ecc_properties_t *pState) override;
ze_result_t setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) override;
LinuxEccImp() = default;
LinuxEccImp(OsSysman *pOsSysman);
~LinuxEccImp() override = default;
protected:
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
private:
static constexpr uint8_t eccStateDisable = 0;
static constexpr uint8_t eccStateEnable = 1;
static constexpr uint8_t eccStateNone = 0xFF;
zes_device_ecc_state_t getEccState(uint8_t state);
};
} // namespace L0

View File

@@ -1,25 +0,0 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/tools/source/sysman/os_sysman.h"
#include <level_zero/zes_api.h>
namespace L0 {
class OsEcc {
public:
virtual ze_result_t deviceEccAvailable(ze_bool_t *pAvailable) = 0;
virtual ze_result_t deviceEccConfigurable(ze_bool_t *pConfigurable) = 0;
virtual ze_result_t getEccState(zes_device_ecc_properties_t *pState) = 0;
virtual ze_result_t setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) = 0;
static OsEcc *create(OsSysman *pOsSysman);
virtual ~OsEcc() = default;
};
} // namespace L0

View File

@@ -6,8 +6,7 @@
set(L0_SRCS_TOOLS_SYSMAN_ECC_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_ecc.cpp
)
if(WIN32)

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
#include "level_zero/tools/source/sysman/windows/os_sysman_imp.h"
namespace L0 {
class WddmSysmanImp;
class FirmwareUtil;
FirmwareUtil *EccImp::getFirmwareUtilInterface(OsSysman *pOsSysman) {
WddmSysmanImp *pWddmSysmanImp = static_cast<WddmSysmanImp *>(pOsSysman);
return pWddmSysmanImp->getFwUtilInterface();
}
} // namespace L0

View File

@@ -1,35 +0,0 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/ecc/windows/os_ecc_imp.h"
namespace L0 {
ze_result_t WddmEccImp::deviceEccAvailable(ze_bool_t *pAvailable) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t WddmEccImp::deviceEccConfigurable(ze_bool_t *pConfigurable) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t WddmEccImp::getEccState(zes_device_ecc_properties_t *pState) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t WddmEccImp::setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
WddmEccImp::WddmEccImp(OsSysman *pOsSysman) {
}
OsEcc *OsEcc::create(OsSysman *pOsSysman) {
WddmEccImp *pWddmEccImp = new WddmEccImp(pOsSysman);
return static_cast<OsEcc *>(pWddmEccImp);
}
} // namespace L0

View File

@@ -1,28 +0,0 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "sysman/ecc/os_ecc.h"
#include "sysman/windows/os_sysman_imp.h"
namespace L0 {
class WddmEccImp : public OsEcc {
public:
ze_result_t deviceEccAvailable(ze_bool_t *pAvailable) override;
ze_result_t deviceEccConfigurable(ze_bool_t *pConfigurable) override;
ze_result_t getEccState(zes_device_ecc_properties_t *pState) override;
ze_result_t setEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) override;
WddmEccImp(OsSysman *pOsSysman);
WddmEccImp() = default;
~WddmEccImp() override = default;
};
} // namespace L0

View File

@@ -7,7 +7,7 @@
#pragma once
#include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
#include "level_zero/tools/source/sysman/ecc/linux/os_ecc_imp.h"
#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
namespace L0 {
@@ -18,10 +18,16 @@ template <>
struct Mock<EccFwInterface> : public EccFwInterface {
ze_result_t mockFwGetEccConfigResult = ZE_RESULT_SUCCESS;
ze_result_t mockFwSetEccConfigResult = ZE_RESULT_SUCCESS;
ze_result_t mockFwDeviceInit = ZE_RESULT_SUCCESS;
ze_bool_t mockSetConfig = true;
uint8_t mockCurrentState = 0;
uint8_t mockPendingState = 0;
ze_result_t fwDeviceInit() override {
return mockFwDeviceInit;
}
ze_result_t fwGetEccConfig(uint8_t *currentState, uint8_t *pendingState) override {
if (mockFwGetEccConfigResult != ZE_RESULT_SUCCESS) {
return mockFwGetEccConfigResult;
@@ -47,7 +53,6 @@ struct Mock<EccFwInterface> : public EccFwInterface {
return ZE_RESULT_SUCCESS;
}
ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, ());
ADDMETHOD_NOBASE(getFirstDevice, ze_result_t, ZE_RESULT_SUCCESS, (igsc_device_info * info));
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));

View File

@@ -21,7 +21,6 @@ class ZesEccFixture : public SysmanDeviceFixture {
protected:
std::unique_ptr<Mock<EccFwInterface>> pMockFwInterface;
FirmwareUtil *pFwUtilInterfaceOld = nullptr;
OsEcc *pOsEccPrev = nullptr;
L0::EccImp *pEccImp;
void SetUp() override {
@@ -34,8 +33,6 @@ class ZesEccFixture : public SysmanDeviceFixture {
pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface.get();
pEccImp = static_cast<L0::EccImp *>(pSysmanDeviceImp->pEcc);
pOsEccPrev = pEccImp->pOsEcc;
pEccImp->pOsEcc = nullptr;
pEccImp->init();
}
@@ -44,10 +41,6 @@ class ZesEccFixture : public SysmanDeviceFixture {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
if (nullptr != pEccImp->pOsEcc) {
delete pEccImp->pOsEcc;
}
pEccImp->pOsEcc = pOsEccPrev;
pEccImp = nullptr;
pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
@@ -74,16 +67,36 @@ TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingze
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsAbsentWhenCallingEccApiThenVerifyApiCallReturnFailure) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
EccImp *tempEccImp = new EccImp(pOsSysman);
auto deviceImp = static_cast<L0::DeviceImp *>(pLinuxSysmanImp->getDeviceHandle());
deviceImp->driverInfo.reset(nullptr);
pLinuxSysmanImp->pFwUtilInterface = nullptr;
pEccImp->init();
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDeviceEccAvailable(device, &eccAvailable));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDeviceEccConfigurable(device, &eccConfigurable));
tempEccImp->init();
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccAvailable(&eccAvailable));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccConfigurable(&eccConfigurable));
zes_device_ecc_desc_t newState = {};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDeviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->setEccState(&newState, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->getEccState(&props));
delete tempEccImp;
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwDeviceInitFailsThenVerifyApiCallReturnFailure) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
pMockFwInterface->mockFwDeviceInit = ZE_RESULT_ERROR_UNKNOWN;
EccImp *tempEccImp = new EccImp(pOsSysman);
tempEccImp->init();
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccAvailable(&eccAvailable));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccConfigurable(&eccConfigurable));
zes_device_ecc_desc_t newState = {};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->setEccState(&newState, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->getEccState(&props));
delete tempEccImp;
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwGetEccConfigFailsWhenCallingzesDeviceEccConfigurableAndAvailableThenVerifyApiCallReturnsFailure) {

View File

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

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/core/test/unit_tests/mock.h"
#include "level_zero/tools/source/sysman/ecc/ecc_imp.h"
#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.h"
namespace L0 {
namespace ult {
class EccFwInterface : public FirmwareUtil {};
template <>
struct Mock<EccFwInterface> : public EccFwInterface {
ze_result_t mockFwGetEccConfigResult = ZE_RESULT_SUCCESS;
ze_result_t mockFwSetEccConfigResult = ZE_RESULT_SUCCESS;
ze_result_t mockFwDeviceInit = ZE_RESULT_SUCCESS;
ze_bool_t mockSetConfig = true;
uint8_t mockCurrentState = 0;
uint8_t mockPendingState = 0;
ze_result_t fwDeviceInit() {
return mockFwDeviceInit;
}
ze_result_t fwGetEccConfig(uint8_t *currentState, uint8_t *pendingState) override {
if (mockFwGetEccConfigResult != ZE_RESULT_SUCCESS) {
return mockFwGetEccConfigResult;
}
*currentState = mockCurrentState;
*pendingState = mockPendingState;
return ZE_RESULT_SUCCESS;
}
ze_result_t fwSetEccConfig(uint8_t newState, uint8_t *currentState, uint8_t *pendingState) override {
if (mockFwSetEccConfigResult != ZE_RESULT_SUCCESS) {
return mockFwSetEccConfigResult;
}
if (mockSetConfig == static_cast<ze_bool_t>(true)) {
mockPendingState = newState;
}
*currentState = mockCurrentState;
*pendingState = mockPendingState;
return ZE_RESULT_SUCCESS;
}
ADDMETHOD_NOBASE(getFirstDevice, ze_result_t, ZE_RESULT_SUCCESS, (igsc_device_info * info));
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(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector<std::string> & supportedDiagTests));
ADDMETHOD_NOBASE(fwRunDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::string & osDiagType, zes_diag_result_t *pResult));
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_VOIDRETURN(getDeviceSupportedFwTypes, (std::vector<std::string> & fwTypes));
Mock<EccFwInterface>() = default;
~Mock<EccFwInterface>() override = default;
};
} // namespace ult
} // namespace L0

View File

@@ -0,0 +1,213 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/test/unit_tests/sources/sysman/ecc/windows/mock_ecc.h"
extern bool sysmanUltsEnable;
using ::testing::Matcher;
using ::testing::NiceMock;
namespace L0 {
namespace ult {
static const uint8_t eccStateNone = 0xFF;
static const uint8_t eccStateEnable = 0x1;
class ZesEccFixture : public SysmanDeviceFixture {
protected:
std::unique_ptr<Mock<EccFwInterface>> pMockFwInterface;
FirmwareUtil *pFwUtilInterfaceOld = nullptr;
L0::EccImp *pEccImp;
void SetUp() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
SysmanDeviceFixture::SetUp();
pFwUtilInterfaceOld = pWddmSysmanImp->pFwUtilInterface;
pMockFwInterface = std::make_unique<NiceMock<Mock<EccFwInterface>>>();
pWddmSysmanImp->pFwUtilInterface = pMockFwInterface.get();
pEccImp = static_cast<L0::EccImp *>(pSysmanDeviceImp->pEcc);
pEccImp->init();
}
void TearDown() override {
if (!sysmanUltsEnable) {
GTEST_SKIP();
}
pEccImp = nullptr;
pWddmSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
SysmanDeviceFixture::TearDown();
}
};
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceEccAvailableThenVerifyApiCallSucceeds) {
ze_bool_t eccAvailable = false;
pEccImp->init();
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccAvailable(device, &eccAvailable));
EXPECT_EQ(true, eccAvailable);
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceEccConfigurableThenVerifyApiCallSucceeds) {
ze_bool_t eccConfigurable = false;
pEccImp->init();
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccConfigurable(device, &eccConfigurable));
EXPECT_EQ(true, eccConfigurable);
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsAbsentWhenCallingEccApiThenVerifyApiCallReturnFailure) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
EccImp *tempEccImp = new EccImp(pOsSysman);
auto deviceImp = static_cast<L0::DeviceImp *>(pWddmSysmanImp->getDeviceHandle());
deviceImp->driverInfo.reset(nullptr);
pWddmSysmanImp->pFwUtilInterface = nullptr;
tempEccImp->init();
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccAvailable(&eccAvailable));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccConfigurable(&eccConfigurable));
zes_device_ecc_desc_t newState = {};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->setEccState(&newState, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->getEccState(&props));
delete tempEccImp;
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwDeviceInitFailsThenVerifyApiCallReturnFailure) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
pMockFwInterface->mockFwDeviceInit = ZE_RESULT_ERROR_UNKNOWN;
EccImp *tempEccImp = new EccImp(pOsSysman);
tempEccImp->init();
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccAvailable(&eccAvailable));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccConfigurable(&eccConfigurable));
zes_device_ecc_desc_t newState = {};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->setEccState(&newState, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->getEccState(&props));
delete tempEccImp;
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwGetEccConfigFailsWhenCallingzesDeviceEccConfigurableAndAvailableThenVerifyApiCallReturnsFailure) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
pMockFwInterface->mockFwGetEccConfigResult = ZE_RESULT_ERROR_UNINITIALIZED;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEccAvailable(device, &eccAvailable));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEccConfigurable(device, &eccConfigurable));
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndCurrentStateIsNoneWhenCallingzesDeviceEccConfigurableAndAvailableThenNotSupportedEccIsReturned) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
pMockFwInterface->mockCurrentState = eccStateNone;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccAvailable(device, &eccAvailable));
EXPECT_EQ(false, eccAvailable);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccConfigurable(device, &eccConfigurable));
EXPECT_EQ(false, eccConfigurable);
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndPendingStateIsNoneWhenCallingzesDeviceEccConfigurableAndAvailableThenNotSupportedEccIsReturned) {
ze_bool_t eccConfigurable = true;
ze_bool_t eccAvailable = true;
pMockFwInterface->mockPendingState = eccStateNone;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccAvailable(device, &eccAvailable));
EXPECT_EQ(false, eccAvailable);
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccConfigurable(device, &eccConfigurable));
EXPECT_EQ(false, eccConfigurable);
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceGetEccStateThenApiCallSucceeds) {
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZES_DEVICE_ECC_STATE_DISABLED, props.currentState);
EXPECT_EQ(ZES_DEVICE_ECC_STATE_DISABLED, props.pendingState);
EXPECT_EQ(ZES_DEVICE_ACTION_NONE, props.pendingAction);
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwGetEccConfigFailsWhenCallingzesDeviceGetEccStateThenApiCallReturnFailure) {
zes_device_ecc_properties_t props = {};
pMockFwInterface->mockFwGetEccConfigResult = ZE_RESULT_ERROR_UNINITIALIZED;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceGetEccState(device, &props));
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceSetEccStateThenApiCallSucceeds) {
zes_device_ecc_desc_t newState = {ZES_STRUCTURE_TYPE_DEVICE_STATE, nullptr, ZES_DEVICE_ECC_STATE_ENABLED};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
newState.state = ZES_DEVICE_ECC_STATE_DISABLED;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceSetEccStateWithInvalidEnumThenFailureIsReturned) {
zes_device_ecc_desc_t newState = {ZES_STRUCTURE_TYPE_DEVICE_STATE, nullptr, ZES_DEVICE_ECC_STATE_UNAVAILABLE};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ENUMERATION, zesDeviceSetEccState(device, &newState, &props));
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwSetEccConfigFailsWhenCallingzesDeviceSetEccStateThenFailureIsReturned) {
zes_device_ecc_desc_t newState = {ZES_STRUCTURE_TYPE_DEVICE_STATE, nullptr, ZES_DEVICE_ECC_STATE_ENABLED};
zes_device_ecc_properties_t props = {};
pMockFwInterface->mockFwSetEccConfigResult = ZE_RESULT_ERROR_UNINITIALIZED;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceSetEccState(device, &newState, &props));
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleWhenCallingEccSetStateAndEccGetStateThenVerifyApiCallSuccedsAndValidStatesAreReturned) {
zes_device_ecc_desc_t newState = {ZES_STRUCTURE_TYPE_DEVICE_STATE, nullptr, ZES_DEVICE_ECC_STATE_ENABLED};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZES_DEVICE_ECC_STATE_ENABLED, props.pendingState);
newState.state = ZES_DEVICE_ECC_STATE_DISABLED;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZES_DEVICE_ECC_STATE_DISABLED, props.pendingState);
pMockFwInterface->mockSetConfig = false;
pMockFwInterface->mockCurrentState = eccStateNone;
pMockFwInterface->mockPendingState = eccStateNone;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZES_DEVICE_ECC_STATE_UNAVAILABLE, props.pendingState);
EXPECT_EQ(ZES_DEVICE_ECC_STATE_UNAVAILABLE, props.currentState);
}
TEST_F(ZesEccFixture, GivenValidSysmanHandleWhenCallingEccSetStateAndEccGetStateThenVerifyApiCallSuccedsAndValidActionIsReturned) {
zes_device_ecc_desc_t newState = {ZES_STRUCTURE_TYPE_DEVICE_STATE, nullptr, ZES_DEVICE_ECC_STATE_ENABLED};
zes_device_ecc_properties_t props = {};
pMockFwInterface->mockCurrentState = eccStateEnable;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZES_DEVICE_ECC_STATE_ENABLED, props.pendingState);
EXPECT_EQ(ZES_DEVICE_ACTION_NONE, props.pendingAction);
newState.state = ZES_DEVICE_ECC_STATE_DISABLED;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceGetEccState(device, &props));
EXPECT_EQ(ZES_DEVICE_ECC_STATE_DISABLED, props.pendingState);
EXPECT_EQ(ZES_DEVICE_ACTION_WARM_CARD_RESET, props.pendingAction);
}
} // namespace ult
} // namespace L0