mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
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:
committed by
Compute-Runtime-Automation
parent
428e2132b0
commit
22fe217567
@@ -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
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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);
|
||||
|
||||
41
shared/test/common/mocks/mock_igc_path.cpp
Normal file
41
shared/test/common/mocks/mock_igc_path.cpp
Normal 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
|
||||
Reference in New Issue
Block a user