11/*
2- * Copyright (C) 2018 Intel Corporation
2+ * Copyright (C) 2018-2019 Intel Corporation
33 *
44 * SPDX-License-Identifier: MIT
55 *
1919#include " test.h"
2020#include < memory>
2121
22- typedef ::testing::Test CommandStreamReceiverWithActiveDebuggerTest;
22+ class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test {
23+ protected:
24+ template <typename FamilyType>
25+ auto createCSR () {
26+ hwInfo = nullptr ;
27+ executionEnvironment = getExecutionEnvironmentImpl (hwInfo);
28+ hwInfo->capabilityTable = platformDevices[0 ]->capabilityTable ;
29+ hwInfo->capabilityTable .sourceLevelDebuggerSupported = true ;
30+
31+ auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0 ], *executionEnvironment);
32+
33+ executionEnvironment->commandStreamReceivers .resize (1 );
34+ executionEnvironment->commandStreamReceivers [0 ][0 ].reset (mockCsr);
35+ auto mockMemoryManager = new MockMemoryManager (*executionEnvironment);
36+ executionEnvironment->memoryManager .reset (mockMemoryManager);
37+
38+ device.reset (Device::create<MockDevice>(&hwInfo[0 ], executionEnvironment, 0 ));
39+ device->setSourceLevelDebuggerActive (true );
40+
41+ return mockCsr;
42+ }
43+
44+ std::unique_ptr<MockDevice> device;
45+ ExecutionEnvironment *executionEnvironment = nullptr ;
46+ HardwareInfo *hwInfo = nullptr ;
47+ };
2348
2449HWTEST_F (CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndDisabledPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) {
25- auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr ));
26- device->setSourceLevelDebuggerActive (true );
27- device->allocatePreemptionAllocationIfNotPresent ();
28- auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0 ], *device->executionEnvironment );
2950
30- device-> resetCommandStreamReceiver (mockCsr );
51+ auto mockCsr = createCSR<FamilyType>( );
3152
3253 CommandQueueHw<FamilyType> commandQueue (nullptr , device.get (), 0 );
3354 auto &commandStream = commandQueue.getCS (4096u );
@@ -50,7 +71,7 @@ HWTEST_F(CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebugger
5071 *device);
5172
5273 auto sipType = SipKernel::getSipKernelType (device->getHardwareInfo ().pPlatform ->eRenderCoreFamily , true );
53- auto sipAllocation = device->getExecutionEnvironment ()->getBuiltIns ()->getSipKernel (sipType, *device. get () ).getSipAllocation ();
74+ auto sipAllocation = device->getExecutionEnvironment ()->getBuiltIns ()->getSipKernel (sipType, *device).getSipAllocation ();
5475 bool found = false ;
5576 for (auto allocation : mockCsr->copyOfAllocations ) {
5677 if (allocation == sipAllocation) {
@@ -66,15 +87,9 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs
6687 using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
6788 using STATE_SIP = typename FamilyType::STATE_SIP;
6889
69- auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>( nullptr ) );
90+ auto mockCsr = createCSR<FamilyType>( );
7091
7192 if (device->getHardwareInfo ().capabilityTable .defaultPreemptionMode == PreemptionMode::MidThread) {
72- device->setSourceLevelDebuggerActive (true );
73- device->allocatePreemptionAllocationIfNotPresent ();
74- auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0 ], *device->executionEnvironment );
75-
76- device->resetCommandStreamReceiver (mockCsr);
77-
7893 CommandQueueHw<FamilyType> commandQueue (nullptr , device.get (), 0 );
7994 auto &commandStream = commandQueue.getCS (4096u );
8095 auto &preambleStream = mockCsr->getCS (0 );
@@ -97,7 +112,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs
97112 *device);
98113
99114 auto sipType = SipKernel::getSipKernelType (device->getHardwareInfo ().pPlatform ->eRenderCoreFamily , true );
100- auto sipAllocation = device->getExecutionEnvironment ()->getBuiltIns ()->getSipKernel (sipType, *device. get () ).getSipAllocation ();
115+ auto sipAllocation = device->getExecutionEnvironment ()->getBuiltIns ()->getSipKernel (sipType, *device).getSipAllocation ();
101116
102117 HardwareParse hwParser;
103118 hwParser.parseCommands <FamilyType>(preambleStream);
@@ -122,23 +137,9 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs
122137 using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
123138 using STATE_SIP = typename FamilyType::STATE_SIP;
124139
125- HardwareInfo *hwInfo = nullptr ;
126- auto executionEnvironment = getExecutionEnvironmentImpl (hwInfo);
127- hwInfo->capabilityTable = platformDevices[0 ]->capabilityTable ;
128- hwInfo->capabilityTable .sourceLevelDebuggerSupported = true ;
129-
130- auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0 ], *executionEnvironment);
131-
132- executionEnvironment->commandStreamReceivers .resize (1 );
133- executionEnvironment->commandStreamReceivers [0 ][0 ].reset (mockCsr);
134- auto mockMemoryManager = new MockMemoryManager (*executionEnvironment);
135- executionEnvironment->memoryManager .reset (mockMemoryManager);
140+ auto mockCsr = createCSR<FamilyType>();
136141
137- auto device = std::unique_ptr<MockDevice>(Device::create<MockDevice>(&hwInfo[0 ], executionEnvironment, 0 ));
138142 if (device->getHardwareInfo ().capabilityTable .defaultPreemptionMode == PreemptionMode::MidThread) {
139- device->setSourceLevelDebuggerActive (true );
140- device->allocatePreemptionAllocationIfNotPresent ();
141-
142143 mockCsr->overrideDispatchPolicy (DispatchMode::ImmediateDispatch);
143144
144145 CommandQueueHw<FamilyType> commandQueue (nullptr , device.get (), 0 );
@@ -174,7 +175,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs
174175 *device);
175176
176177 auto sipType = SipKernel::getSipKernelType (device->getHardwareInfo ().pPlatform ->eRenderCoreFamily , true );
177- auto sipAllocation = device->getExecutionEnvironment ()->getBuiltIns ()->getSipKernel (sipType, *device. get () ).getSipAllocation ();
178+ auto sipAllocation = device->getExecutionEnvironment ()->getBuiltIns ()->getSipKernel (sipType, *device).getSipAllocation ();
178179
179180 HardwareParse hwParser;
180181 hwParser.parseCommands <FamilyType>(preambleStream);
0 commit comments