From 0089cb698fc45d5d82fb42f3ff1d2a05fa46628e Mon Sep 17 00:00:00 2001 From: Krystian Chmielewski Date: Tue, 11 Jan 2022 13:03:13 +0000 Subject: [PATCH] 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 --- .../offline_compiler_tests.cpp | 48 +++++++++++++++++++ .../offline_compiler/source/decoder/helper.h | 4 +- .../source/ocloc_arg_helper.cpp | 7 +-- .../source/ocloc_arg_helper.h | 4 +- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp index 0a88e3827c..5a1baf59ac 100644 --- a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp @@ -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(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(outputs[0]), + static_cast(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 diff --git a/shared/offline_compiler/source/decoder/helper.h b/shared/offline_compiler/source/decoder/helper.h index bdad5f2180..2998bbade8 100644 --- a/shared/offline_compiler/source/decoder/helper.h +++ b/shared/offline_compiler/source/decoder/helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -50,6 +50,8 @@ class MessagePrinter { return ss; } + bool isSuppressed() const { return suppressMessages; } + private: template std::string stringFormat(const std::string &format, Args... args) { diff --git a/shared/offline_compiler/source/ocloc_arg_helper.cpp b/shared/offline_compiler/source/ocloc_arg_helper.cpp index d88c5f2eb6..1ac56f44f0 100644 --- a/shared/offline_compiler/source/ocloc_arg_helper.cpp +++ b/shared/offline_compiler/source/ocloc_arg_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -48,13 +48,14 @@ OclocArgHelper::OclocArgHelper(const uint32_t numSources, const uint8_t **dataSo uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***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 DEVICE(devId, product, ignored_gtType) {devId, NEO::hardwarePrefix[NEO::product::hwInfo.platform.eProductFamily]}, #include "devices.inl" #undef DEVICE #undef NAMEDDEVICE - {0u, std::string("")}}), + {0u, std::string("")}}), deviceMap({ #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}, diff --git a/shared/offline_compiler/source/ocloc_arg_helper.h b/shared/offline_compiler/source/ocloc_arg_helper.h index 84188b124a..7290497e7a 100644 --- a/shared/offline_compiler/source/ocloc_arg_helper.h +++ b/shared/offline_compiler/source/ocloc_arg_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -66,13 +66,13 @@ class OclocArgHelper { uint8_t ***dataOutputs = nullptr; uint64_t **lenOutputs = nullptr; bool hasOutput = false; + MessagePrinter messagePrinter; const std::vector deviceProductTable; std::vector deviceMap; DeviceMapping deviceForFatbinary; std::map genIGFXMap; bool fatBinary = false; void moveOutputs(); - MessagePrinter messagePrinter; Source *findSourceFile(const std::string &filename); bool sourceFileExists(const std::string &filename) const;