Improve MockCsr reset pattern in unit tests

Change-Id: I0e9e13a44455de72d3a7298befa330a18b584788
Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz
2019-07-24 14:07:14 +02:00
committed by sys_ocldev
parent 4410ebe74d
commit d9e02697bf
2 changed files with 48 additions and 32 deletions

View File

@@ -14,6 +14,7 @@
#include "unit_tests/fixtures/enqueue_handler_fixture.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_execution_environment.h"
#include "unit_tests/mocks/mock_graphics_allocation.h"
#include "unit_tests/mocks/mock_timestamp_container.h"
@@ -46,15 +47,24 @@ HWTEST_F(EnqueueHandlerTest, GivenCommandStreamWithoutKernelWhenCommandEnqueuedT
EXPECT_EQ(allocation->getTaskCount(mockCmdQ->getGpgpuCommandStreamReceiver().getOsContext().getContextId()), 1u);
}
HWTEST_F(EnqueueHandlerTest, whenEnqueueCommandWithoutKernelThenPassCorrectDispatchFlags) {
auto executionEnvironment = pDevice->getExecutionEnvironment();
auto mockCsr = std::make_unique<MockCsrHw2<FamilyType>>(*executionEnvironment);
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
mockCsr->setupContext(*mockCmdQ->gpgpuEngine->osContext);
mockCsr->initializeTagAllocation();
auto oldCsr = mockCmdQ->gpgpuEngine->commandStreamReceiver;
mockCmdQ->gpgpuEngine->commandStreamReceiver = mockCsr.get();
mockCsr->createPreemptionAllocation();
struct DispatchFlagsTests : public ::testing::Test {
template <typename CsrType>
void SetUpImpl() {
auto executionEnvironment = new MockExecutionEnvironmentWithCsr<CsrType>(**platformDevices);
device.reset(MockDevice::createWithExecutionEnvironment<MockDevice>(*platformDevices, executionEnvironment, 0));
context = std::make_unique<MockContext>(device.get());
}
std::unique_ptr<MockDevice> device;
std::unique_ptr<MockContext> context;
};
HWTEST_F(DispatchFlagsTests, whenEnqueueCommandWithoutKernelThenPassCorrectDispatchFlags) {
using CsrType = MockCsrHw2<FamilyType>;
SetUpImpl<CsrType>();
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
auto mockCsr = static_cast<CsrType *>(&mockCmdQ->getGpgpuCommandStreamReceiver());
auto blocking = true;
TimestampPacketContainer previousTimestampPacketNodes;
@@ -66,19 +76,15 @@ HWTEST_F(EnqueueHandlerTest, whenEnqueueCommandWithoutKernelThenPassCorrectDispa
EXPECT_FALSE(mockCsr->passedDispatchFlags.implicitFlush);
EXPECT_TRUE(mockCsr->passedDispatchFlags.guardCommandBufferWithPipeControl);
EXPECT_EQ(mockCmdQ->isMultiEngineQueue(), mockCsr->passedDispatchFlags.multiEngineQueue);
EXPECT_EQ(pDevice->getPreemptionMode(), mockCsr->passedDispatchFlags.preemptionMode);
mockCmdQ->gpgpuEngine->commandStreamReceiver = oldCsr;
EXPECT_EQ(device->getPreemptionMode(), mockCsr->passedDispatchFlags.preemptionMode);
}
HWTEST_F(EnqueueHandlerTest, givenBlitEnqueueWhenDispatchingCommandsWithoutKernelThenDoImplicitFlush) {
auto executionEnvironment = pDevice->getExecutionEnvironment();
auto mockCsr = std::make_unique<MockCsrHw2<FamilyType>>(*executionEnvironment);
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
mockCsr->setupContext(*mockCmdQ->gpgpuEngine->osContext);
mockCsr->initializeTagAllocation();
auto oldCsr = mockCmdQ->gpgpuEngine->commandStreamReceiver;
mockCmdQ->gpgpuEngine->commandStreamReceiver = mockCsr.get();
mockCsr->createPreemptionAllocation();
HWTEST_F(DispatchFlagsTests, givenBlitEnqueueWhenDispatchingCommandsWithoutKernelThenDoImplicitFlush) {
using CsrType = MockCsrHw2<FamilyType>;
SetUpImpl<CsrType>();
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
auto mockCsr = static_cast<CsrType *>(&mockCmdQ->getGpgpuCommandStreamReceiver());
auto blocking = true;
TimestampPacketContainer previousTimestampPacketNodes;
@@ -88,18 +94,14 @@ HWTEST_F(EnqueueHandlerTest, givenBlitEnqueueWhenDispatchingCommandsWithoutKerne
EXPECT_TRUE(mockCsr->passedDispatchFlags.implicitFlush);
EXPECT_TRUE(mockCsr->passedDispatchFlags.guardCommandBufferWithPipeControl);
mockCmdQ->gpgpuEngine->commandStreamReceiver = oldCsr;
}
HWTEST_F(EnqueueHandlerTest, givenN1EnabledWhenDispatchingWithoutKernelTheAllowOutOfOrderExecution) {
auto executionEnvironment = pDevice->getExecutionEnvironment();
auto mockCsr = std::make_unique<MockCsrHw2<FamilyType>>(*executionEnvironment);
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
mockCsr->setupContext(*mockCmdQ->gpgpuEngine->osContext);
mockCsr->initializeTagAllocation();
auto oldCsr = mockCmdQ->gpgpuEngine->commandStreamReceiver;
mockCmdQ->gpgpuEngine->commandStreamReceiver = mockCsr.get();
mockCsr->createPreemptionAllocation();
HWTEST_F(DispatchFlagsTests, givenN1EnabledWhenDispatchingWithoutKernelTheAllowOutOfOrderExecution) {
using CsrType = MockCsrHw2<FamilyType>;
SetUpImpl<CsrType>();
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
auto mockCsr = static_cast<CsrType *>(&mockCmdQ->getGpgpuCommandStreamReceiver());
TimestampPacketContainer previousTimestampPacketNodes;
EventsRequest eventsRequest(0, nullptr, nullptr);
@@ -114,8 +116,6 @@ HWTEST_F(EnqueueHandlerTest, givenN1EnabledWhenDispatchingWithoutKernelTheAllowO
mockCsr->nTo1SubmissionModelEnabled = true;
mockCmdQ->enqueueCommandWithoutKernel(nullptr, 0, mockCmdQ->getCS(0), 0, blocked, true, &previousTimestampPacketNodes, eventsRequest, eventBuilder, 0);
EXPECT_TRUE(mockCsr->passedDispatchFlags.outOfOrderExecutionAllowed);
mockCmdQ->gpgpuEngine->commandStreamReceiver = oldCsr;
}
HWTEST_F(EnqueueHandlerTest, GivenCommandStreamWithoutKernelAndZeroSurfacesWhenEnqueuedHandlerThenProgramPipeControl) {

View File

@@ -8,6 +8,7 @@
#pragma once
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/helpers/options.h"
#include "unit_tests/fixtures/mock_aub_center_fixture.h"
@@ -36,4 +37,19 @@ struct MockExecutionEnvironment : ExecutionEnvironment {
std::string aubFileNameReceived = "";
bool useMockAubCenter = true;
};
template <typename CsrType>
struct MockExecutionEnvironmentWithCsr : public ExecutionEnvironment {
MockExecutionEnvironmentWithCsr() = delete;
MockExecutionEnvironmentWithCsr(const HardwareInfo &hwInfo) {
setHwInfo(&hwInfo);
auto &gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances();
commandStreamReceivers.resize(1);
for (uint32_t csrIndex = 0; csrIndex < gpgpuEngines.size(); csrIndex++) {
commandStreamReceivers[0].push_back(std::unique_ptr<CommandStreamReceiver>(new CsrType(*this)));
}
}
};
} // namespace NEO