mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Enhanced unit tests for level zero
- add mocks - link test with driver library - add debugger test Related-To: NEO-4500 Change-Id: I33313553c3f10ab899fd13447d1091f223e79a87 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
49d54cf45d
commit
8978fcce3d
@@ -10,13 +10,16 @@ set(TARGET_NAME ${TARGET_NAME_L0}_core_tests)
|
||||
|
||||
append_sources_from_properties(L0_CORE_ENABLERS NEO_CORE_SRCS_LINK)
|
||||
|
||||
function(ADD_SUPPORTED_TEST_PRODUCT_FAMILIES_DEFINITION)
|
||||
set(L0_TESTED_PRODUCT_FAMILIES ${ALL_TESTED_PRODUCT_FAMILY})
|
||||
string(REPLACE ";" "," L0_TESTED_PRODUCT_FAMILIES "${L0_TESTED_PRODUCT_FAMILIES}")
|
||||
add_definitions(-DSUPPORTED_TEST_PRODUCT_FAMILIES=${L0_TESTED_PRODUCT_FAMILIES})
|
||||
endfunction()
|
||||
|
||||
ADD_SUPPORTED_TEST_PRODUCT_FAMILIES_DEFINITION()
|
||||
|
||||
add_executable(${TARGET_NAME}
|
||||
${NEO_SOURCE_DIR}/level_zero/core/source/dll/disallow_deferred_deleter.cpp
|
||||
${NEO_SOURCE_DIR}/level_zero/core/source/debug_manager.cpp
|
||||
${NEO_SOURCE_DIR}/level_zero/core/source/debugger.cpp
|
||||
${NEO_SOURCE_DIR}/level_zero/core/source/debugger/debugger_l0.cpp
|
||||
${NEO_SOURCE_DIR}/level_zero/core/source/compiler_interface/default_l0_cache_config.cpp
|
||||
${NEO_SOURCE_DIR}/level_zero/core/source/compiler_interface/default_cache_config.cpp
|
||||
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.h
|
||||
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.cpp
|
||||
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.h
|
||||
@@ -27,10 +30,13 @@ add_executable(${TARGET_NAME}
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/white_box.h
|
||||
)
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/libult/create_command_stream.cpp
|
||||
$<TARGET_OBJECTS:${L0_MOCKABLE_LIB_NAME}>
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
@@ -39,8 +45,7 @@ if (UNIX)
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/drm_neo_create.cpp
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/options.cpp
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp
|
||||
${COMPUTE_RUNTIME_DIR}/level_zero/core/source/linux/registry_path.cpp
|
||||
)
|
||||
)
|
||||
else()
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp
|
||||
@@ -49,18 +54,15 @@ else()
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp
|
||||
${COMPUTE_RUNTIME_DIR}/level_zero/core/source/windows/registry_path.cpp
|
||||
)
|
||||
)
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${ASAN_FLAGS})
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER ${TARGET_NAME_L0})
|
||||
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC
|
||||
DEFAULT_PRODUCT_FAMILY=${DEFAULT_PRODUCT_FAMILY}
|
||||
ZE_MAKEDLL
|
||||
)
|
||||
add_subdirectoriesL0(${CMAKE_CURRENT_SOURCE_DIR} "*")
|
||||
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:${L0_MOCKABLE_LIB_NAME},INTERFACE_COMPILE_DEFINITIONS>)
|
||||
|
||||
target_include_directories(${TARGET_NAME}
|
||||
BEFORE
|
||||
@@ -80,9 +82,6 @@ if (UNIX)
|
||||
$<TARGET_PROPERTY:${TARGET_NAME_L0},SOURCE_DIR>/tools/linux
|
||||
${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/linux
|
||||
)
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
pthread
|
||||
)
|
||||
else()
|
||||
target_include_directories(${TARGET_NAME}
|
||||
BEFORE
|
||||
@@ -94,20 +93,13 @@ else()
|
||||
endif()
|
||||
|
||||
if (UNIX)
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
rt
|
||||
)
|
||||
target_link_libraries(${TARGET_NAME} pthread rt)
|
||||
else()
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
dbghelp
|
||||
)
|
||||
target_link_libraries(${TARGET_NAME} dbghelp)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
${NEO_MOCKABLE_LIB_NAME}
|
||||
${NEO_SHARED_MOCKABLE_LIB_NAME}
|
||||
${NEO_MOCKABLE_LIB_NAME}
|
||||
${NEO_SHARED_MOCKABLE_LIB_NAME}
|
||||
${NEO_STATICALLY_LINKED_LIBRARIES_MOCKABLE}
|
||||
compute_runtime_mockable_extra
|
||||
${HW_LIBS_ULT}
|
||||
gmock-gtest
|
||||
@@ -117,7 +109,10 @@ if(SKIP_NEO_UNIT_TESTS)
|
||||
add_subdirectory(${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/mock_gmm ${CMAKE_BINARY_DIR}/mock_gmm)
|
||||
endif()
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE $<TARGET_OBJECTS:mock_gmm>)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
$<TARGET_OBJECTS:mock_gmm>
|
||||
$<TARGET_OBJECTS:${TARGET_NAME_L0}_mocks>
|
||||
)
|
||||
|
||||
option(L0_ULT_VERBOSE "Use the default/verbose test output" OFF)
|
||||
if(NOT L0_ULT_VERBOSE)
|
||||
@@ -153,6 +148,4 @@ if(NOT GTEST_SHUFFLE)
|
||||
endif()
|
||||
message(STATUS "GTest shuffle set to ${GTEST_SHUFFLE}")
|
||||
|
||||
add_subdirectoriesL0(${CMAKE_CURRENT_SOURCE_DIR} "*")
|
||||
|
||||
create_source_tree(${TARGET_NAME} ${L0_ROOT_DIR}/..)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "opencl/test/unit_test/mocks/mock_gmm_client_context.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_sip.h"
|
||||
|
||||
#include "level_zero/core/source/cmdlist.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "igfxfmid.h"
|
||||
|
||||
@@ -118,6 +120,11 @@ void applyWorkarounds() {
|
||||
});
|
||||
tempThreadID = t.get_id();
|
||||
t.join();
|
||||
|
||||
//Create FileLogger to prevent false memory leaks
|
||||
{
|
||||
NEO::FileLoggerInstance();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -168,9 +175,12 @@ int main(int argc, char **argv) {
|
||||
useDefaultListener = true;
|
||||
}
|
||||
}
|
||||
|
||||
productFamily = hwInfoForTests.platform.eProductFamily;
|
||||
renderCoreFamily = hwInfoForTests.platform.eRenderCoreFamily;
|
||||
// Platforms with uninitialized factory are not supported
|
||||
if (L0::commandListFactory[productFamily] == nullptr) {
|
||||
std::cout << "unsupported product family has been set: " << NEO::hardwarePrefix[::productFamily] << std::endl;
|
||||
std::cout << "skipping tests" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
|
||||
if (useDefaultListener == false) {
|
||||
@@ -191,17 +201,28 @@ int main(int argc, char **argv) {
|
||||
::testing::AddGlobalTestEnvironment(environment);
|
||||
}
|
||||
|
||||
auto hwInfoConfig = NEO::defaultHardwareInfoConfigTable[productFamily];
|
||||
NEO::setHwInfoValuesFromConfig(hwInfoConfig, hwInfoForTests);
|
||||
NEO::hardwareInfoSetup[productFamily](&hwInfoForTests, true, hwInfoConfig);
|
||||
NEO::HardwareInfo hwInfo = hwInfoForTests;
|
||||
uint64_t hwInfoConfig = NEO::defaultHardwareInfoConfigTable[productFamily];
|
||||
NEO::setHwInfoValuesFromConfig(hwInfoConfig, hwInfo);
|
||||
|
||||
// set Gt and FeatureTable to initial state
|
||||
NEO::hardwareInfoSetup[productFamily](&hwInfo, false, hwInfoConfig);
|
||||
|
||||
::productFamily = hwInfo.platform.eProductFamily;
|
||||
::renderCoreFamily = hwInfo.platform.eRenderCoreFamily;
|
||||
|
||||
NEO::platformDevices = new NEO::HardwareInfo *[1];
|
||||
NEO::platformDevices[0] = &hwInfo;
|
||||
NEO::defaultHwInfo = std::make_unique<NEO::HardwareInfo>();
|
||||
*NEO::defaultHwInfo = hwInfoForTests;
|
||||
*NEO::defaultHwInfo = hwInfo;
|
||||
|
||||
NEO::useKernelDescriptor = true;
|
||||
NEO::MockSipData::mockSipKernel.reset(new NEO::MockSipKernel());
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
auto retVal = RUN_ALL_TESTS();
|
||||
delete[] NEO::platformDevices;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
|
||||
18
level_zero/core/test/unit_tests/mock.h
Normal file
18
level_zero/core/test/unit_tests/mock.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <typename Type>
|
||||
struct Mock : public Type {};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
35
level_zero/core/test/unit_tests/mocks/CMakeLists.txt
Normal file
35
level_zero/core/test/unit_tests/mocks/CMakeLists.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(TARGET_NAME ${TARGET_NAME_L0}_mocks)
|
||||
|
||||
set(L0_MOCKS_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_built_ins.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_built_ins.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_cmdqueue.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_cmdqueue.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_device.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.cpp
|
||||
)
|
||||
|
||||
add_library(${TARGET_NAME} OBJECT ${L0_MOCKS_SOURCES})
|
||||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
$<TARGET_PROPERTY:gmock-gtest,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:${L0_MOCKABLE_LIB_NAME},INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:${NEO_SHARED_MOCKABLE_LIB_NAME},INTERFACE_INCLUDE_DIRECTORIES>
|
||||
${NEO_SOURCE_DIR}/level_zero/core/test/unit_test
|
||||
)
|
||||
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:${L0_MOCKABLE_LIB_NAME},INTERFACE_COMPILE_DEFINITIONS>)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER ${TARGET_NAME_L0})
|
||||
|
||||
create_source_tree(${TARGET_NAME} ${L0_ROOT_DIR})
|
||||
20
level_zero/core/test/unit_tests/mocks/mock_built_ins.cpp
Normal file
20
level_zero/core/test/unit_tests/mocks/mock_built_ins.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
|
||||
#include "opencl/source/helpers/built_ins_helper.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
const NEO::SipKernel &MockBuiltins::getSipKernel(NEO::SipKernelType type, NEO::Device &device) {
|
||||
return NEO::initSipKernel(type, device);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
19
level_zero/core/test/unit_tests/mocks/mock_built_ins.h
Normal file
19
level_zero/core/test/unit_tests/mocks/mock_built_ins.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/built_ins/built_ins.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
class MockBuiltins : public NEO::BuiltIns {
|
||||
public:
|
||||
const NEO::SipKernel &getSipKernel(NEO::SipKernelType type, NEO::Device &device) override;
|
||||
};
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
29
level_zero/core/test/unit_tests/mocks/mock_cmdqueue.cpp
Normal file
29
level_zero/core/test/unit_tests/mocks/mock_cmdqueue.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mock_cmdqueue.h"
|
||||
|
||||
#include "shared/source/device/device.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
WhiteBox<::L0::CommandQueue>::WhiteBox(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc)
|
||||
: ::L0::CommandQueueImp(device, csr, desc) {}
|
||||
|
||||
WhiteBox<::L0::CommandQueue>::~WhiteBox() {}
|
||||
|
||||
Mock<CommandQueue>::Mock(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc)
|
||||
: WhiteBox<::L0::CommandQueue>(device, csr, desc) {
|
||||
this->device = device;
|
||||
}
|
||||
|
||||
Mock<CommandQueue>::~Mock() {
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
73
level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h
Normal file
73
level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/core/source/cmdqueue_hw.h"
|
||||
#include "level_zero/core/source/cmdqueue_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
#endif
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <>
|
||||
struct WhiteBox<::L0::CommandQueue> : public ::L0::CommandQueueImp {
|
||||
using BaseClass = ::L0::CommandQueueImp;
|
||||
using BaseClass::buffers;
|
||||
using BaseClass::commandStream;
|
||||
using BaseClass::csr;
|
||||
using BaseClass::device;
|
||||
using BaseClass::printfFunctionContainer;
|
||||
using BaseClass::synchronizeByPollingForTaskCount;
|
||||
|
||||
WhiteBox(Device *device, NEO::CommandStreamReceiver *csr,
|
||||
const ze_command_queue_desc_t *desc);
|
||||
~WhiteBox() override;
|
||||
};
|
||||
|
||||
using CommandQueue = WhiteBox<::L0::CommandQueue>;
|
||||
static ze_command_queue_desc_t default_cmd_queue_desc = {};
|
||||
template <>
|
||||
struct Mock<CommandQueue> : public CommandQueue {
|
||||
Mock(L0::Device *device = nullptr, NEO::CommandStreamReceiver *csr = nullptr, const ze_command_queue_desc_t *desc = &default_cmd_queue_desc);
|
||||
~Mock() override;
|
||||
|
||||
MOCK_METHOD2(createFence, ze_result_t(const ze_fence_desc_t *desc, ze_fence_handle_t *phFence));
|
||||
MOCK_METHOD0(destroy, ze_result_t());
|
||||
MOCK_METHOD4(executeCommandLists,
|
||||
ze_result_t(uint32_t numCommandLists, ze_command_list_handle_t *phCommandLists,
|
||||
ze_fence_handle_t hFence, bool performMigration));
|
||||
MOCK_METHOD3(executeCommands, ze_result_t(uint32_t numCommands,
|
||||
void *phCommands,
|
||||
ze_fence_handle_t hFence));
|
||||
MOCK_METHOD1(synchronize, ze_result_t(uint32_t timeout));
|
||||
|
||||
MOCK_METHOD2(dispatchTaskCountWrite, void(NEO::LinearStream &commandStream, bool flushDataCache));
|
||||
};
|
||||
|
||||
template <GFXCORE_FAMILY gfxCoreFamily>
|
||||
struct MockCommandQueueHw : public L0::CommandQueueHw<gfxCoreFamily> {
|
||||
MockCommandQueueHw(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc) : L0::CommandQueueHw<gfxCoreFamily>(device, csr, desc) {
|
||||
}
|
||||
ze_result_t synchronize(uint32_t timeout) override {
|
||||
synchronizedCalled++;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
uint32_t synchronizedCalled = 0;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
33
level_zero/core/test/unit_tests/mocks/mock_device.cpp
Normal file
33
level_zero/core/test/unit_tests/mocks/mock_device.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mock_device.h"
|
||||
|
||||
#include "shared/source/device/device.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using ::testing::AnyNumber;
|
||||
using ::testing::Return;
|
||||
|
||||
Mock<Device>::Mock() {
|
||||
ON_CALL(*this, getMOCS(false, false)).WillByDefault(Return(0));
|
||||
EXPECT_CALL(*this, getMOCS(false, false)).Times(AnyNumber());
|
||||
ON_CALL(*this, getMOCS(true, false)).WillByDefault(Return(2));
|
||||
EXPECT_CALL(*this, getMOCS(true, false)).Times(AnyNumber());
|
||||
|
||||
EXPECT_CALL(*this, getMaxNumHwThreads).WillRepeatedly(Return(16));
|
||||
}
|
||||
|
||||
Mock<Device>::~Mock() {
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
118
level_zero/core/test/unit_tests/mocks/mock_device.h
Normal file
118
level_zero/core/test/unit_tests/mocks/mock_device.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/command_stream/preemption_mode.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/device/device_info.h"
|
||||
|
||||
#include "level_zero/core/source/device.h"
|
||||
#include "level_zero/core/source/driver_handle.h"
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
#include "level_zero/tools/source/metrics/metric.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
#endif
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <>
|
||||
struct WhiteBox<::L0::Device> : public ::L0::Device {};
|
||||
|
||||
using Device = WhiteBox<::L0::Device>;
|
||||
|
||||
template <>
|
||||
struct Mock<Device> : public Device {
|
||||
Mock();
|
||||
~Mock() override;
|
||||
|
||||
MOCK_METHOD0(getRootDeviceIndex, uint32_t());
|
||||
MOCK_METHOD2(canAccessPeer, ze_result_t(ze_device_handle_t hPeerDevice, ze_bool_t *value));
|
||||
MOCK_METHOD2(copyCommandList, ze_result_t(ze_command_list_handle_t hCommandList,
|
||||
ze_command_list_handle_t *phCommandList));
|
||||
MOCK_METHOD2(createCommandList, ze_result_t(const ze_command_list_desc_t *desc,
|
||||
ze_command_list_handle_t *commandList));
|
||||
|
||||
MOCK_METHOD2(createCommandListImmediate, ze_result_t(const ze_command_queue_desc_t *desc,
|
||||
ze_command_list_handle_t *commandList));
|
||||
|
||||
MOCK_METHOD2(createCommandQueue, ze_result_t(const ze_command_queue_desc_t *desc,
|
||||
ze_command_queue_handle_t *commandQueue));
|
||||
|
||||
MOCK_METHOD2(createEventPool,
|
||||
ze_result_t(const ze_event_pool_desc_t *desc, ze_event_pool_handle_t *eventPool));
|
||||
MOCK_METHOD2(createImage, ze_result_t(const ze_image_desc_t *desc, ze_image_handle_t *phImage));
|
||||
|
||||
MOCK_METHOD3(createModule, ze_result_t(const ze_module_desc_t *desc, ze_module_handle_t *module,
|
||||
ze_module_build_log_handle_t *buildLog));
|
||||
MOCK_METHOD2(createSampler,
|
||||
ze_result_t(const ze_sampler_desc_t *pDesc, ze_sampler_handle_t *phSampler));
|
||||
MOCK_METHOD1(evictImage, ze_result_t(ze_image_handle_t hImage));
|
||||
MOCK_METHOD2(evictMemory, ze_result_t(void *ptr, size_t size));
|
||||
MOCK_METHOD1(getComputeProperties,
|
||||
ze_result_t(ze_device_compute_properties_t *pComputeProperties));
|
||||
MOCK_METHOD2(getP2PProperties, ze_result_t(ze_device_handle_t hPeerDevice,
|
||||
ze_device_p2p_properties_t *pP2PProperties));
|
||||
MOCK_METHOD1(getKernelProperties, ze_result_t(ze_device_kernel_properties_t *pKernelProperties));
|
||||
MOCK_METHOD2(getMemoryProperties, ze_result_t(uint32_t *pCount, ze_device_memory_properties_t *pMemProperties));
|
||||
MOCK_METHOD1(getMemoryAccessProperties, ze_result_t(ze_device_memory_access_properties_t *pMemAccessProperties));
|
||||
MOCK_METHOD1(getProperties, ze_result_t(ze_device_properties_t *pDeviceProperties));
|
||||
MOCK_METHOD2(getSubDevice, ze_result_t(uint32_t ordinal, ze_device_handle_t *phSubDevice));
|
||||
MOCK_METHOD2(getSubDevices, ze_result_t(uint32_t *pCount, ze_device_handle_t *phSubdevices));
|
||||
MOCK_METHOD1(makeImageResident, ze_result_t(ze_image_handle_t hImage));
|
||||
MOCK_METHOD2(makeMemoryResident, ze_result_t(void *ptr, size_t size));
|
||||
MOCK_METHOD1(setIntermediateCacheConfig, ze_result_t(ze_cache_config_t CacheConfig));
|
||||
MOCK_METHOD1(setLastLevelCacheConfig, ze_result_t(ze_cache_config_t CacheConfig));
|
||||
MOCK_METHOD1(getCacheProperties, ze_result_t(ze_device_cache_properties_t *pCacheProperties));
|
||||
|
||||
MOCK_METHOD2(imageGetProperties,
|
||||
ze_result_t(const ze_image_desc_t *desc, ze_image_properties_t *pImageProperties));
|
||||
MOCK_METHOD1(getDeviceImageProperties,
|
||||
ze_result_t(ze_device_image_properties_t *pDeviceImageProperties));
|
||||
MOCK_METHOD0(systemBarrier, ze_result_t());
|
||||
MOCK_METHOD3(registerCLMemory, ze_result_t(cl_context context, cl_mem mem, void **ptr));
|
||||
MOCK_METHOD3(registerCLProgram,
|
||||
ze_result_t(cl_context context, cl_program program, ze_module_handle_t *phModule));
|
||||
MOCK_METHOD3(registerCLCommandQueue,
|
||||
ze_result_t(cl_context context, cl_command_queue command_queue,
|
||||
ze_command_queue_handle_t *phCommandQueue));
|
||||
// Runtime internal methods
|
||||
MOCK_METHOD0(getMemoryManager, NEO::MemoryManager *());
|
||||
MOCK_METHOD0(getExecEnvironment, void *());
|
||||
MOCK_METHOD0(getHwHelper, NEO::HwHelper &());
|
||||
MOCK_CONST_METHOD0(isMultiDeviceCapable, bool());
|
||||
MOCK_METHOD0(getBuiltinFunctionsLib, BuiltinFunctionsLib *());
|
||||
MOCK_METHOD2(getMOCS, uint32_t(bool l3enabled, bool l1enabled));
|
||||
MOCK_CONST_METHOD0(getMaxNumHwThreads, uint32_t());
|
||||
|
||||
MOCK_METHOD2(activateMetricGroups,
|
||||
ze_result_t(uint32_t count, zet_metric_group_handle_t *phMetricGroups));
|
||||
MOCK_METHOD0(getOsInterface, NEO::OSInterface &());
|
||||
MOCK_CONST_METHOD0(getPlatformInfo, uint32_t());
|
||||
MOCK_METHOD0(getMetricContext, MetricContext &());
|
||||
MOCK_CONST_METHOD0(getHwInfo, const NEO::HardwareInfo &());
|
||||
MOCK_METHOD0(getDriverHandle, L0::DriverHandle *());
|
||||
MOCK_METHOD1(setDriverHandle, void(L0::DriverHandle *));
|
||||
|
||||
MOCK_CONST_METHOD0(getDevicePreemptionMode, NEO::PreemptionMode());
|
||||
MOCK_CONST_METHOD0(getDeviceInfo, const NEO::DeviceInfo &());
|
||||
MOCK_METHOD0(getNEODevice, NEO::Device *());
|
||||
MOCK_METHOD0(activateMetricGroups, void());
|
||||
MOCK_CONST_METHOD0(getDebugSurface, NEO::GraphicsAllocation *());
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
30
level_zero/core/test/unit_tests/mocks/mock_driver.cpp
Normal file
30
level_zero/core/test/unit_tests/mocks/mock_driver.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mock_driver.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using MockDriver = Mock<L0::ult::Driver>;
|
||||
using ::testing::Invoke;
|
||||
|
||||
Mock<Driver>::Mock() {
|
||||
previousDriver = driver;
|
||||
driver = this;
|
||||
EXPECT_CALL(*this, initialize)
|
||||
.WillRepeatedly(Invoke(this, &MockDriver::mockInitialize));
|
||||
}
|
||||
|
||||
Mock<Driver>::~Mock() {
|
||||
if (driver == this) {
|
||||
driver = previousDriver;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
48
level_zero/core/test/unit_tests/mocks/mock_driver.h
Normal file
48
level_zero/core/test/unit_tests/mocks/mock_driver.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/core/source/driver_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
#endif
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <>
|
||||
struct WhiteBox<::L0::DriverImp> : public ::L0::DriverImp {
|
||||
};
|
||||
|
||||
using Driver = WhiteBox<::L0::DriverImp>;
|
||||
|
||||
template <>
|
||||
struct Mock<Driver> : public DriverImp {
|
||||
Mock();
|
||||
virtual ~Mock();
|
||||
|
||||
MOCK_METHOD1(driverInit, ze_result_t(ze_init_flag_t));
|
||||
MOCK_METHOD1(initialize, void(bool *result));
|
||||
|
||||
ze_result_t mockInit(ze_init_flag_t) { return this->DriverImp::driverInit(ZE_INIT_FLAG_NONE); }
|
||||
void mockInitialize(bool *result) { *result = true; }
|
||||
|
||||
Driver *previousDriver = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mock_memory_manager.h"
|
||||
|
||||
#include "shared/source/helpers/aligned_memory.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
using namespace testing;
|
||||
using ::testing::Return;
|
||||
|
||||
Mock<NEO::MemoryManager>::Mock(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(executionEnvironment) {
|
||||
EXPECT_CALL(*this, allocateGraphicsMemoryInPreferredPool)
|
||||
.WillRepeatedly(Invoke(this, &Mock<NEO::MemoryManager>::doAllocateGraphicsMemoryInPreferredPool));
|
||||
EXPECT_CALL(*this, freeGraphicsMemory)
|
||||
.WillRepeatedly(Invoke(this, &Mock<NEO::MemoryManager>::doFreeGraphicsMemory));
|
||||
}
|
||||
|
||||
inline NEO::GraphicsAllocation *Mock<NEO::MemoryManager>::doAllocateGraphicsMemoryInPreferredPool(const NEO::AllocationProperties &properties, const void *hostPtr) {
|
||||
void *buffer;
|
||||
if (hostPtr != nullptr) {
|
||||
buffer = const_cast<void *>(hostPtr);
|
||||
} else {
|
||||
buffer = alignedMalloc(properties.size, MemoryConstants::pageSize);
|
||||
}
|
||||
uint64_t baseAddress = 0;
|
||||
if (properties.allocationType == NEO::GraphicsAllocation::AllocationType::INTERNAL_HEAP) {
|
||||
baseAddress = castToUint64(alignDown(buffer, MemoryConstants::pageSize64k));
|
||||
}
|
||||
auto allocation = new NEO::GraphicsAllocation(properties.rootDeviceIndex, properties.allocationType,
|
||||
buffer, reinterpret_cast<uint64_t>(buffer), baseAddress, properties.size,
|
||||
MemoryPool::System4KBPages);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
inline void Mock<NEO::MemoryManager>::doFreeGraphicsMemory(NEO::GraphicsAllocation *allocation) {
|
||||
if (allocation == nullptr) {
|
||||
return;
|
||||
}
|
||||
alignedFree(allocation->getUnderlyingBuffer());
|
||||
delete allocation;
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
50
level_zero/core/test/unit_tests/mocks/mock_memory_manager.h
Normal file
50
level_zero/core/test/unit_tests/mocks/mock_memory_manager.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/memory_manager/unified_memory_manager.h"
|
||||
|
||||
#include "opencl/source/memory_manager/os_agnostic_memory_manager.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/core/test/unit_tests/white_box.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
#endif
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <>
|
||||
struct WhiteBox<::NEO::OsAgnosticMemoryManager> : public ::NEO::OsAgnosticMemoryManager {
|
||||
using BaseClass = ::NEO::OsAgnosticMemoryManager;
|
||||
WhiteBox(NEO::ExecutionEnvironment &executionEnvironment) : NEO::OsAgnosticMemoryManager(executionEnvironment) {}
|
||||
};
|
||||
|
||||
using MemoryManagerMock = WhiteBox<::NEO::OsAgnosticMemoryManager>;
|
||||
|
||||
template <>
|
||||
struct Mock<NEO::MemoryManager> : public MemoryManagerMock {
|
||||
Mock(NEO::ExecutionEnvironment &executionEnvironment);
|
||||
MOCK_METHOD2(allocateGraphicsMemoryInPreferredPool,
|
||||
NEO::GraphicsAllocation *(const NEO::AllocationProperties &properties, const void *hostPtr));
|
||||
MOCK_METHOD1(freeGraphicsMemory, void(NEO::GraphicsAllocation *));
|
||||
|
||||
NEO::GraphicsAllocation *doAllocateGraphicsMemoryInPreferredPool(const NEO::AllocationProperties &properties, const void *hostPtr);
|
||||
void doFreeGraphicsMemory(NEO::GraphicsAllocation *allocation);
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
@@ -8,3 +8,5 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter_test.cpp
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_debugger.cpp
|
||||
)
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/command_stream/linear_stream.h"
|
||||
#include "shared/source/gen_common/reg_configs/reg_configs_common.h"
|
||||
#include "shared/source/helpers/preamble.h"
|
||||
#include "shared/test/unit_test/mocks/mock_os_library.h"
|
||||
|
||||
#include "opencl/test/unit_test/gen_common/gen_cmd_parse.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_device.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "level_zero/core/source/cmdqueue_hw.h"
|
||||
#include "level_zero/core/source/fence.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
|
||||
#include <level_zero/ze_api.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
struct ActiveDebuggerFixture {
|
||||
void SetUp() {
|
||||
auto executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(*platformDevices);
|
||||
|
||||
debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(debugger);
|
||||
executionEnvironment->initializeMemoryManager();
|
||||
|
||||
device = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
|
||||
device->setDebuggerActive(true);
|
||||
|
||||
std::vector<std::unique_ptr<NEO::Device>> devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(device));
|
||||
|
||||
auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices)));
|
||||
driverHandle.reset(driverHandleUlt);
|
||||
|
||||
ASSERT_NE(nullptr, driverHandle);
|
||||
|
||||
ze_device_handle_t hDevice;
|
||||
uint32_t count = 1;
|
||||
ze_result_t result = driverHandle->getDevice(&count, &hDevice);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
deviceL0 = L0::Device::fromHandle(hDevice);
|
||||
ASSERT_NE(nullptr, deviceL0);
|
||||
}
|
||||
void TearDown() {
|
||||
}
|
||||
|
||||
std::unique_ptr<L0::ult::WhiteBox<L0::DriverHandle>> driverHandle;
|
||||
NEO::MockDevice *device = nullptr;
|
||||
L0::Device *deviceL0;
|
||||
MockActiveSourceLevelDebugger *debugger = nullptr;
|
||||
};
|
||||
|
||||
using CommandQueueDebugCommandsTest = Test<ActiveDebuggerFixture>;
|
||||
|
||||
HWTEST_F(CommandQueueDebugCommandsTest, givenDebuggingEnabledWhenCommandListIsExecutedThenKernelDebugCommandsAreAdded) {
|
||||
ze_command_queue_desc_t queueDesc = {};
|
||||
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc));
|
||||
ASSERT_NE(nullptr, commandQueue->commandStream);
|
||||
|
||||
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
|
||||
|
||||
ze_command_list_handle_t commandLists[] = {
|
||||
CommandList::create(productFamily, deviceL0)->toHandle()};
|
||||
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
|
||||
|
||||
auto result = commandQueue->executeCommandLists(numCommandLists, commandLists, nullptr, true);
|
||||
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
auto usedSpaceAfter = commandQueue->commandStream->getUsed();
|
||||
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
|
||||
|
||||
GenCmdList cmdList;
|
||||
ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(
|
||||
cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter));
|
||||
using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM;
|
||||
|
||||
auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end());
|
||||
ASSERT_LE(2u, miLoadImm.size());
|
||||
|
||||
MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[0]);
|
||||
ASSERT_NE(nullptr, miLoad);
|
||||
|
||||
EXPECT_EQ(DebugModeRegisterOffset<FamilyType>::registerOffset, miLoad->getRegisterOffset());
|
||||
EXPECT_EQ(DebugModeRegisterOffset<FamilyType>::debugEnabledValue, miLoad->getDataDword());
|
||||
|
||||
miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[1]);
|
||||
ASSERT_NE(nullptr, miLoad);
|
||||
|
||||
EXPECT_EQ(TdDebugControlRegisterOffset::registerOffset, miLoad->getRegisterOffset());
|
||||
EXPECT_EQ(TdDebugControlRegisterOffset::debugEnabledValue, miLoad->getDataDword());
|
||||
|
||||
for (auto i = 0u; i < numCommandLists; i++) {
|
||||
auto commandList = CommandList::fromHandle(commandLists[i]);
|
||||
commandList->destroy();
|
||||
}
|
||||
|
||||
commandQueue->destroy();
|
||||
}
|
||||
|
||||
using DeviceWithDebuggerEnabledTest = Test<ActiveDebuggerFixture>;
|
||||
|
||||
TEST_F(DeviceWithDebuggerEnabledTest, givenDebuggingEnabledWhenDeviceIsCreatedThenItHasDebugSurfaceCreated) {
|
||||
EXPECT_NE(nullptr, deviceL0->getDebugSurface());
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
32
level_zero/core/test/unit_tests/white_box.h
Normal file
32
level_zero/core/test/unit_tests/white_box.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
template <typename Type>
|
||||
struct WhiteBox : public Type {};
|
||||
|
||||
template <typename Type>
|
||||
WhiteBox<Type> *whitebox_cast(Type *obj) {
|
||||
return static_cast<WhiteBox<Type> *>(obj);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
WhiteBox<Type> &whitebox_cast(Type &obj) {
|
||||
return static_cast<WhiteBox<Type> &>(obj);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
Type *blackbox_cast(WhiteBox<Type> *obj) {
|
||||
return static_cast<Type *>(obj);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user