OclocInvoke suppress print to stdout if has output

Suppressing output could be achieved with quiet option "-q",
but some information was gone because of it.
Call to oclocInvoke with output parameters passed should not
print message to stdout. All messages should be stored,
and returned to the user via output as stdout.log file.
This commit turns off printing messages to stdout when
output parameters are present.

Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
Krystian Chmielewski
2022-01-11 13:03:13 +00:00
committed by Compute-Runtime-Automation
parent 2194b647e9
commit 0089cb698f
4 changed files with 57 additions and 6 deletions

View File

@@ -2063,4 +2063,52 @@ TEST(OfflineCompilerTest, GivenDebugFlagWhenSetStatelessToStatefullBufferOffsetF
} }
} }
struct WhiteBoxOclocArgHelper : public OclocArgHelper {
using OclocArgHelper::messagePrinter;
using OclocArgHelper::OclocArgHelper;
};
TEST(OclocArgHelperTest, GivenOutputSuppressMessagesAndSaveItToFile) {
uint32_t numOutputs = 0U;
uint64_t *lenOutputs = nullptr;
uint8_t **outputs = nullptr;
char **nameOutputs = nullptr;
auto helper = std::unique_ptr<WhiteBoxOclocArgHelper>(new WhiteBoxOclocArgHelper(0, nullptr, nullptr, nullptr,
0, nullptr, nullptr, nullptr,
&numOutputs, &outputs, &lenOutputs, &nameOutputs));
EXPECT_TRUE(helper->messagePrinter.isSuppressed());
ConstStringRef printMsg = "Hello world!";
testing::internal::CaptureStdout();
helper->printf(printMsg.data());
std::string capturedStdout = testing::internal::GetCapturedStdout();
EXPECT_TRUE(capturedStdout.empty());
helper.reset(); // Delete helper. Destructor saves data to output
EXPECT_EQ(1U, numOutputs);
EXPECT_EQ(printMsg.length(), lenOutputs[0]);
EXPECT_STREQ("stdout.log", nameOutputs[0]);
std::string stdoutStr = std::string(reinterpret_cast<const char *>(outputs[0]),
static_cast<size_t>(lenOutputs[0]));
EXPECT_STREQ(printMsg.data(), stdoutStr.c_str());
delete[] nameOutputs[0];
delete[] outputs[0];
delete[] nameOutputs;
delete[] outputs;
delete[] lenOutputs;
}
TEST(OclocArgHelperTest, GivenNoOutputPrintMessages) {
auto helper = WhiteBoxOclocArgHelper(0, nullptr, nullptr, nullptr,
0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr);
EXPECT_FALSE(helper.messagePrinter.isSuppressed());
ConstStringRef printMsg = "Hello world!";
testing::internal::CaptureStdout();
helper.printf(printMsg.data());
std::string capturedStdout = testing::internal::GetCapturedStdout();
EXPECT_STREQ(printMsg.data(), capturedStdout.c_str());
}
} // namespace NEO } // namespace NEO

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2021 Intel Corporation * Copyright (C) 2018-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -50,6 +50,8 @@ class MessagePrinter {
return ss; return ss;
} }
bool isSuppressed() const { return suppressMessages; }
private: private:
template <typename... Args> template <typename... Args>
std::string stringFormat(const std::string &format, Args... args) { std::string stringFormat(const std::string &format, Args... args) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2021 Intel Corporation * Copyright (C) 2020-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -48,13 +48,14 @@ OclocArgHelper::OclocArgHelper(const uint32_t numSources, const uint8_t **dataSo
uint32_t *numOutputs, uint8_t ***dataOutputs, uint32_t *numOutputs, uint8_t ***dataOutputs,
uint64_t **lenOutputs, char ***nameOutputs) uint64_t **lenOutputs, char ***nameOutputs)
: numOutputs(numOutputs), nameOutputs(nameOutputs), : numOutputs(numOutputs), nameOutputs(nameOutputs),
dataOutputs(dataOutputs), lenOutputs(lenOutputs), hasOutput(numOutputs != nullptr), deviceProductTable({ dataOutputs(dataOutputs), lenOutputs(lenOutputs), hasOutput(numOutputs != nullptr),
messagePrinter(hasOutput), deviceProductTable({
#define NAMEDDEVICE(devId, product, ignored_gtType, ignored_devName) {devId, NEO::hardwarePrefix[NEO::product::hwInfo.platform.eProductFamily]}, #define NAMEDDEVICE(devId, product, ignored_gtType, ignored_devName) {devId, NEO::hardwarePrefix[NEO::product::hwInfo.platform.eProductFamily]},
#define DEVICE(devId, product, ignored_gtType) {devId, NEO::hardwarePrefix[NEO::product::hwInfo.platform.eProductFamily]}, #define DEVICE(devId, product, ignored_gtType) {devId, NEO::hardwarePrefix[NEO::product::hwInfo.platform.eProductFamily]},
#include "devices.inl" #include "devices.inl"
#undef DEVICE #undef DEVICE
#undef NAMEDDEVICE #undef NAMEDDEVICE
{0u, std::string("")}}), {0u, std::string("")}}),
deviceMap({ deviceMap({
#define DEVICE_CONFIG_REVISION(product, productConfig, revision_id) {product, &NEO::productConfig::hwInfo, NEO::productConfig::setupHardwareInfo, revision_id}, #define DEVICE_CONFIG_REVISION(product, productConfig, revision_id) {product, &NEO::productConfig::hwInfo, NEO::productConfig::setupHardwareInfo, revision_id},
#define DEVICE_CONFIG(product, productConfig) {product, &NEO::productConfig::hwInfo, NEO::productConfig::setupHardwareInfo, NEO::productConfig::hwInfo.platform.usRevId}, #define DEVICE_CONFIG(product, productConfig) {product, &NEO::productConfig::hwInfo, NEO::productConfig::setupHardwareInfo, NEO::productConfig::hwInfo.platform.usRevId},

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2021 Intel Corporation * Copyright (C) 2020-2022 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -66,13 +66,13 @@ class OclocArgHelper {
uint8_t ***dataOutputs = nullptr; uint8_t ***dataOutputs = nullptr;
uint64_t **lenOutputs = nullptr; uint64_t **lenOutputs = nullptr;
bool hasOutput = false; bool hasOutput = false;
MessagePrinter messagePrinter;
const std::vector<DeviceProduct> deviceProductTable; const std::vector<DeviceProduct> deviceProductTable;
std::vector<DeviceMapping> deviceMap; std::vector<DeviceMapping> deviceMap;
DeviceMapping deviceForFatbinary; DeviceMapping deviceForFatbinary;
std::map<std::string, unsigned int> genIGFXMap; std::map<std::string, unsigned int> genIGFXMap;
bool fatBinary = false; bool fatBinary = false;
void moveOutputs(); void moveOutputs();
MessagePrinter messagePrinter;
Source *findSourceFile(const std::string &filename); Source *findSourceFile(const std::string &filename);
bool sourceFileExists(const std::string &filename) const; bool sourceFileExists(const std::string &filename) const;