From 2047fc88f94752ba55db0313db5974cccac06dd1 Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Thu, 23 Dec 2021 13:48:36 +0000 Subject: [PATCH] Move execution environment helper to shared Signed-off-by: Zbigniew Zdanowicz --- .../create_command_stream_receiver_tests.cpp | 20 +++-- .../fixtures/buffer_enqueue_fixture.h | 4 +- .../device_instrumentation_fixture.cpp | 2 +- .../windows/gmm_callbacks_tests_gen12lp.cpp | 15 +--- ...pp => cl_execution_environment_helper.cpp} | 6 +- .../helpers/cl_execution_environment_helper.h | 16 ++++ opencl/test/unit_test/libult/CMakeLists.txt | 4 +- .../memory_manager/memory_manager_tests.cpp | 2 +- .../linux/device_command_stream_tests.cpp | 9 ++- .../linux/drm_command_stream_tests_1.cpp | 2 +- .../linux/drm_command_stream_tests_2.cpp | 2 +- .../windows/device_command_stream_tests.cpp | 64 ++++++++-------- .../windows/wddm_memory_manager_tests.cpp | 74 ++++++++++++------- .../windows/wddm_memory_manager_tests.h | 7 +- ...d_write_buffer_scenarios_windows_tests.cpp | 4 +- .../source_level_debugger_csr_tests.h | 2 +- .../source_level_debugger_tests.cpp | 2 +- .../common/fixtures/gmm_callbacks_fixture.h | 25 +++++++ .../helpers/execution_environment_helper.cpp | 29 ++++++++ .../helpers/execution_environment_helper.h | 4 +- shared/test/common/libult/CMakeLists.txt | 7 +- 21 files changed, 198 insertions(+), 102 deletions(-) rename opencl/test/unit_test/helpers/{execution_environment_helper.cpp => cl_execution_environment_helper.cpp} (78%) create mode 100644 opencl/test/unit_test/helpers/cl_execution_environment_helper.h create mode 100644 shared/test/common/fixtures/gmm_callbacks_fixture.h create mode 100644 shared/test/common/helpers/execution_environment_helper.cpp rename {opencl/test/unit_test => shared/test/common}/helpers/execution_environment_helper.h (82%) diff --git a/opencl/test/unit_test/command_stream/create_command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/create_command_stream_receiver_tests.cpp index 70e3412737..e543c4a553 100644 --- a/opencl/test/unit_test/command_stream/create_command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/create_command_stream_receiver_tests.cpp @@ -10,14 +10,13 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/memory_manager/os_agnostic_memory_manager.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/libult/create_command_stream.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/fixtures/mock_aub_center_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" - using namespace NEO; struct CreateCommandStreamReceiverTest : public ::testing::TestWithParam {}; @@ -26,6 +25,8 @@ HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetTo DebugManagerStateRestore stateRestorer; HardwareInfo *hwInfo = nullptr; ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + ASSERT_NE(nullptr, executionEnvironment->memoryManager.get()); + executionEnvironment->incRefInternal(); MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); CommandStreamReceiverType csrType = GetParam(); @@ -33,14 +34,17 @@ HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetTo VariableBackup backup(&ultHwConfig); ultHwConfig.useHwCsr = true; DebugManager.flags.SetCommandStreamReceiver.set(csrType); - auto csr = std::unique_ptr(createCommandStream(*executionEnvironment, 0, 1)); + { + auto csr = std::unique_ptr(createCommandStream(*executionEnvironment, 0, 1)); - if (csrType < CommandStreamReceiverType::CSR_TYPES_NUM) { - EXPECT_NE(nullptr, csr.get()); - } else { - EXPECT_EQ(nullptr, csr.get()); + if (csrType < CommandStreamReceiverType::CSR_TYPES_NUM) { + EXPECT_NE(nullptr, csr.get()); + } else { + EXPECT_EQ(nullptr, csr.get()); + } } - EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); + + executionEnvironment->decRefInternal(); } static CommandStreamReceiverType commandStreamReceiverTypes[] = { diff --git a/opencl/test/unit_test/fixtures/buffer_enqueue_fixture.h b/opencl/test/unit_test/fixtures/buffer_enqueue_fixture.h index 019df79065..047fb58873 100644 --- a/opencl/test/unit_test/fixtures/buffer_enqueue_fixture.h +++ b/opencl/test/unit_test/fixtures/buffer_enqueue_fixture.h @@ -14,8 +14,8 @@ #include "shared/test/common/test_macros/test.h" #include "opencl/test/unit_test/fixtures/buffer_fixture.h" +#include "opencl/test/unit_test/helpers/cl_execution_environment_helper.h" #include "opencl/test/unit_test/helpers/cl_hw_parse.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" using namespace NEO; @@ -27,7 +27,7 @@ struct BufferEnqueueFixture : public ClHardwareParse, } void SetUp() override { - executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + executionEnvironment = getClExecutionEnvironmentImpl(hwInfo, 1); } void TearDown() override { diff --git a/opencl/test/unit_test/fixtures/device_instrumentation_fixture.cpp b/opencl/test/unit_test/fixtures/device_instrumentation_fixture.cpp index 078f24fbf2..c6b29a6e1a 100644 --- a/opencl/test/unit_test/fixtures/device_instrumentation_fixture.cpp +++ b/opencl/test/unit_test/fixtures/device_instrumentation_fixture.cpp @@ -7,10 +7,10 @@ #include "opencl/test/unit_test/fixtures/device_instrumentation_fixture.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/mocks/mock_device.h" #include "opencl/source/cl_device/cl_device.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_platform.h" namespace NEO { diff --git a/opencl/test/unit_test/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp b/opencl/test/unit_test/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp index ad408ae234..72709a9ca1 100644 --- a/opencl/test/unit_test/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp +++ b/opencl/test/unit_test/gen12lp/windows/gmm_callbacks_tests_gen12lp.cpp @@ -13,18 +13,15 @@ #include "shared/source/helpers/windows/gmm_callbacks.h" #include "shared/source/os_interface/windows/wddm_device_command_stream.h" #include "shared/test/common/cmd_parse/hw_parse.h" +#include "shared/test/common/fixtures/gmm_callbacks_fixture.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/test_macros/test.h" -#include "opencl/source/platform/platform.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" -#include "opencl/test/unit_test/mocks/mock_platform.h" - using namespace NEO; -using Gen12LpGmmCallbacksTests = ::testing::Test; +using Gen12LpGmmCallbacksTests = ::Test; template struct MockAubCsrToTestNotifyAubCapture : public AUBCommandStreamReceiverHw { @@ -33,9 +30,6 @@ struct MockAubCsrToTestNotifyAubCapture : public AUBCommandStreamReceiverHwinitializeMemoryManager(); auto csr = std::make_unique>(*executionEnvironment, 0, 1); uint64_t address = 0xFEDCBA9876543210; size_t size = 1024; @@ -46,9 +40,8 @@ GEN12LPTEST_F(Gen12LpGmmCallbacksTests, givenCsrWithoutAubDumpWhenNotifyAubCaptu } GEN12LPTEST_F(Gen12LpGmmCallbacksTests, givenWddmCsrWhenWriteL3CalledThenWriteTwoMmio) { - typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; - ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); - executionEnvironment->initializeMemoryManager(); + using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM; + UltCommandStreamReceiver csr(*executionEnvironment, 0, 1); uint8_t buffer[128] = {}; csr.commandStream.replaceBuffer(buffer, 128); diff --git a/opencl/test/unit_test/helpers/execution_environment_helper.cpp b/opencl/test/unit_test/helpers/cl_execution_environment_helper.cpp similarity index 78% rename from opencl/test/unit_test/helpers/execution_environment_helper.cpp rename to opencl/test/unit_test/helpers/cl_execution_environment_helper.cpp index 839ea861ce..989e0b0966 100644 --- a/opencl/test/unit_test/helpers/execution_environment_helper.cpp +++ b/opencl/test/unit_test/helpers/cl_execution_environment_helper.cpp @@ -5,18 +5,18 @@ * */ -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" +#include "opencl/test/unit_test/helpers/cl_execution_environment_helper.h" +#include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/os_interface/device_factory.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" -#include "opencl/source/platform/platform.h" #include "opencl/test/unit_test/mocks/mock_platform.h" namespace NEO { -ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo, uint32_t rootDeviceEnvironments) { +ExecutionEnvironment *getClExecutionEnvironmentImpl(HardwareInfo *&hwInfo, uint32_t rootDeviceEnvironments) { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->prepareRootDeviceEnvironments(rootDeviceEnvironments); DebugManagerStateRestore restorer; diff --git a/opencl/test/unit_test/helpers/cl_execution_environment_helper.h b/opencl/test/unit_test/helpers/cl_execution_environment_helper.h new file mode 100644 index 0000000000..fcf921ca06 --- /dev/null +++ b/opencl/test/unit_test/helpers/cl_execution_environment_helper.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include + +namespace NEO { +class ExecutionEnvironment; +struct HardwareInfo; +ExecutionEnvironment *getClExecutionEnvironmentImpl(HardwareInfo *&hwInfo, uint32_t rootDeviceEnvironments); +} // namespace NEO diff --git a/opencl/test/unit_test/libult/CMakeLists.txt b/opencl/test/unit_test/libult/CMakeLists.txt index ac204e00b2..c6f7b4b01a 100644 --- a/opencl/test/unit_test/libult/CMakeLists.txt +++ b/opencl/test/unit_test/libult/CMakeLists.txt @@ -23,9 +23,9 @@ set(IGDRCL_SRCS_LIB_ULT ${NEO_SOURCE_DIR}/opencl/source/helpers/implicit_scaling_ocl.cpp ${NEO_SOURCE_DIR}/opencl/source/memory_manager/compression_selector_ocl.cpp ${NEO_SOURCE_DIR}/opencl/source/memory_manager/cpu_page_fault_manager_memory_sync.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/execution_environment_helper.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/execution_environment_helper.h ${NEO_SOURCE_DIR}/shared/source/helpers/allow_deferred_deleter.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/cl_execution_environment_helper.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/helpers/cl_execution_environment_helper.h ) add_library(igdrcl_libult OBJECT EXCLUDE_FROM_ALL diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 0c564fd941..d6b91a3025 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -18,6 +18,7 @@ #include "shared/source/program/program_initialization.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/mocks/mock_csr.h" @@ -46,7 +47,6 @@ #include "opencl/test/unit_test/fixtures/memory_allocator_fixture.h" #include "opencl/test/unit_test/fixtures/memory_manager_fixture.h" #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/helpers/raii_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" diff --git a/opencl/test/unit_test/os_interface/linux/device_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/linux/device_command_stream_tests.cpp index 69a1d69caf..c88e107580 100644 --- a/opencl/test/unit_test/os_interface/linux/device_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/device_command_stream_tests.cpp @@ -14,13 +14,11 @@ #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/os_interface/linux/device_command_stream_fixture.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/fixtures/mock_aub_center_fixture.h" -#include "opencl/test/unit_test/fixtures/cl_device_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" - #include "gtest/gtest.h" #include @@ -31,9 +29,14 @@ struct DeviceCommandStreamLeaksTest : ::testing::Test { void SetUp() override { HardwareInfo *hwInfo = nullptr; executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + executionEnvironment->incRefInternal(); MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); } + void TearDown() override { + executionEnvironment->decRefInternal(); + } + ExecutionEnvironment *executionEnvironment; }; diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp index 18efdbe674..f5d95cea57 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp @@ -25,6 +25,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/dispatch_flags_helper.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/mocks/linux/mock_drm_command_stream_receiver.h" #include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/mocks/mock_gmm.h" @@ -35,7 +36,6 @@ #include "opencl/source/mem_obj/buffer.h" #include "opencl/test/unit_test/fixtures/cl_device_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_buffer.h" #include "opencl/test/unit_test/mocks/mock_program.h" #include "opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h" diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp index adb20f966d..b877ea1988 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp @@ -23,6 +23,7 @@ #include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/dispatch_flags_helper.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/mocks/linux/mock_drm_command_stream_receiver.h" #include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/mocks/mock_gmm.h" @@ -34,7 +35,6 @@ #include "opencl/source/helpers/cl_memory_properties_helpers.h" #include "opencl/source/mem_obj/buffer.h" #include "opencl/test/unit_test/fixtures/cl_device_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_buffer.h" #include "opencl/test/unit_test/mocks/mock_program.h" #include "opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h" diff --git a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp index ddb1b8fc39..9ea6cda32b 100644 --- a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp @@ -28,6 +28,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/dispatch_flags_helper.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/mocks/mock_builtins.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_gmm_page_table_mngr.h" @@ -42,13 +43,7 @@ #include "shared/test/unit_test/fixtures/mock_aub_center_fixture.h" #include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" -#include "opencl/source/mem_obj/buffer.h" -#include "opencl/source/platform/platform.h" -#include "opencl/test/unit_test/fixtures/cl_device_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_buffer.h" -#include "opencl/test/unit_test/mocks/mock_platform.h" -#include "opencl/test/unit_test/mocks/mock_program.h" #include "hw_cmds.h" @@ -64,7 +59,7 @@ class WddmCommandStreamFixture { DebugManagerStateRestore stateRestore; - virtual void SetUp() { + void SetUp() { HardwareInfo *hwInfo = nullptr; DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); @@ -80,7 +75,7 @@ class WddmCommandStreamFixture { csr->getOsContext().ensureContextInitialized(); } - virtual void TearDown() { + void TearDown() { } }; @@ -152,7 +147,7 @@ class WddmCommandStreamWithMockGdiFixture { DebugManagerStateRestore stateRestore; GraphicsAllocation *preemptionAllocation = nullptr; - virtual void SetUp() { + void SetUp() { HardwareInfo *hwInfo = nullptr; ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as()); @@ -170,14 +165,14 @@ class WddmCommandStreamWithMockGdiFixture { this->csr->overrideRecorededCommandBuffer(*device); } - virtual void TearDown() { + void TearDown() { wddm = nullptr; } }; using WddmCommandStreamTest = ::Test; using WddmCommandStreamMockGdiTest = ::Test; -using WddmDefaultTest = ::Test; +using WddmDefaultTest = ::Test; struct DeviceCommandStreamTest : ::Test, DeviceFixture { void SetUp() override { DeviceFixture::SetUp(); @@ -306,12 +301,27 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFl memoryManager->freeGraphicsMemory(commandBuffer); } -TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOffWhenWorkloadIsSubmittedThenHeaderDoesntHavePreemptionFieldSet) { +struct WddmPreemptionHeaderFixture { + void SetUp() { + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + executionEnvironment->incRefInternal(); + wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as()); + } + + void TearDown() { + executionEnvironment->decRefInternal(); + } + + ExecutionEnvironment *executionEnvironment = nullptr; HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + WddmMock *wddm = nullptr; +}; + +using WddmPreemptionHeaderTests = ::Test; + +TEST_F(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOffWhenWorkloadIsSubmittedThenHeaderDoesntHavePreemptionFieldSet) { hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(hwInfo); - auto wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as()); auto csr = std::make_unique>(*executionEnvironment, 0, 1); executionEnvironment->memoryManager.reset(new MemoryManagerCreate(false, false, *executionEnvironment)); csr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); @@ -332,12 +342,9 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } -TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOnWhenWorkloadIsSubmittedThenHeaderDoesHavePreemptionFieldSet) { - HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); +TEST_F(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOnWhenWorkloadIsSubmittedThenHeaderDoesHavePreemptionFieldSet) { hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(hwInfo); - auto wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as()); auto csr = std::make_unique>(*executionEnvironment, 0, 1); executionEnvironment->memoryManager.reset(new MemoryManagerCreate(false, false, *executionEnvironment)); csr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); @@ -359,9 +366,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } -TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderContainsPreemptionFieldSet) { - HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); +TEST_F(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderContainsPreemptionFieldSet) { hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(hwInfo); auto commandStreamReceiver = std::make_unique>(*executionEnvironment, 0, 1); @@ -370,9 +375,7 @@ TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStream EXPECT_TRUE(header->NeedsMidBatchPreEmptionSupport); } -TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderPreemptionFieldIsNotSet) { - HardwareInfo *hwInfo = nullptr; - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); +TEST_F(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderPreemptionFieldIsNotSet) { hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(hwInfo); auto commandStreamReceiver = std::make_unique>(*executionEnvironment, 0, 1); @@ -923,14 +926,13 @@ using WddmSimpleTest = ::testing::Test; HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedOn) { DebugManager.flags.CsrDispatchMode.set(0); - ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); + HardwareInfo *hwInfo = nullptr; + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); std::unique_ptr device(Device::create(executionEnvironment, 0u)); - auto wddm = Wddm::createWddm(nullptr, *executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(wddm)); - executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); - std::unique_ptr> mockCsr(new MockWddmCsr(*executionEnvironment, 0, 1)); - EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); + { + std::unique_ptr> mockCsr(new MockWddmCsr(*executionEnvironment, 0, 1)); + EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); + } } HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVersionBasingOnFtrFlag) { diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index c7b80c969b..05b445c472 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -19,6 +19,7 @@ #include "shared/source/utilities/tag_allocator.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_deferred_deleter.h" @@ -34,7 +35,6 @@ #include "opencl/source/mem_obj/image.h" #include "opencl/source/mem_obj/mem_obj_helper.h" #include "opencl/source/platform/platform.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_platform.h" #include "opencl/test/unit_test/os_interface/windows/mock_wddm_allocation.h" @@ -136,31 +136,39 @@ TEST(WddmAllocationTest, givenMemoryPoolWhenPassedToWddmAllocationConstructorThe TEST(WddmMemoryManagerExternalHeapTest, WhenExternalHeapIsCreatedThenItHasCorrectBase) { HardwareInfo *hwInfo; auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); - std::unique_ptr wddm(static_cast(Wddm::createWddm(nullptr, *executionEnvironment->rootDeviceEnvironments[0].get()))); - wddm->init(); - uint64_t base = 0x56000; - uint64_t size = 0x9000; - wddm->setHeap32(base, size); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(wddm)); + executionEnvironment->incRefInternal(); + { + std::unique_ptr wddm(static_cast(Wddm::createWddm(nullptr, *executionEnvironment->rootDeviceEnvironments[0].get()))); + wddm->init(); + uint64_t base = 0x56000; + uint64_t size = 0x9000; + wddm->setHeap32(base, size); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(wddm)); - std::unique_ptr memoryManager = std::unique_ptr(new WddmMemoryManager(*executionEnvironment)); + std::unique_ptr memoryManager = std::unique_ptr(new WddmMemoryManager(*executionEnvironment)); - EXPECT_EQ(base, memoryManager->getExternalHeapBaseAddress(0, false)); + EXPECT_EQ(base, memoryManager->getExternalHeapBaseAddress(0, false)); + } + executionEnvironment->decRefInternal(); } TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWmmWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) { HardwareInfo *hwInfo; auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); - auto wddm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0].get()); - wddm->init(); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(wddm)); - bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); - DebugManager.flags.EnableDeferredDeleter.set(true); - MockWddmMemoryManager memoryManager(*executionEnvironment); - EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); - memoryManager.waitForDeletions(); - EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); - DebugManager.flags.EnableDeferredDeleter.set(actualDeleterFlag); + executionEnvironment->incRefInternal(); + { + auto wddm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0].get()); + wddm->init(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::move(wddm)); + bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); + DebugManager.flags.EnableDeferredDeleter.set(true); + MockWddmMemoryManager memoryManager(*executionEnvironment); + EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); + memoryManager.waitForDeletions(); + EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); + DebugManager.flags.EnableDeferredDeleter.set(actualDeleterFlag); + } + executionEnvironment->decRefInternal(); } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { @@ -1463,8 +1471,9 @@ TEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocati } struct WddmMemoryManagerWithAsyncDeleterTest : public ::testing::Test { - void SetUp() { + void SetUp() override { executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + executionEnvironment->incRefInternal(); wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as()); wddm->resetGdi(new MockGdi()); wddm->callBaseDestroyAllocations = false; @@ -1473,6 +1482,11 @@ struct WddmMemoryManagerWithAsyncDeleterTest : public ::testing::Test { memoryManager = std::make_unique(*executionEnvironment); memoryManager->setDeferredDeleter(deleter); } + + void TearDown() override { + executionEnvironment->decRefInternal(); + } + MockDeferredDeleter *deleter = nullptr; std::unique_ptr memoryManager; ExecutionEnvironment *executionEnvironment; @@ -1554,14 +1568,18 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalBaseIsReturned) { HardwareInfo *hwInfo; auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); - auto wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[0].get()); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(wddm)); - executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); - wddm->init(); - MockWddmMemoryManager memoryManager(*executionEnvironment); - auto heapBase = wddm->getGfxPartition().Heap32[static_cast(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Base; - heapBase = std::max(heapBase, static_cast(wddm->getWddmMinAddress())); - EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress(0, true)); + executionEnvironment->incRefInternal(); + { + auto wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[0].get()); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(wddm)); + executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(wddm); + wddm->init(); + MockWddmMemoryManager memoryManager(*executionEnvironment); + auto heapBase = wddm->getGfxPartition().Heap32[static_cast(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)].Base; + heapBase = std::max(heapBase, static_cast(wddm->getWddmMinAddress())); + EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress(0, true)); + } + executionEnvironment->decRefInternal(); } TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) { diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h index fe23ac6a23..217917f526 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h @@ -11,6 +11,7 @@ #include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/wddm_memory_operations_handler.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/mocks/mock_gmm.h" #include "shared/test/common/mocks/mock_gmm_page_table_mngr.h" #include "shared/test/common/mocks/mock_wddm_residency_allocations_container.h" @@ -19,7 +20,6 @@ #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_platform.h" @@ -176,11 +176,16 @@ class MockWddmMemoryManagerTest : public ::testing::Test { public: void SetUp() override { executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 2); + executionEnvironment->incRefInternal(); wddm = new WddmMock(*executionEnvironment->rootDeviceEnvironments[1].get()); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(wddm)); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(wddm); } + void TearDown() override { + executionEnvironment->decRefInternal(); + } + HardwareInfo *hwInfo = nullptr; WddmMock *wddm = nullptr; ExecutionEnvironment *executionEnvironment = nullptr; diff --git a/opencl/test/unit_test/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp b/opencl/test/unit_test/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp index acb9739782..d608b24a12 100644 --- a/opencl/test/unit_test/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp +++ b/opencl/test/unit_test/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp @@ -15,8 +15,8 @@ #include "shared/test/common/test_macros/test.h" #include "opencl/test/unit_test/fixtures/buffer_fixture.h" +#include "opencl/test/unit_test/helpers/cl_execution_environment_helper.h" #include "opencl/test/unit_test/helpers/cl_hw_parse.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" @@ -30,7 +30,7 @@ struct EnqueueBufferWindowsTest : public ClHardwareParse, void SetUp() override { DebugManager.flags.EnableBlitterForEnqueueOperations.set(0); - executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + executionEnvironment = getClExecutionEnvironmentImpl(hwInfo, 1); } void TearDown() override { diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h b/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h index a8e768f8cc..3e1c84d3a1 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h @@ -5,6 +5,7 @@ * */ +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/mocks/mock_builtins.h" #include "shared/test/common/mocks/mock_csr.h" #include "shared/test/common/mocks/mock_memory_manager.h" @@ -13,7 +14,6 @@ #include "shared/test/common/mocks/mock_source_level_debugger.h" #include "shared/test/common/test_macros/test.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp index 32bd6404f2..c410587835 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp @@ -12,6 +12,7 @@ #include "shared/source/program/kernel_info.h" #include "shared/source/source_level_debugger/source_level_debugger.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/execution_environment_helper.h" #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/libult/source_level_debugger_library.h" @@ -20,7 +21,6 @@ #include "shared/test/common/test_macros/test.h" #include "opencl/source/platform/platform.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_platform.h" diff --git a/shared/test/common/fixtures/gmm_callbacks_fixture.h b/shared/test/common/fixtures/gmm_callbacks_fixture.h new file mode 100644 index 0000000000..70f38f3e86 --- /dev/null +++ b/shared/test/common/fixtures/gmm_callbacks_fixture.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/execution_environment.h" +#include "shared/test/common/helpers/execution_environment_helper.h" + +using namespace NEO; + +struct GmmCallbacksFixture { + void SetUp() { + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + executionEnvironment->incRefInternal(); + } + + void TearDown() { + executionEnvironment->decRefInternal(); + } + + ExecutionEnvironment *executionEnvironment = nullptr; + HardwareInfo *hwInfo = nullptr; +}; diff --git a/shared/test/common/helpers/execution_environment_helper.cpp b/shared/test/common/helpers/execution_environment_helper.cpp new file mode 100644 index 0000000000..acdcb74326 --- /dev/null +++ b/shared/test/common/helpers/execution_environment_helper.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/helpers/execution_environment_helper.h" + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/device_factory.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/mocks/mock_execution_environment.h" + +namespace NEO { + +ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo, uint32_t rootDeviceEnvironments) { + ExecutionEnvironment *executionEnvironment = new MockExecutionEnvironment(); + executionEnvironment->prepareRootDeviceEnvironments(rootDeviceEnvironments); + DebugManagerStateRestore restorer; + DebugManager.flags.CreateMultipleRootDevices.set(rootDeviceEnvironments); + hwInfo = nullptr; + DeviceFactory::prepareDeviceEnvironments(*executionEnvironment); + hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo(); + executionEnvironment->initializeMemoryManager(); + + return executionEnvironment; +} +} // namespace NEO diff --git a/opencl/test/unit_test/helpers/execution_environment_helper.h b/shared/test/common/helpers/execution_environment_helper.h similarity index 82% rename from opencl/test/unit_test/helpers/execution_environment_helper.h rename to shared/test/common/helpers/execution_environment_helper.h index 04c4294b08..73a5a243b3 100644 --- a/opencl/test/unit_test/helpers/execution_environment_helper.h +++ b/shared/test/common/helpers/execution_environment_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,8 +8,6 @@ #pragma once #include "shared/source/execution_environment/execution_environment.h" -#include "CL/cl.h" - #include namespace NEO { diff --git a/shared/test/common/libult/CMakeLists.txt b/shared/test/common/libult/CMakeLists.txt index 218926c28f..79b2186b26 100644 --- a/shared/test/common/libult/CMakeLists.txt +++ b/shared/test/common/libult/CMakeLists.txt @@ -62,10 +62,15 @@ set(neo_libult_common_SRCS_LIB_ULT ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/aub_command_stream_receiver_fixture.h ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/device_fixture.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/device_fixture.h + ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/gmm_callbacks_fixture.h + ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/memory_management_fixture.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/memory_management_fixture.h ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/mock_execution_environment_gmm_fixture.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/mock_execution_environment_gmm_fixture.h ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/tbx_command_stream_fixture.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/tbx_command_stream_fixture.h + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/execution_environment_helper.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/execution_environment_helper.h ${NEO_SHARED_TEST_DIRECTORY}/common/helpers${BRANCH_DIR_SUFFIX}kernel_binary_helper_hash_value.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/kernel_binary_helper.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/kernel_binary_helper.h @@ -74,8 +79,6 @@ set(neo_libult_common_SRCS_LIB_ULT ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_leak_listener.h ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_management.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_management.h - ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/memory_management_fixture.cpp - ${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/memory_management_fixture.h ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/sip_init.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/test_files.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/test_files.h