Skip to content

Commit f0a9533

Browse files
Improve error reporting in ocloc
Related-To: NEO-6425 Signed-off-by: Warchulski, Jaroslaw <[email protected]>
1 parent 0606e8d commit f0a9533

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,33 @@ TEST(OclocApiTests, givenInvalidOclocOptionsFileWhenCmdlineIsPrintedThenTheyAreP
413413
EXPECT_FALSE(output.find("Building with ocloc options:") != std::string::npos);
414414
}
415415

416+
TEST(OclocApiTests, givenInvalidOclocOptionsFileWhenCmdlineIsPrintedThenTheyAreNotPrinted) {
417+
ASSERT_TRUE(fileExists(clFiles + "valid_kernel.cl"));
418+
ASSERT_TRUE(fileExists(clFiles + "valid_kernel_ocloc_options.txt"));
419+
std::string clFileName(clFiles + "valid_kernel.cl");
420+
421+
const char *argv[] = {
422+
"ocloc",
423+
"-qq",
424+
"-file",
425+
clFileName.c_str(),
426+
"-device",
427+
gEnvironment->devicePrefix.c_str()};
428+
unsigned int argc = sizeof(argv) / sizeof(const char *);
429+
430+
testing::internal::CaptureStdout();
431+
int retVal = oclocInvoke(argc, argv,
432+
0, nullptr, nullptr, nullptr,
433+
0, nullptr, nullptr, nullptr,
434+
nullptr, nullptr, nullptr, nullptr);
435+
std::string output = testing::internal::GetCapturedStdout();
436+
EXPECT_NE(retVal, NEO::OclocErrorCode::SUCCESS);
437+
438+
EXPECT_FALSE(output.find("Failed with ocloc options from file:\n"
439+
"-invalid_ocloc_option") != std::string::npos);
440+
EXPECT_FALSE(output.find("Building with ocloc options:") != std::string::npos);
441+
}
442+
416443
TEST(OclocApiTests, GivenIncludeHeadersWhenCompilingThenPassesToFclHeadersPackedAsElf) {
417444
auto prevFclDebugVars = NEO::getFclDebugVars();
418445
auto debugVars = prevFclDebugVars;

shared/offline_compiler/source/offline_compiler.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,16 +562,16 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
562562
std::string oclocOptionsFromFile;
563563
bool oclocOptionsRead = readOptionsFromFile(oclocOptionsFromFile, oclocOptionsFileName, argHelper);
564564
if (oclocOptionsRead) {
565-
argHelper->printf("Building with ocloc options:\n%s\n", oclocOptionsFromFile.c_str());
565+
if (!isQuiet()) {
566+
argHelper->printf("Building with ocloc options:\n%s\n", oclocOptionsFromFile.c_str());
567+
}
566568
std::istringstream iss(allArgs[0] + " " + oclocOptionsFromFile);
567569
std::vector<std::string> tokens{
568570
std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}};
569571

570572
retVal = parseCommandLine(tokens.size(), tokens);
571573
if (retVal != SUCCESS) {
572-
if (isQuiet()) {
573-
printf("Failed with ocloc options from file:\n%s\n", oclocOptionsFromFile.c_str());
574-
}
574+
argHelper->printf("Failed with ocloc options from file:\n%s\n", oclocOptionsFromFile.c_str());
575575
return retVal;
576576
}
577577
}
@@ -732,6 +732,8 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
732732
cacheDir = argv[argIndex + 1];
733733
argIndex++;
734734
} else if ("-q" == currArg) {
735+
quiet = true;
736+
} else if ("-qq" == currArg) {
735737
argHelper->getPrinterRef() = MessagePrinter(true);
736738
quiet = true;
737739
} else if ("-spv_only" == currArg) {
@@ -1008,7 +1010,9 @@ Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename
10081010
-force_stos_opt Will forcibly enable stateless to stateful optimization,
10091011
i.e. skip "-cl-intel-greater-than-4GB-buffer-required".
10101012
1011-
-q Will silence most of output messages.
1013+
-q Will silence output messages (except errors).
1014+
1015+
-qq Will silence most of output messages.
10121016
10131017
-spv_only Will generate only spirV file.
10141018

0 commit comments

Comments
 (0)