test: StreamCapture on pipes

Enhance StreamCapture class to mimic gtest's CaptureStdout/Stderr functionality.
Store data in a pipe instead of a temporary file like gtest
resulting in faster test execution

Signed-off-by: Marcel Skierkowski <marcel.skierkowski@intel.com>
This commit is contained in:
Marcel Skierkowski
2025-06-06 16:24:08 +00:00
committed by Compute-Runtime-Automation
parent 767755df94
commit a52260ce63
66 changed files with 970 additions and 711 deletions

View File

@@ -15,6 +15,7 @@
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/relaxed_ordering_commands_helper.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/libult/ult_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
@@ -868,7 +869,8 @@ TEST_F(CommandListMemAdvisePageFault, givenValidDeviceMemPtrAndPageFaultHandlerA
EXPECT_EQ(handlerWithHints, reinterpret_cast<void *>(mockPageFaultManager->gpuDomainHandler));
testing::internal::CaptureStdout(); // start capturing
StreamCapture capture;
capture.captureStdout(); // start capturing
NEO::CpuPageFaultManager::PageFaultData pageData;
pageData.cmdQ = deviceImp;
@@ -878,7 +880,7 @@ TEST_F(CommandListMemAdvisePageFault, givenValidDeviceMemPtrAndPageFaultHandlerA
flags = deviceImp->memAdviseSharedAllocations[allocData];
EXPECT_EQ(0, flags.cpuMigrationBlocked);
std::string output = testing::internal::GetCapturedStdout(); // stop capturing
std::string output = capture.getCapturedStdout(); // stop capturing
std::string expectedString = "UMD transferred shared allocation";
uint32_t occurrences = 0u;

View File

@@ -9,6 +9,7 @@
#include "shared/source/helpers/preamble.h"
#include "shared/source/helpers/register_offsets.h"
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/libult/ult_command_stream_receiver.h"
#include "shared/test/common/test_macros/hw_test.h"
@@ -111,7 +112,8 @@ HWTEST_P(L0DebuggerWithBlitterTest, givenDebuggerLogsDisabledWhenCommandListIsSy
NEO::debugManager.flags.DebuggerLogBitmask.set(0);
EXPECT_NE(nullptr, device->getL0Debugger());
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue = ZE_RESULT_SUCCESS;
@@ -119,7 +121,7 @@ HWTEST_P(L0DebuggerWithBlitterTest, givenDebuggerLogsDisabledWhenCommandListIsSy
commandList->executeCommandListImmediate(false);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
size_t pos = output.find("Debugger: SBA");
EXPECT_EQ(std::string::npos, pos);

View File

@@ -11,6 +11,7 @@
#include "shared/source/helpers/register_offsets.h"
#include "shared/source/indirect_heap/indirect_heap.h"
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/mocks/mock_gmm_helper.h"
#include "shared/test/common/test_macros/hw_test.h"
@@ -276,7 +277,8 @@ HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledAndDebuggerLogsWhenCommandQueueIs
DebugManagerStateRestore restorer;
NEO::debugManager.flags.DebuggerLogBitmask.set(255);
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue;
@@ -294,7 +296,7 @@ HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledAndDebuggerLogsWhenCommandQueueIs
commandQueue->synchronize(0);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
size_t pos = output.find("INFO: Debugger: SBA stored ssh");
EXPECT_NE(std::string::npos, pos);
@@ -313,7 +315,8 @@ HWTEST2_F(L0DebuggerSimpleTest, givenNullL0DebuggerAndDebuggerLogsWhenCommandQue
NEO::debugManager.flags.DebuggerLogBitmask.set(255);
EXPECT_EQ(nullptr, device->getL0Debugger());
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue;
@@ -331,7 +334,7 @@ HWTEST2_F(L0DebuggerSimpleTest, givenNullL0DebuggerAndDebuggerLogsWhenCommandQue
commandQueue->synchronize(0);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
size_t pos = output.find("Debugger: SBA");
EXPECT_EQ(std::string::npos, pos);
@@ -345,7 +348,8 @@ HWTEST2_F(L0DebuggerTest, givenL0DebuggerAndDebuggerLogsDisabledWhenCommandQueue
NEO::debugManager.flags.DebuggerLogBitmask.set(0);
EXPECT_NE(nullptr, device->getL0Debugger());
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue;
@@ -363,7 +367,7 @@ HWTEST2_F(L0DebuggerTest, givenL0DebuggerAndDebuggerLogsDisabledWhenCommandQueue
commandQueue->synchronize(0);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
size_t pos = output.find("Debugger: SBA");
EXPECT_EQ(std::string::npos, pos);

View File

@@ -25,6 +25,7 @@
#include "shared/test/common/helpers/mock_product_helper_hw.h"
#include "shared/test/common/helpers/raii_gfx_core_helper.h"
#include "shared/test/common/helpers/raii_product_helper.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/libult/ult_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_compiler_product_helper.h"
@@ -2007,10 +2008,11 @@ TEST_F(DeviceTest, givenPrintGlobalTimestampIsSetWhenGetGlobalTimestampIsCalledT
capabilityTable.timestampValidBits = 36;
capabilityTable.kernelTimestampValidBits = 32;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
// Considering kernelTimestampValidBits(32)
auto gpuTimeStamp = cpuDeviceTime->mockGpuTimeInNs & 0xFFFFFFFF;
const std::string expectedString("Host timestamp in ns : 0 | Device timestamp in ns : " +
@@ -2038,10 +2040,11 @@ TEST_F(DeviceTest, givenPrintGlobalTimestampIsSetAnd64bitTimestampWhenGetGlobalT
uint64_t hostTs = 0u;
uint64_t deviceTs = 0u;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
ze_result_t result = device->getGlobalTimestamps(&hostTs, &deviceTs);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
const std::string expectedString("Host timestamp in ns : 0 | Device timestamp in ns : " +
std::to_string(static_cast<uint64_t>(neoDevice->getProfilingTimerResolution()) *
cpuDeviceTime->mockGpuTimeInNs) +

View File

@@ -12,6 +12,7 @@
#include "shared/source/utilities/buffer_pool_allocator.inl"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "shared/test/common/mocks/mock_device.h"
@@ -2753,9 +2754,10 @@ HWTEST_F(TimestampEventCreate, givenFlagPrintCalculatedTimestampsWhenCallQueryKe
event->hostAddressFromPool = &data;
ze_kernel_timestamp_result_t result = {};
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
event->queryKernelTimestamp(&result);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
std::stringstream expected;
expected << "globalStartTS: " << result.global.kernelStart << ", "
<< "globalEndTS: " << result.global.kernelEnd << ", "
@@ -2785,9 +2787,10 @@ TEST_F(TimestampEventUsedPacketSignalCreate, givenFlagPrintTimestampPacketConten
auto packedCount = 2u;
event->setPacketsInUse(packedCount);
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
event->queryKernelTimestamp(&results);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
std::stringstream expected;
for (uint32_t i = 0; i < packedCount; i++) {
@@ -2894,9 +2897,10 @@ HWTEST2_F(TimestampEventCreateMultiKernel, givenFlagPrintTimestampPacketContents
event->setPacketsInUse(packedCount);
ze_kernel_timestamp_result_t results;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
event->queryKernelTimestamp(&results);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
std::stringstream expected;
auto i = 0u;
for (uint32_t kernelId = 0u; kernelId < kernelCount; kernelId++) {
@@ -4313,7 +4317,8 @@ TEST_F(EventTests, givenDebugFlagSetWhenCallingResetThenSynchronizeBeforeReset)
*reinterpret_cast<uint32_t *>(event->hostAddressFromPool) = Event::STATE_SIGNALED;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
EXPECT_EQ(0u, event->hostSynchronizeCalled);
@@ -4321,7 +4326,7 @@ TEST_F(EventTests, givenDebugFlagSetWhenCallingResetThenSynchronizeBeforeReset)
EXPECT_EQ(1u, event->hostSynchronizeCalled);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
std::string expectedOutput("");
EXPECT_EQ(expectedOutput, output);
}
@@ -4335,7 +4340,8 @@ TEST_F(EventTests, givenDebugFlagSetWhenCallingResetThenPrintLogAndSynchronizeBe
{
event->failOnNextQueryStatus = false;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
EXPECT_EQ(0u, event->hostSynchronizeCalled);
@@ -4343,7 +4349,7 @@ TEST_F(EventTests, givenDebugFlagSetWhenCallingResetThenPrintLogAndSynchronizeBe
EXPECT_EQ(1u, event->hostSynchronizeCalled);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
std::string expectedOutput("");
EXPECT_EQ(expectedOutput, output);
}
@@ -4351,7 +4357,8 @@ TEST_F(EventTests, givenDebugFlagSetWhenCallingResetThenPrintLogAndSynchronizeBe
{
event->failOnNextQueryStatus = true;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
EXPECT_EQ(1u, event->hostSynchronizeCalled);
@@ -4359,7 +4366,7 @@ TEST_F(EventTests, givenDebugFlagSetWhenCallingResetThenPrintLogAndSynchronizeBe
EXPECT_EQ(2u, event->hostSynchronizeCalled);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
char expectedStr[128] = {};
snprintf(expectedStr, 128, "\nzeEventHostReset: Event %p not ready. Calling zeEventHostSynchronize.", event.get());

View File

@@ -26,6 +26,7 @@
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/helpers/gtest_helpers.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/libult/ult_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_bindless_heaps_helper.h"
#include "shared/test/common/mocks/mock_device.h"
@@ -3873,9 +3874,10 @@ HWTEST_F(PrintfHandlerTests, givenKernelWithPrintfWhenPrintingOutputWithBlitterU
printfAllocation[0] = 8;
printfAllocation[1] = 0;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
PrintfHandler::printOutput(kernelImmutableData.get(), &mockAllocation, &deviceImp, true);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
auto bcsEngine = device->tryGetEngine(NEO::EngineHelpers::getBcsEngineType(device->getRootDeviceEnvironment(), device->getDeviceBitfield(), device->getSelectorCopyEngine(), true), EngineUsage::internal);
if (bcsEngine) {
@@ -3937,10 +3939,11 @@ HWTEST_F(PrintfHandlerTests, givenPrintDebugMessagesAndKernelWithPrintfWhenBlitt
printfAllocation[0] = 8;
printfAllocation[1] = 0;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
testing::internal::CaptureStderr();
PrintfHandler::printOutput(kernelImmutableData.get(), &mockAllocation, &deviceImp, true);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
std::string error = testing::internal::GetCapturedStderr();
EXPECT_EQ(1u, bcsCsr->blitBufferCalled);
@@ -3975,9 +3978,10 @@ TEST_F(KernelPatchtokensPrintfStringMapTests, givenKernelWithPrintfStringsMapUsa
printfAllocation[0] = 8;
printfAllocation[1] = 0;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
kernel->printPrintfOutput(false);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
EXPECT_STREQ(expectedString.c_str(), output.c_str());
}
@@ -4003,9 +4007,10 @@ TEST_F(KernelPatchtokensPrintfStringMapTests, givenKernelWithPrintfStringsMapUsa
printfAllocation[0] = 8;
printfAllocation[1] = 0;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
kernel->printPrintfOutput(false);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
EXPECT_STREQ("", output.c_str());
}
@@ -4031,9 +4036,10 @@ TEST_F(KernelPatchtokensPrintfStringMapTests, givenKernelWithPrintfStringsMapUsa
printfAllocation[0] = 8;
printfAllocation[1] = 0;
testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
kernel->printPrintfOutput(false);
std::string output = testing::internal::GetCapturedStdout();
std::string output = capture.getCapturedStdout();
EXPECT_STREQ(expectedString.c_str(), output.c_str());
}

View File

@@ -8,6 +8,7 @@
#include "shared/source/built_ins/sip.h"
#include "shared/source/os_interface/windows/wddm_allocation.h"
#include "shared/source/os_interface/windows/wddm_debug.h"
#include "shared/test/common/helpers/stream_capture.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_sip.h"
#include "shared/test/common/mocks/windows/mock_wddm_eudebug.h"
@@ -920,11 +921,12 @@ TEST_F(DebugApiWindowsTest, givenEscapeReturnTimeoutWhenReadAndHandleEventCalled
auto session = std::make_unique<MockDebugSessionWindows>(config, device);
session->wddm = mockWddm;
::testing::internal::CaptureStdout();
StreamCapture capture;
capture.captureStdout();
mockWddm->numEvents = 1;
mockWddm->eventQueue[0].escapeReturnStatus = DBGUMD_RETURN_READ_EVENT_TIMEOUT_EXPIRED;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, session->readAndHandleEvent(100));
auto errorMessage = ::testing::internal::GetCapturedStdout();
auto errorMessage = capture.getCapturedStdout();
EXPECT_EQ(std::string(""), errorMessage);
}