refactor: cleanup around IGC library name mocking logic

This patchset improves mocking of IGC library name and adds
safety mechanism to ensure that global IGC library name gets
restored before test finishes.

Related-To: NEO-12747

Signed-off-by: Chodor, Jaroslaw <jaroslaw.chodor@intel.com>
This commit is contained in:
Chodor, Jaroslaw
2024-10-23 19:55:38 +00:00
committed by Compute-Runtime-Automation
parent 428e2132b0
commit 22fe217567
11 changed files with 72 additions and 61 deletions

View File

@@ -65,6 +65,7 @@ set(NEO_CORE_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_graphics_allocation.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_host_ptr_manager.h
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mock_igc_path.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_core_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_kmd_notify_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_product_helper.cpp

View File

@@ -70,9 +70,8 @@ void MockCompilerEnableGuard::Enable() {
if (enabled == false) {
// load mock from self (don't load dynamic libraries)
this->oldFclDllName = Os::frontEndDllName;
this->oldIgcDllName = Os::igcDllName;
Os::frontEndDllName = "";
Os::igcDllName = "";
igcNameGuard = pushIgcDllName("");
MockCIFMain::setGlobalCreatorFunc<NEO::MockIgcOclDeviceCtx>(NEO::MockIgcOclDeviceCtx::Create);
MockCIFMain::setGlobalCreatorFunc<NEO::MockFclOclDeviceCtx>(NEO::MockFclOclDeviceCtx::Create);
if (fclDebugVars == nullptr) {
@@ -89,7 +88,7 @@ void MockCompilerEnableGuard::Enable() {
void MockCompilerEnableGuard::Disable() {
if (enabled) {
Os::frontEndDllName = this->oldFclDllName;
Os::igcDllName = this->oldIgcDllName;
igcNameGuard.reset();
MockCIFMain::removeGlobalCreatorFunc<NEO::MockIgcOclDeviceCtx>();
MockCIFMain::removeGlobalCreatorFunc<NEO::MockFclOclDeviceCtx>();

View File

@@ -19,6 +19,11 @@
namespace NEO {
struct PopIgcDllNameGuard {
~PopIgcDllNameGuard();
};
[[nodiscard]] std::unique_ptr<PopIgcDllNameGuard> pushIgcDllName(const char *name);
struct MockCompilerDebugVars {
enum class SipAddressingType {
unknown,
@@ -61,9 +66,9 @@ struct MockCompilerEnableGuard {
void Disable(); // NOLINT(readability-identifier-naming)
const char *oldFclDllName;
const char *oldIgcDllName;
bool enabled = false;
std::unique_ptr<PopIgcDllNameGuard> igcNameGuard;
};
void setFclDebugVars(MockCompilerDebugVars &dbgv);

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/utilities/stackvec.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include <memory>
namespace Os {
extern const char *igcDllName;
} // namespace Os
namespace NEO {
StackVec<const char *, 32> prevIgcDllName;
bool popIgcDllName() {
if (prevIgcDllName.empty()) {
return false;
}
Os::igcDllName = *prevIgcDllName.rbegin();
prevIgcDllName.pop_back();
return true;
}
PopIgcDllNameGuard::~PopIgcDllNameGuard() {
popIgcDllName();
}
[[nodiscard]] std::unique_ptr<PopIgcDllNameGuard> pushIgcDllName(const char *name) {
prevIgcDllName.push_back(Os::igcDllName);
Os::igcDllName = name;
return std::make_unique<PopIgcDllNameGuard>();
}
} // namespace NEO