compute-runtime/opencl/test/unit_test/offline_compiler/stdout_capturer.h

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