Print ocloc cmdline after compilation fail

Related-To: NEO-4784

Change-Id: I451d6e0a67fc185d610e5d2dd4ff6a3f6542ca4c
Signed-off-by: Konstanty Misiak <konstanty.misiak@intel.com>
This commit is contained in:
Konstanty Misiak
2020-08-26 12:53:38 +02:00
committed by sys_ocldev
parent dcf708f2d2
commit 86b133207f
3 changed files with 72 additions and 0 deletions

View File

@ -51,6 +51,7 @@ set(IGDRCL_SRCS_offline_compiler_tests
${CMAKE_CURRENT_SOURCE_DIR}/decoder/encoder_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/environment.h
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_api_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_fatbinary_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_fatbinary_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/ocloc_validator_tests.cpp

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/offline_compiler.h"
#include "environment.h"
#include "gtest/gtest.h"
#include <string>
extern Environment *gEnvironment;
using namespace std::string_literals;
TEST(OclocApiTests, WhenGoodArgsAreGivenThenSuccessIsReturned) {
const char *argv[] = {
"ocloc",
"-file",
"test_files/copybuffer.cl",
"-device",
gEnvironment->devicePrefix.c_str()};
unsigned int argc = sizeof(argv) / sizeof(const char *);
testing::internal::CaptureStdout();
int retVal = oclocInvoke(argc, argv,
0, nullptr, nullptr, nullptr,
0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr);
std::string output = testing::internal::GetCapturedStdout();
EXPECT_EQ(retVal, NEO::SUCCESS);
EXPECT_EQ(std::string::npos, output.find("Command was: ocloc -file test_files/copybuffer.cl -device "s + argv[4]));
}
TEST(OclocApiTests, WhenArgsWithMissingFileAreGivenThenErrorMessageIsProduced) {
const char *argv[] = {
"ocloc",
"-file",
"test_files/IDoNotExist.cl",
"-device",
gEnvironment->devicePrefix.c_str()};
unsigned int argc = sizeof(argv) / sizeof(const char *);
testing::internal::CaptureStdout();
int retVal = oclocInvoke(argc, argv,
0, nullptr, nullptr, nullptr,
0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr);
std::string output = testing::internal::GetCapturedStdout();
EXPECT_EQ(retVal, NEO::INVALID_FILE);
EXPECT_NE(std::string::npos, output.find("Command was: ocloc -file test_files/IDoNotExist.cl -device "s + argv[4]));
}

View File

@ -58,6 +58,13 @@ Examples:
)===";
extern "C" {
void printOclocCmdLine(unsigned int numArgs, const char *argv[], std::unique_ptr<OclocArgHelper> &helper) {
helper->printf("Command was:");
for (auto i = 0u; i < numArgs; ++i)
helper->printf(" %s", argv[i]);
helper->printf("\n");
}
int oclocInvoke(unsigned int numArgs, const char *argv[],
const uint32_t numSources, const uint8_t **dataSources, const uint64_t *lenSources, const char **nameSources,
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[],
helper->printf("Build failed with error code: %d\n", retVal);
}
}
if (retVal != ErrorCode::SUCCESS)
printOclocCmdLine(numArgs, argv, helper);
return retVal;
}
} catch (const std::exception &e) {
helper->printf("%s\n", e.what());
printOclocCmdLine(numArgs, argv, helper);
return -1;
}
return -1;
}
int oclocFreeOutput(uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs) {
for (uint32_t i = 0; i < *numOutputs; i++) {
delete[](*dataOutputs)[i];