Improve GtPin init error status reporting

Related-To: LOCI-1286

Signed-off-by: davidoli <david.olien@intel.com>
This commit is contained in:
davidoli
2022-07-26 01:38:44 +00:00
committed by Compute-Runtime-Automation
parent a931f1654e
commit d7c43d022a
8 changed files with 110 additions and 14 deletions

View File

@ -48,7 +48,6 @@ class OaMetricSourceImp : public MetricSource {
uint32_t getSubDeviceIndex();
bool isImplicitScalingCapable() const;
const MetricDeviceContext &getMetricDeviceContext() const { return metricDeviceContext; }
static bool checkDependencies();
static std::unique_ptr<OaMetricSourceImp> create(const MetricDeviceContext &metricDeviceContext);
using OsLibraryLoadPtr = std::add_pointer<NEO::OsLibrary *(const std::string &)>::type;
static OsLibraryLoadPtr osLibraryLoadFunction;

View File

@ -18,27 +18,28 @@ const std::string gtPinOpenFunctionName = "OpenGTPin";
namespace L0 {
ze_result_t PinContext::init() {
std::unique_ptr<NEO::OsLibrary> hGtPinLibrary = nullptr;
PinContext::OsLibraryLoadPtr PinContext::osLibraryLoadFunction(NEO::OsLibrary::load);
hGtPinLibrary.reset(NEO::OsLibrary::load(gtPinLibraryFilename.c_str()));
if (hGtPinLibrary.get() == nullptr) {
ze_result_t PinContext::init() {
NEO::OsLibrary *hGtPinLibrary = nullptr;
hGtPinLibrary = PinContext::osLibraryLoadFunction(gtPinLibraryFilename.c_str());
if (hGtPinLibrary == nullptr) {
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library %s\n", gtPinLibraryFilename.c_str());
return ZE_RESULT_ERROR_UNKNOWN;
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
OpenGTPin_fn openGTPin = reinterpret_cast<OpenGTPin_fn>(hGtPinLibrary->getProcAddress(gtPinOpenFunctionName.c_str()));
if (openGTPin == nullptr) {
hGtPinLibrary.reset(nullptr);
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library open function symbol %s\n", gtPinOpenFunctionName.c_str());
return ZE_RESULT_ERROR_UNKNOWN;
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
uint32_t openResult = openGTPin(nullptr);
if (openResult != 0) {
hGtPinLibrary.reset(nullptr);
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "gtpin library open %s failed with status %u\n", gtPinOpenFunctionName.c_str(), openResult);
return ZE_RESULT_ERROR_UNKNOWN;
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
return ZE_RESULT_SUCCESS;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -16,6 +16,8 @@ namespace L0 {
class PinContext {
public:
static ze_result_t init();
using OsLibraryLoadPtr = std::add_pointer<NEO::OsLibrary *(const std::string &)>::type;
static OsLibraryLoadPtr osLibraryLoadFunction;
private:
static const std::string gtPinLibraryFilename;

View File

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

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/mocks/mock_os_library.h"
#include "level_zero/tools/source/pin/pin.h"
#include "gtest/gtest.h"
namespace ult {
TEST(PinInitializationTest, GivenValidLibraryPinContextInitSucceeds) {
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 0; };
auto newPtr = new MockOsLibrary(reinterpret_cast<void *>(openPinHandler), false);
MockOsLibrary::loadLibraryNewObject = newPtr;
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_SUCCESS);
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
MockOsLibrary::loadLibraryNewObject = nullptr;
delete newPtr;
}
TEST(PinInitializationTest, GivenBadLibraryNamePinContextInitFAILS) {
MockOsLibrary::loadLibraryNewObject = nullptr;
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
MockOsLibrary::loadLibraryNewObject = nullptr;
}
TEST(PinInitializationTest, GivenBadProcAddressPinContextInitFAILS) {
auto newPtr = new MockOsLibrary(nullptr, false);
MockOsLibrary::loadLibraryNewObject = newPtr;
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
MockOsLibrary::loadLibraryNewObject = nullptr;
delete newPtr;
}
TEST(PinInitializationTest, GivenBadPinHandlerPinContextInitFAILS) {
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 1; };
auto newPtr = new MockOsLibrary(reinterpret_cast<void *>(openPinHandler), false);
MockOsLibrary::loadLibraryNewObject = newPtr;
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
MockOsLibrary::loadLibraryNewObject = nullptr;
delete newPtr;
}
} // namespace ult