Fix for '-q' option in ocloc

Related-To: NEO-6425
Signed-off-by: Warchulski, Jaroslaw <jaroslaw.warchulski@intel.com>
This commit is contained in:
Warchulski, Jaroslaw
2022-11-25 11:26:12 +00:00
committed by Compute-Runtime-Automation
parent 083471a158
commit bf6dfa6b94
2 changed files with 45 additions and 8 deletions

View File

@@ -1430,7 +1430,7 @@ TEST(OclocFatBinaryHelpersTest, givenNonEmptyBuildLogWhenBuildingFatbinaryForTar
MockOfflineCompiler mockOfflineCompiler{};
mockOfflineCompiler.initialize(argv.size(), argv);
const char buildWarning[] = "Warning: This is a build log!";
const char buildWarning[] = "warning: This is a build log!";
mockOfflineCompiler.updateBuildLog(buildWarning, sizeof(buildWarning));
mockOfflineCompiler.buildReturnValue = OclocErrorCode::SUCCESS;
@@ -1454,6 +1454,39 @@ TEST(OclocFatBinaryHelpersTest, givenNonEmptyBuildLogWhenBuildingFatbinaryForTar
EXPECT_EQ(expectedOutput, output);
}
TEST(OclocFatBinaryHelpersTest, givenNonEmptyBuildLogWhenBuildingFatbinaryForTargetThenBuildLogIsNotPrinted) {
::testing::internal::CaptureStdout();
const std::vector<std::string> argv = {
"ocloc",
"-q",
"-file",
clFiles + "copybuffer.cl",
"-device",
gEnvironment->devicePrefix.c_str()};
MockOfflineCompiler mockOfflineCompiler{};
mockOfflineCompiler.initialize(argv.size(), argv);
const auto mockArgHelper = mockOfflineCompiler.uniqueHelper.get();
const auto deviceConfig = getDeviceConfig(mockOfflineCompiler, mockArgHelper);
const char buildWarning[] = "Warning: this is a build log!";
mockOfflineCompiler.updateBuildLog(buildWarning, sizeof(buildWarning));
mockOfflineCompiler.buildReturnValue = OclocErrorCode::SUCCESS;
mockOfflineCompiler.elfBinary = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Ar::ArEncoder ar;
const std::string pointerSize{"32"};
const int previousReturnValue{OclocErrorCode::SUCCESS};
buildFatBinaryForTarget(previousReturnValue, argv, pointerSize, ar, &mockOfflineCompiler, mockArgHelper, deviceConfig);
const auto output{::testing::internal::GetCapturedStdout()};
EXPECT_TRUE(output.empty()) << output;
}
TEST(OclocFatBinaryHelpersTest, givenQuietModeWhenBuildingFatbinaryForTargetThenNothingIsPrinted) {
using namespace std::string_literals;

View File

@@ -406,13 +406,17 @@ int OfflineCompiler::build() {
}
void OfflineCompiler::updateBuildLog(const char *pErrorString, const size_t errorStringSize) {
std::string errorString = (errorStringSize && pErrorString) ? std::string(pErrorString, pErrorString + errorStringSize) : "";
if (errorString[0] != '\0') {
if (buildLog.empty()) {
buildLog.assign(errorString.c_str());
} else {
buildLog.append("\n");
buildLog.append(errorString.c_str());
if (pErrorString != nullptr) {
std::string log(pErrorString, pErrorString + errorStringSize);
ConstStringRef errorString(log);
const bool warningFound = errorString.containsCaseInsensitive("warning");
if (!isQuiet() || !warningFound) {
if (buildLog.empty()) {
buildLog.assign(errorString.data());
} else {
buildLog.append("\n");
buildLog.append(errorString.data());
}
}
}
}