sysman:add support for Diagnostis API.

Signed-off-by: Vilvaraj, T J Vivek <t.j.vivek.vilvaraj@intel.com>
This commit is contained in:
Vilvaraj, T J Vivek
2021-04-21 04:12:31 +00:00
committed by Compute-Runtime-Automation
parent 6f555d6258
commit 24a745f4bd
24 changed files with 286 additions and 79 deletions

View File

@@ -88,9 +88,8 @@ if(BUILD_WITH_L0)
# Firmware Update Library
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/source/sysman/linux/firmware_util${BRANCH_DIR_SUFFIX}")
find_package(libigsc)
if(libigsc_LIBRARIES)
set(libigsc_FOUND TRUE)
add_definitions(-DIGSC_PRESENT=$(libigsc_FOUND))
if(libigsc_FOUND)
add_definitions(-DIGSC_PRESENT=1)
message(STATUS "libigsc Library headers directory: ${libigsc_INCLUDE_DIR}")
message(STATUS "libigsc version: ${libigsc_VERSION}")
else()

View File

@@ -700,7 +700,7 @@ zesDiagnosticsGetTests(
zes_diag_handle_t hDiagnostics,
uint32_t *pCount,
zes_diag_test_t *pTests) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsGetTests(pCount, pTests);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -709,7 +709,7 @@ zesDiagnosticsRunTests(
uint32_t start,
uint32_t end,
zes_diag_result_t *pResult) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
return L0::Diagnostics::fromHandle(hDiagnostics)->diagnosticsRunTests(start, end, pResult);
}
ZE_APIEXPORT ze_result_t ZE_APICALL

View File

@@ -18,17 +18,17 @@ DiagnosticsHandleContext::~DiagnosticsHandleContext() {
handleList.clear();
}
void DiagnosticsHandleContext::createHandle() {
Diagnostics *pDiagnostics = new DiagnosticsImp(pOsSysman);
if (pDiagnostics->isDiagnosticsEnabled == true) {
handleList.push_back(pDiagnostics);
} else {
delete pDiagnostics;
}
void DiagnosticsHandleContext::createHandle(const std::string &diagTests) {
Diagnostics *pDiagnostics = new DiagnosticsImp(pOsSysman, diagTests);
handleList.push_back(pDiagnostics);
}
void DiagnosticsHandleContext::init() {
createHandle();
OsDiagnostics::getSupportedDiagTests(supportedDiagTests, pOsSysman);
for (const std::string &diagTests : supportedDiagTests) {
createHandle(diagTests);
}
}
ze_result_t DiagnosticsHandleContext::diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) {

View File

@@ -23,12 +23,13 @@ class Diagnostics : _zes_diag_handle_t {
public:
virtual ~Diagnostics() {}
virtual ze_result_t diagnosticsGetProperties(zes_diag_properties_t *pProperties) = 0;
virtual ze_result_t diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) = 0;
virtual ze_result_t diagnosticsRunTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) = 0;
inline zes_diag_handle_t toHandle() { return this; }
static Diagnostics *fromHandle(zes_diag_handle_t handle) {
return static_cast<Diagnostics *>(handle);
}
bool isDiagnosticsEnabled = false;
};
struct DiagnosticsHandleContext {
@@ -38,12 +39,12 @@ struct DiagnosticsHandleContext {
void init();
ze_result_t diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics);
std::vector<std::string> supportedDiagTests = {};
OsSysman *pOsSysman = nullptr;
std::vector<Diagnostics *> handleList = {};
private:
void createHandle();
void createHandle(const std::string &DiagTests);
};
} // namespace L0

View File

@@ -20,14 +20,17 @@ ze_result_t DiagnosticsImp::diagnosticsGetProperties(zes_diag_properties_t *pPro
return ZE_RESULT_SUCCESS;
}
void DiagnosticsImp::init() {
this->isDiagnosticsEnabled = pOsDiagnostics->isDiagnosticsSupported();
ze_result_t DiagnosticsImp::diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) {
return pOsDiagnostics->osGetDiagTests(pCount, pTests);
}
DiagnosticsImp::DiagnosticsImp(OsSysman *pOsSysman) {
pOsDiagnostics = OsDiagnostics::create(pOsSysman);
ze_result_t DiagnosticsImp::diagnosticsRunTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) {
return pOsDiagnostics->osRunDiagTests(start, end, pResult);
}
DiagnosticsImp::DiagnosticsImp(OsSysman *pOsSysman, const std::string &initalizedDiagTest) {
pOsDiagnostics = OsDiagnostics::create(pOsSysman, initalizedDiagTest);
UNRECOVERABLE_IF(nullptr == pOsDiagnostics);
init();
}
DiagnosticsImp::~DiagnosticsImp() {

View File

@@ -20,12 +20,12 @@ class OsDiagnostics;
class DiagnosticsImp : public Diagnostics, NEO::NonCopyableOrMovableClass {
public:
ze_result_t diagnosticsGetProperties(zes_diag_properties_t *pProperties) override;
ze_result_t diagnosticsGetTests(uint32_t *pCount, zes_diag_test_t *pTests) override;
ze_result_t diagnosticsRunTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override;
DiagnosticsImp() = default;
DiagnosticsImp(OsSysman *pOsSysman);
DiagnosticsImp(OsSysman *pOsSysman, const std::string &initalizedDiagTest);
~DiagnosticsImp() override;
std::unique_ptr<OsDiagnostics> pOsDiagnostics = nullptr;
void init();
};
} // namespace L0

View File

@@ -8,6 +8,7 @@ set(L0_SRCS_TOOLS_SYSMAN_DIAGNOSTICS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/os_diagnostics_imp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_diagnostics_imp.h
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/os_diagnostics_helper.cpp
)
if(UNIX)

View File

@@ -0,0 +1,20 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/string.h"
#include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h"
namespace L0 {
void OsDiagnostics::getSupportedDiagTestsFromFW(void *pFwInterface, std::vector<std::string> &supportedDiagTests) {
}
ze_result_t LinuxDiagnosticsImp::osRunDiagTestsinFW(zes_diag_result_t *pResult) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
} // namespace L0

View File

@@ -11,25 +11,37 @@
namespace L0 {
bool LinuxDiagnosticsImp::isDiagnosticsSupported(void) {
void OsDiagnostics::getSupportedDiagTests(std::vector<std::string> &supportedDiagTests, OsSysman *pOsSysman) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
if (pFwInterface != nullptr) {
isFWInitalized = ((ZE_RESULT_SUCCESS == pFwInterface->fwDeviceInit()) ? true : false);
return this->isFWInitalized;
getSupportedDiagTestsFromFW(pFwInterface, supportedDiagTests);
}
return false;
}
void LinuxDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties) {
pProperties->onSubdevice = false;
pProperties->haveTests = 0; // osGetDiagTests is Unsupported
strncpy_s(pProperties->name, ZES_STRING_PROPERTY_SIZE, osDiagType.c_str(), osDiagType.size());
return;
}
LinuxDiagnosticsImp::LinuxDiagnosticsImp(OsSysman *pOsSysman) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
ze_result_t LinuxDiagnosticsImp::osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman) {
std::unique_ptr<LinuxDiagnosticsImp> pLinuxDiagnosticsImp = std::make_unique<LinuxDiagnosticsImp>(pOsSysman);
ze_result_t LinuxDiagnosticsImp::osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) {
return osRunDiagTestsinFW(pResult);
}
LinuxDiagnosticsImp::LinuxDiagnosticsImp(OsSysman *pOsSysman, const std::string &diagTests) : osDiagType(diagTests) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<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;
}

View File

@@ -16,15 +16,21 @@ namespace L0 {
class LinuxDiagnosticsImp : public OsDiagnostics, NEO::NonCopyableOrMovableClass {
public:
bool isDiagnosticsSupported(void) override;
void osGetDiagProperties(zes_diag_properties_t *pProperties) override;
ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) override;
ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override;
ze_result_t osRunDiagTestsinFW(zes_diag_result_t *pResult);
LinuxDiagnosticsImp() = default;
LinuxDiagnosticsImp(OsSysman *pOsSysman);
LinuxDiagnosticsImp(OsSysman *pOsSysman, const std::string &diagTests);
~LinuxDiagnosticsImp() override = default;
std::string osDiagType = "unknown";
protected:
FirmwareUtil *pFwInterface = nullptr;
bool isFWInitalized = false;
SysfsAccess *pSysfsAccess = nullptr;
private:
static const std::string quiescentGpuFile;
};
} // namespace L0

View File

@@ -18,9 +18,12 @@ namespace L0 {
class OsDiagnostics {
public:
virtual bool isDiagnosticsSupported(void) = 0;
virtual void osGetDiagProperties(zes_diag_properties_t *pProperties) = 0;
static std::unique_ptr<OsDiagnostics> create(OsSysman *pOsSysman);
virtual ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) = 0;
virtual ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) = 0;
static std::unique_ptr<OsDiagnostics> create(OsSysman *pOsSysman, const std::string &DiagTests);
static void getSupportedDiagTestsFromFW(void *pFwInterface, std::vector<std::string> &supportedDiagTests);
static void getSupportedDiagTests(std::vector<std::string> &supportedDiagTests, OsSysman *pOsSysman);
virtual ~OsDiagnostics() {}
};

View File

@@ -9,15 +9,24 @@
namespace L0 {
bool WddmDiagnosticsImp::isDiagnosticsSupported(void) {
return false;
}
void WddmDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties){};
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman) {
ze_result_t WddmDiagnosticsImp::osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t WddmDiagnosticsImp::osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman, const std::string &diagTests) {
std::unique_ptr<WddmDiagnosticsImp> pWddmDiagnosticsImp = std::make_unique<WddmDiagnosticsImp>();
return pWddmDiagnosticsImp;
}
void OsDiagnostics::getSupportedDiagTests(std::vector<std::string> &supportedDiagTests, OsSysman *pOsSysman) {
}
void OsDiagnostics::getSupportedDiagTestsFromFW(void *pFwInterface, std::vector<std::string> &supportedDiagTests) {
}
} // namespace L0

View File

@@ -14,8 +14,9 @@
namespace L0 {
class WddmDiagnosticsImp : public OsDiagnostics {
public:
bool isDiagnosticsSupported(void) override;
void osGetDiagProperties(zes_diag_properties_t *pProperties) override;
ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) override;
ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override;
};
} // namespace L0

View File

@@ -10,14 +10,16 @@ if(libigsc_FOUND)
${CMAKE_CURRENT_SOURCE_DIR}/firmware_util_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/firmware_util.h
)
if($(libigsc_VERSION) GREATER "2")
set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_HELPER
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/firmware_util_imp_helper.cpp
)
else()
if(libigsc_VERSION VERSION_LESS 0.3)
message(STATUS "default libigsc version: ${libigsc_VERSION}")
set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_HELPER
${CMAKE_CURRENT_SOURCE_DIR}/firmware_util_imp_helper.cpp
)
else()
message(STATUS "LIBIGSC version: ${libigsc_VERSION}")
set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL_HELPER
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/firmware_util_imp_helper.cpp
)
endif()
else()
set(L0_SRCS_TOOLS_SYSMAN_LINUX_FIRMWARE_UTIL

View File

@@ -31,6 +31,8 @@ class FirmwareUtil {
virtual ze_result_t fwFlashGSC(void *pImage, uint32_t size) = 0;
virtual ze_result_t fwFlashOprom(void *pImage, uint32_t size) = 0;
virtual ze_result_t fwIfrApplied(bool &ifrStatus) = 0;
virtual ze_result_t fwSupportedDiagTests(std::vector<std::string> &supportedDiagTests) = 0;
virtual ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) = 0;
virtual ~FirmwareUtil() = default;
};
} // namespace L0

View File

@@ -187,7 +187,6 @@ FirmwareUtil *FirmwareUtil::create() {
delete pFwUtilImp;
return nullptr;
}
return static_cast<FirmwareUtil *>(pFwUtilImp);
}
} // namespace L0

View File

@@ -68,6 +68,8 @@ class FirmwareUtilImp : public FirmwareUtil, NEO::NonCopyableOrMovableClass {
ze_result_t fwFlashGSC(void *pImage, uint32_t size) override;
ze_result_t fwFlashOprom(void *pImage, uint32_t size) override;
ze_result_t fwIfrApplied(bool &ifrStatus) override;
ze_result_t fwSupportedDiagTests(std::vector<std::string> &supportedDiagTests) override;
ze_result_t fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) override;
template <class T>
bool getSymbolAddr(const std::string name, T &proc);

View File

@@ -14,4 +14,12 @@ namespace L0 {
ze_result_t FirmwareUtilImp::fwIfrApplied(bool &ifrStatus) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t FirmwareUtilImp::fwSupportedDiagTests(std::vector<std::string> &supportedDiagTests) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t FirmwareUtilImp::fwRunDiagTests(std::string &osDiagType, zes_diag_result_t *pDiagResult) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
} // namespace L0

View File

@@ -96,6 +96,7 @@ void usage() {
"\n -r, --reset force|noforce selectively run device reset test"
"\n -i, --firmware <image> selectively run device firmware test <image> is the firmware binary needed to flash"
"\n -F, --fabricport selectively run fabricport black box test"
"\n -d, --diagnostics selectively run diagnostics black box test"
"\n -h, --help display help message"
"\n"
"\n All L0 Syman APIs that set values require root privileged execution"
@@ -930,6 +931,66 @@ void testSysmanGlobalOperations(ze_device_handle_t &device) {
}
}
}
void testSysmanDiagnostics(ze_device_handle_t &device) {
std::cout << std::endl
<< " ---- diagnostics tests ---- " << std::endl;
uint32_t count = 0;
uint32_t subTestCount = 0;
zes_diag_test_t tests = {};
zes_diag_result_t results;
uint32_t start = 0, end = 0;
VALIDATECALL(zesDeviceEnumDiagnosticTestSuites(device, &count, nullptr));
if (count == 0) {
std::cout << "Could not retrieve diagnostics domains" << std::endl;
return;
}
std::vector<zes_diag_handle_t> handles(count, nullptr);
VALIDATECALL(zesDeviceEnumDiagnosticTestSuites(device, &count, handles.data()));
for (auto handle : handles) {
zes_diag_properties_t diagProperties = {};
VALIDATECALL(zesDiagnosticsGetProperties(handle, &diagProperties));
if (verbose) {
std::cout << "diagnostics name = " << diagProperties.name << std::endl;
std::cout << "On Subdevice = " << diagProperties.onSubdevice << std::endl;
std::cout << "Subdevice Id = " << diagProperties.subdeviceId << std::endl;
std::cout << "diagnostics have sub tests = " << diagProperties.haveTests << std::endl;
}
if (diagProperties.haveTests != 0) {
VALIDATECALL(zesDiagnosticsGetTests(handle, &subTestCount, &tests));
if (verbose) {
std::cout << "diagnostics subTestCount = " << subTestCount << "for " << diagProperties.name << std::endl;
for (uint32_t i = 0; i < subTestCount; i++) {
std::cout << "subTest#" << tests.index << " = " << tests.name << std::endl;
}
}
end = subTestCount - 1;
}
VALIDATECALL(zesDiagnosticsRunTests(handle, start, end, &results));
if (verbose) {
switch (results) {
case ZES_DIAG_RESULT_NO_ERRORS:
std::cout << "No errors have occurred" << std::endl;
break;
case ZES_DIAG_RESULT_REBOOT_FOR_REPAIR:
std::cout << "diagnostics successful and repair applied, reboot needed" << std::endl;
break;
case ZES_DIAG_RESULT_FAIL_CANT_REPAIR:
std::cout << "diagnostics run, unable to fix" << std::endl;
break;
case ZES_DIAG_RESULT_ABORT:
std::cout << "diagnostics run fialed, unknown error" << std::endl;
break;
case ZES_DIAG_RESULT_FORCE_UINT32:
default:
std::cout << "undefined error" << std::endl;
}
}
}
}
bool validateGetenv(const char *name) {
const char *env = getenv(name);
if ((nullptr == env) || (0 == strcmp("0", env)))
@@ -963,10 +1024,11 @@ int main(int argc, char *argv[]) {
{"reset", required_argument, nullptr, 'r'},
{"fabricport", no_argument, nullptr, 'F'},
{"firmware", optional_argument, nullptr, 'i'},
{"diagnostics", no_argument, nullptr, 'd'},
{0, 0, 0, 0},
};
bool force = false;
while ((opt = getopt_long(argc, argv, "hpfsectogmrFEi:", long_opts, nullptr)) != -1) {
while ((opt = getopt_long(argc, argv, "hdpfsectogmrFEi:", long_opts, nullptr)) != -1) {
switch (opt) {
case 'h':
usage();
@@ -1062,7 +1124,11 @@ int main(int argc, char *argv[]) {
testSysmanFabricPort(device);
});
break;
case 'd':
std::for_each(devices.begin(), devices.end(), [&](auto device) {
testSysmanDiagnostics(device);
});
break;
default:
usage();
exit(0);

View File

@@ -9,6 +9,6 @@ if(UNIX)
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/mock_zes_sysman_diagnostics.h
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_sysman_diagnostics.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/test_zes_sysman_diagnostics.cpp
)
endif()

View File

@@ -13,7 +13,9 @@
namespace L0 {
namespace ult {
constexpr uint32_t mockDiagHandleCount = 1;
constexpr uint32_t mockDiagHandleCount = 2;
const std::string mockQuiescentGpuFile("quiesce_gpu");
const std::vector<std::string> mockSupportedDiagTypes = {"MOCKSUITE1", "MOCKSUITE2"};
class DiagnosticsInterface : public FirmwareUtil {};
template <>
@@ -25,20 +27,17 @@ struct Mock<DiagnosticsInterface> : public FirmwareUtil {
ze_result_t mockFwDeviceInitFail(void) {
return ZE_RESULT_ERROR_UNKNOWN;
}
ze_result_t mockFwGetVersion(std::string &fwVersion) {
return ZE_RESULT_SUCCESS;
}
ze_result_t mockOpromGetVersion(std::string &fwVersion) {
return ZE_RESULT_SUCCESS;
}
ze_result_t mockGetFirstDevice(igsc_device_info *info) {
return ZE_RESULT_SUCCESS;
}
ze_result_t mockFwFlash(void *pImage, uint32_t size) {
ze_result_t mockFwSupportedDiagTests(std::vector<std::string> &supportedDiagTests) {
supportedDiagTests.push_back(mockSupportedDiagTypes[0]);
supportedDiagTests.push_back(mockSupportedDiagTypes[1]);
return ZE_RESULT_SUCCESS;
}
ze_result_t mockFwGetVersionFailed(std::string &fwVersion) {
return ZE_RESULT_ERROR_UNINITIALIZED;
ze_result_t mockFwRunDiagTestsReturnSuccess(std::string &osDiagType, zes_diag_result_t *pResult) {
*pResult = ZES_DIAG_RESULT_NO_ERRORS;
return ZE_RESULT_SUCCESS;
}
Mock<DiagnosticsInterface>() = default;
@@ -50,6 +49,28 @@ struct Mock<DiagnosticsInterface> : public FirmwareUtil {
MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override));
MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override));
MOCK_METHOD(ze_result_t, fwIfrApplied, (bool &ifrStatus), (override));
MOCK_METHOD(ze_result_t, fwSupportedDiagTests, (std::vector<std::string> & supportedDiagTests), (override));
MOCK_METHOD(ze_result_t, fwRunDiagTests, (std::string & osDiagType, zes_diag_result_t *pResult), (override));
};
class DiagSysfsAccess : public SysfsAccess {};
template <>
struct Mock<DiagSysfsAccess> : public DiagSysfsAccess {
ze_result_t mockwrite(const std::string file, const int val) {
if (std::string::npos != file.find(mockQuiescentGpuFile)) {
return ZE_RESULT_SUCCESS;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
}
ze_result_t mockwriteFails(const std::string file, const int val) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
Mock<DiagSysfsAccess>() = default;
MOCK_METHOD(ze_result_t, write, (const std::string file, const int val), (override));
};
class PublicLinuxDiagnosticsImp : public L0::LinuxDiagnosticsImp {

View File

@@ -26,16 +26,10 @@ class ZesDiagnosticsFixture : public SysmanDeviceFixture {
pLinuxSysmanImp->pFwUtilInterface = pMockDiagInterface.get();
ON_CALL(*pMockDiagInterface.get(), fwDeviceInit())
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwDeviceInit));
ON_CALL(*pMockDiagInterface.get(), fwGetVersion(_))
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwGetVersion));
ON_CALL(*pMockDiagInterface.get(), opromGetVersion(_))
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockOpromGetVersion));
ON_CALL(*pMockDiagInterface.get(), getFirstDevice(_))
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockGetFirstDevice));
ON_CALL(*pMockDiagInterface.get(), fwFlashGSC(_, _))
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwFlash));
ON_CALL(*pMockDiagInterface.get(), fwFlashOprom(_, _))
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwFlash));
ON_CALL(*pMockDiagInterface.get(), fwSupportedDiagTests(_))
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwSupportedDiagTests));
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
}
@@ -47,7 +41,7 @@ class ZesDiagnosticsFixture : public SysmanDeviceFixture {
pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
}
std::vector<zes_diag_handle_t> get_diagnostics_handles(uint32_t count) {
std::vector<zes_diag_handle_t> get_diagnostics_handles(uint32_t &count) {
std::vector<zes_diag_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
return handles;
@@ -61,7 +55,7 @@ TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDia
ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
EXPECT_EQ(count, 0u);
uint32_t testCount = count + 1;
@@ -74,14 +68,14 @@ TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDia
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, diagnosticsHandle.data());
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
EXPECT_EQ(count, 0u);
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman);
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp);
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
EXPECT_EQ(count, 1u);
testCount = count;
@@ -90,7 +84,7 @@ TEST_F(ZesDiagnosticsFixture, GivenComponentCountZeroWhenCallingzesDeviceEnumDia
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_NE(nullptr, diagnosticsHandle.data());
EXPECT_EQ(testCount, mockDiagHandleCount);
EXPECT_EQ(testCount, 1u);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
delete ptestDiagnosticsImp;
@@ -109,6 +103,20 @@ TEST_F(ZesDiagnosticsFixture, GivenFailedFirmwareInitializationWhenInitializingD
EXPECT_EQ(0u, pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.size());
}
TEST_F(ZesDiagnosticsFixture, GivenSupportedTestsWhenInitializingDiagnosticsContextThenexpectHandles) {
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
pSysmanDeviceImp->pDiagnosticsHandleContext->supportedDiagTests.push_back(mockSupportedDiagTypes[0]);
ON_CALL(*pMockDiagInterface.get(), fwDeviceInit())
.WillByDefault(::testing::Invoke(pMockDiagInterface.get(), &Mock<DiagnosticsInterface>::mockFwDeviceInitFail));
pSysmanDeviceImp->pDiagnosticsHandleContext->init();
EXPECT_EQ(1u, pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.size());
}
TEST_F(ZesDiagnosticsFixture, GivenFirmwareInitializationFailureThenCreateHandleMustFail) {
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
@@ -121,10 +129,50 @@ TEST_F(ZesDiagnosticsFixture, GivenFirmwareInitializationFailureThenCreateHandle
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsPropertiesThenCallSucceeds) {
auto handles = get_diagnostics_handles(mockDiagHandleCount);
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp);
auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle();
zes_diag_properties_t properties = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDiagnosticsGetProperties(handles[0], &properties));
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDiagnosticsGetProperties(handle, &properties));
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGettingDiagnosticsTestThenCallSucceeds) {
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp);
auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle();
zes_diag_test_t tests = {};
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDiagnosticsGetTests(handle, &count, &tests));
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
delete ptestDiagnosticsImp;
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenRunningDiagnosticsTestThenCallSucceeds) {
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp);
auto handle = pSysmanDeviceImp->pDiagnosticsHandleContext->handleList[0]->toHandle();
zes_diag_result_t results = ZES_DIAG_RESULT_FORCE_UINT32;
uint32_t start = 0, end = 0;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDiagnosticsRunTests(handle, start, end, &results));
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.pop_back();
delete ptestDiagnosticsImp;
}
} // namespace ult
} // namespace L0

View File

@@ -71,6 +71,8 @@ struct Mock<FirmwareInterface> : public FirmwareUtil {
MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override));
MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override));
MOCK_METHOD(ze_result_t, fwIfrApplied, (bool &ifrStatus), (override));
MOCK_METHOD(ze_result_t, fwSupportedDiagTests, (std::vector<std::string> & supportedDiagTests), (override));
MOCK_METHOD(ze_result_t, fwRunDiagTests, (std::string & osDiagType, zes_diag_result_t *pResult), (override));
};
class PublicLinuxFirmwareImp : public L0::LinuxFirmwareImp {

View File

@@ -426,6 +426,8 @@ struct Mock<FirmwareInterface> : public FirmwareUtil {
MOCK_METHOD(ze_result_t, fwFlashGSC, (void *pImage, uint32_t size), (override));
MOCK_METHOD(ze_result_t, fwFlashOprom, (void *pImage, uint32_t size), (override));
MOCK_METHOD(ze_result_t, fwIfrApplied, (bool &ifrStatus), (override));
MOCK_METHOD(ze_result_t, fwSupportedDiagTests, (std::vector<std::string> & supportedDiagTests), (override));
MOCK_METHOD(ze_result_t, fwRunDiagTests, (std::string & osDiagType, zes_diag_result_t *pResult), (override));
};
class PublicLinuxGlobalOperationsImp : public L0::LinuxGlobalOperationsImp {