Skip to content

Commit 86b1332

Browse files
Print ocloc cmdline after compilation fail
Related-To: NEO-4784 Change-Id: I451d6e0a67fc185d610e5d2dd4ff6a3f6542ca4c Signed-off-by: Konstanty Misiak <[email protected]>
1 parent dcf708f commit 86b1332

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

opencl/test/unit_test/offline_compiler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set(IGDRCL_SRCS_offline_compiler_tests
5151
${CMAKE_CURRENT_SOURCE_DIR}/decoder/encoder_tests.cpp
5252
${CMAKE_CURRENT_SOURCE_DIR}/environment.h
5353
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
54+
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_api_tests.cpp
5455
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_fatbinary_tests.cpp
5556
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_fatbinary_tests.h
5657
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_validator_tests.cpp
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/offline_compiler/source/ocloc_api.h"
9+
#include "shared/offline_compiler/source/offline_compiler.h"
10+
11+
#include "environment.h"
12+
#include "gtest/gtest.h"
13+
14+
#include <string>
15+
16+
extern Environment *gEnvironment;
17+
18+
using namespace std::string_literals;
19+
20+
TEST(OclocApiTests, WhenGoodArgsAreGivenThenSuccessIsReturned) {
21+
const char *argv[] = {
22+
"ocloc",
23+
"-file",
24+
"test_files/copybuffer.cl",
25+
"-device",
26+
gEnvironment->devicePrefix.c_str()};
27+
unsigned int argc = sizeof(argv) / sizeof(const char *);
28+
29+
testing::internal::CaptureStdout();
30+
int retVal = oclocInvoke(argc, argv,
31+
0, nullptr, nullptr, nullptr,
32+
0, nullptr, nullptr, nullptr,
33+
nullptr, nullptr, nullptr, nullptr);
34+
std::string output = testing::internal::GetCapturedStdout();
35+
36+
EXPECT_EQ(retVal, NEO::SUCCESS);
37+
EXPECT_EQ(std::string::npos, output.find("Command was: ocloc -file test_files/copybuffer.cl -device "s + argv[4]));
38+
}
39+
40+
TEST(OclocApiTests, WhenArgsWithMissingFileAreGivenThenErrorMessageIsProduced) {
41+
const char *argv[] = {
42+
"ocloc",
43+
"-file",
44+
"test_files/IDoNotExist.cl",
45+
"-device",
46+
gEnvironment->devicePrefix.c_str()};
47+
unsigned int argc = sizeof(argv) / sizeof(const char *);
48+
49+
testing::internal::CaptureStdout();
50+
int retVal = oclocInvoke(argc, argv,
51+
0, nullptr, nullptr, nullptr,
52+
0, nullptr, nullptr, nullptr,
53+
nullptr, nullptr, nullptr, nullptr);
54+
std::string output = testing::internal::GetCapturedStdout();
55+
56+
EXPECT_EQ(retVal, NEO::INVALID_FILE);
57+
EXPECT_NE(std::string::npos, output.find("Command was: ocloc -file test_files/IDoNotExist.cl -device "s + argv[4]));
58+
}

shared/offline_compiler/source/ocloc_api.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ Default command (when none provided) is 'compile'.
5858
)===";
5959

6060
extern "C" {
61+
void printOclocCmdLine(unsigned int numArgs, const char *argv[], std::unique_ptr<OclocArgHelper> &helper) {
62+
helper->printf("Command was:");
63+
for (auto i = 0u; i < numArgs; ++i)
64+
helper->printf(" %s", argv[i]);
65+
helper->printf("\n");
66+
}
67+
6168
int oclocInvoke(unsigned int numArgs, const char *argv[],
6269
const uint32_t numSources, const uint8_t **dataSources, const uint64_t *lenSources, const char **nameSources,
6370
const uint32_t numInputHeaders, const uint8_t **dataInputHeaders, const uint64_t *lenInputHeaders, const char **nameInputHeaders,
@@ -118,14 +125,20 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
118125
helper->printf("Build failed with error code: %d\n", retVal);
119126
}
120127
}
128+
129+
if (retVal != ErrorCode::SUCCESS)
130+
printOclocCmdLine(numArgs, argv, helper);
131+
121132
return retVal;
122133
}
123134
} catch (const std::exception &e) {
124135
helper->printf("%s\n", e.what());
136+
printOclocCmdLine(numArgs, argv, helper);
125137
return -1;
126138
}
127139
return -1;
128140
}
141+
129142
int oclocFreeOutput(uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs) {
130143
for (uint32_t i = 0; i < *numOutputs; i++) {
131144
delete[](*dataOutputs)[i];

0 commit comments

Comments
 (0)