diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index bb904f583f..1ad55ec4a0 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -177,13 +177,14 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw::create(const Hardw csr = new TbxCommandStreamReceiverHw(hwInfoIn, executionEnvironment); } - // Open our stream - csr->stream->open(nullptr); - - // Add the file header. - bool streamInitialized = csr->stream->init(AubMemDump::SteppingValues::A, csr->aubDeviceId); - csr->streamInitialized = streamInitialized; + if (csr->hardwareContext == nullptr) { + // Open our stream + csr->stream->open(nullptr); + // Add the file header. + bool streamInitialized = csr->stream->init(AubMemDump::SteppingValues::A, csr->aubDeviceId); + csr->streamInitialized = streamInitialized; + } return csr; } diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 6054eef784..1b206420f4 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -440,3 +440,16 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeCoherentIsC EXPECT_TRUE(mockHardwareContext->readMemoryCalled); } + +HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenHardwareContextIsCreatedThenTbxStreamInCsrIsNotInitialized) { + const HardwareInfo &hwInfo = *platformDevices[0]; + MockAubManager *mockManager = new MockAubManager(); + MockAubCenter *mockAubCenter = new MockAubCenter(&hwInfo, false, ""); + mockAubCenter->aubManager = std::unique_ptr(mockManager); + ExecutionEnvironment executionEnvironment; + executionEnvironment.aubCenter = std::unique_ptr(mockAubCenter); + auto tbxCsr = std::unique_ptr>(reinterpret_cast *>( + TbxCommandStreamReceiverHw::create(hwInfo, false, executionEnvironment))); + + EXPECT_FALSE(tbxCsr->streamInitialized); +}