Files
compute-runtime/opencl/test/unit_test/offline_compiler/stdout_capturer.h
Marcel Skierkowski b75fbe8e2c refactor: mock filesystem in ocloc ult pt.1
Mocked IO operations in ./ocloc_tests application

Mocked gtest stdout capture in ocloc tests

Related-To: NEO-14084
Signed-off-by: Marcel Skierkowski <marcel.skierkowski@intel.com>
2025-04-08 16:08:42 +02:00

43 lines
887 B
C++

/*
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/test/common/helpers/stdout_capture.h"
#include <string>
namespace NEO {
/*
* This class is a RAII wrapper for GTEST's mechanism, which allows capturing stdout.
* We must ensure that GetCapturedStdout() is called after CaptureStdout().
* If it is not invoked, then next call to CaptureStdout() will cause abort of the test application.
*/
class StdoutCapturer {
public:
StdoutCapturer() {
capture.captureStdout();
}
~StdoutCapturer() {
if (!outputAcquired) {
capture.getCapturedStdout();
}
}
std::string acquireOutput() {
outputAcquired = true;
return capture.getCapturedStdout();
}
private:
StdoutCapture capture;
bool outputAcquired{false};
};
} // namespace NEO