Ocloc return success when returning help

Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
Krystian Chmielewski
2021-08-06 14:44:04 +00:00
committed by Compute-Runtime-Automation
parent 5cc970a503
commit 73264c65d4
9 changed files with 85 additions and 36 deletions

View File

@@ -272,3 +272,37 @@ __kernel void k(){
EXPECT_EQ(sourcesLen[0], sourceSection->data.size());
EXPECT_STREQ(headerB, reinterpret_cast<const char *>(headerBSection->data.begin()));
}
TEST(OclocApiTests, GivenHelpParameterWhenDecodingThenHelpMsgIsPrintedAndSuccessIsReturned) {
const char *argv[] = {
"ocloc",
"disasm",
"--help"};
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_FALSE(output.empty());
EXPECT_EQ(retVal, NEO::OfflineCompiler::ErrorCode::SUCCESS);
}
TEST(OclocApiTests, GivenHelpParameterWhenEncodingThenHelpMsgIsPrintedAndSuccessIsReturned) {
const char *argv[] = {
"ocloc",
"asm",
"--help"};
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_FALSE(output.empty());
EXPECT_EQ(retVal, NEO::OfflineCompiler::ErrorCode::SUCCESS);
}

View File

@@ -583,9 +583,8 @@ TEST_F(OfflineCompilerTests, GivenHelpOptionThenBuildDoesNotOccur) {
testing::internal::CaptureStdout();
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, true, retVal, oclocArgHelperWithoutInput.get());
std::string output = testing::internal::GetCapturedStdout();
EXPECT_EQ(nullptr, pOfflineCompiler);
EXPECT_STRNE("", output.c_str());
EXPECT_EQ(OfflineCompiler::ErrorCode::PRINT_USAGE, retVal);
EXPECT_EQ(OfflineCompiler::ErrorCode::SUCCESS, retVal);
delete pOfflineCompiler;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -503,11 +503,6 @@ uint32_t BinaryDecoder::readStructFields(const std::vector<std::string> &patchLi
}
int BinaryDecoder::validateInput(const std::vector<std::string> &args) {
if (args[args.size() - 1] == "-help") {
printHelp();
return -1;
}
for (size_t argIndex = 2; argIndex < args.size(); ++argIndex) {
const auto &currArg = args[argIndex];
const bool hasMoreArgs = (argIndex + 1 < args.size());
@@ -521,6 +516,9 @@ int BinaryDecoder::validateInput(const std::vector<std::string> &args) {
} else if ("-dump" == currArg && hasMoreArgs) {
pathToDump = args[++argIndex];
addSlash(pathToDump);
} else if ("--help" == currArg) {
showHelp = true;
return 0;
} else if ("-ignore_isa_padding" == currArg) {
ignoreIsaPadding = true;
} else if ("-q" == currArg) {
@@ -528,13 +526,11 @@ int BinaryDecoder::validateInput(const std::vector<std::string> &args) {
iga->setMessagePrinter(argHelper->getPrinterRef());
} else {
argHelper->printf("Unknown argument %s\n", currArg.c_str());
printHelp();
return -1;
}
}
if (binaryFile.find(".bin") == std::string::npos) {
argHelper->printf(".bin extension is expected for binary file.\n");
printHelp();
return -1;
}
if (false == iga->isKnownPlatform()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -40,6 +40,9 @@ class BinaryDecoder {
int decode();
int validateInput(const std::vector<std::string> &args);
bool showHelp = false;
void printHelp();
protected:
OclocArgHelper *argHelper = nullptr;
bool ignoreIsaPadding = false;
@@ -54,7 +57,6 @@ class BinaryDecoder {
const void *getDevBinary();
std::vector<std::string> loadPatchList();
void parseTokens();
void printHelp();
int processBinary(const void *&ptr, std::ostream &ptmFile);
void processKernel(const void *&ptr, std::ostream &ptmFile);
void readPatchTokens(const void *&patchListPtr, uint32_t patchListSize, std::ostream &ptmFile);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -305,11 +305,6 @@ int BinaryEncoder::processKernel(size_t &line, const std::vector<std::string> &p
}
int BinaryEncoder::validateInput(const std::vector<std::string> &args) {
if ("-help" == args[args.size() - 1]) {
printHelp();
return -1;
}
for (size_t argIndex = 2; argIndex < args.size(); ++argIndex) {
const auto &currArg = args[argIndex];
const bool hasMoreArgs = (argIndex + 1 < args.size());
@@ -320,6 +315,9 @@ int BinaryEncoder::validateInput(const std::vector<std::string> &args) {
iga->setProductFamily(getProductFamilyFromDeviceName(args[++argIndex]));
} else if ("-out" == currArg && hasMoreArgs) {
elfName = args[++argIndex];
} else if ("--help" == currArg) {
showHelp = true;
return 0;
} else if ("-ignore_isa_padding" == currArg) {
ignoreIsaPadding = true;
} else if ("-q" == currArg) {
@@ -327,7 +325,6 @@ int BinaryEncoder::validateInput(const std::vector<std::string> &args) {
iga->setMessagePrinter(argHelper->getPrinterRef());
} else {
argHelper->printf("Unknown argument %s\n", currArg.c_str());
printHelp();
return -1;
}
}
@@ -340,7 +337,6 @@ int BinaryEncoder::validateInput(const std::vector<std::string> &args) {
}
if (elfName.find(".bin") == std::string::npos) {
argHelper->printf(".bin extension is expected for binary file.\n");
printHelp();
return -1;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -25,18 +25,21 @@ class BinaryEncoder {
int encode();
int validateInput(const std::vector<std::string> &args);
bool showHelp = false;
void printHelp();
protected:
OclocArgHelper *argHelper = nullptr;
bool ignoreIsaPadding = false;
std::string pathToDump, elfName;
std::unique_ptr<IgaWrapper> iga;
void calculatePatchListSizes(std::vector<std::string> &ptmFile);
MOCKABLE_VIRTUAL bool copyBinaryToBinary(const std::string &srcFileName, std::ostream &outBinary, uint32_t *binaryLength);
bool copyBinaryToBinary(const std::string &srcFileName, std::ostream &outBinary) {
return copyBinaryToBinary(srcFileName, outBinary, nullptr);
}
int createElf(std::stringstream &deviceBinary);
void printHelp();
int processBinary(const std::vector<std::string> &ptmFile, std::ostream &deviceBinary);
int processKernel(size_t &i, const std::vector<std::string> &ptmFileLines, std::ostream &deviceBinary);
template <typename T>

View File

@@ -89,6 +89,12 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
} else if (numArgs > 1 && ConstStringRef("disasm") == allArgs[1]) {
BinaryDecoder disasm(helper.get());
int retVal = disasm.validateInput(allArgs);
if (disasm.showHelp) {
disasm.printHelp();
return retVal;
}
if (retVal == 0) {
return disasm.decode();
} else {
@@ -97,6 +103,12 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
} else if (numArgs > 1 && ConstStringRef("asm") == allArgs[1]) {
BinaryEncoder assembler(helper.get());
int retVal = assembler.validateInput(allArgs);
if (assembler.showHelp) {
assembler.printHelp();
return retVal;
}
if (retVal == 0) {
return assembler.encode();
} else {

View File

@@ -391,7 +391,10 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
size_t sourceFromFileSize = 0;
this->pBuildInfo = std::make_unique<buildInfo>();
retVal = parseCommandLine(numArgs, allArgs);
if (retVal != SUCCESS) {
if (showHelp) {
printUsage();
return retVal;
} else if (retVal != SUCCESS) {
return retVal;
}
@@ -622,8 +625,8 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
bool compile64 = false;
if (numArgs < 2) {
printUsage();
retVal = PRINT_USAGE;
showHelp = true;
return INVALID_COMMAND_LINE;
}
for (uint32_t argIndex = 1; argIndex < numArgs; argIndex++) {
@@ -679,8 +682,8 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
} else if ("-output_no_suffix" == currArg) {
outputNoSuffix = true;
} else if ("--help" == currArg) {
printUsage();
retVal = PRINT_USAGE;
showHelp = true;
return SUCCESS;
} else if (("-revision_id" == currArg) && hasMoreArgs) {
revisionId = std::stoi(argv[argIndex + 1], nullptr, 0);
argIndex++;
@@ -694,13 +697,17 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
if (retVal == SUCCESS) {
if (compile32 && compile64) {
argHelper->printf("Error: Cannot compile for 32-bit and 64-bit, please choose one.\n");
retVal = INVALID_COMMAND_LINE;
} else if (inputFile.empty()) {
argHelper->printf("Error: Input file name missing.\n");
retVal = INVALID_COMMAND_LINE;
} else if (deviceName.empty() && (false == onlySpirV)) {
retVal |= INVALID_COMMAND_LINE;
}
if (deviceName.empty() && (false == onlySpirV)) {
argHelper->printf("Error: Device name missing.\n");
retVal = INVALID_COMMAND_LINE;
}
if (inputFile.empty()) {
argHelper->printf("Error: Input file name missing.\n");
retVal = INVALID_COMMAND_LINE;
} else if (!argHelper->fileExists(inputFile)) {
argHelper->printf("Error: Input file %s missing.\n", inputFile.c_str());
retVal = INVALID_FILE;
@@ -895,7 +902,7 @@ Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename
as defined by compilers used underneath.
Check intel-graphics-compiler (IGC) project
for details on available internal options.
You also may provide explicit -help to inquire
You also may provide explicit --help to inquire
information about option, mentioned in -options
-llvm_text Forces intermediate representation (IR) format

View File

@@ -41,7 +41,6 @@ class OfflineCompiler {
INVALID_PROGRAM = -44,
INVALID_COMMAND_LINE = -5150,
INVALID_FILE = -5151,
PRINT_USAGE = -5152,
};
static int query(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper);
@@ -126,8 +125,8 @@ class OfflineCompiler {
std::string internalOptions;
std::string sourceCode;
std::string buildLog;
bool dumpFiles = true;
bool dumpFiles = true;
bool useLlvmText = false;
bool useLlvmBc = false;
bool useCppFile = false;
@@ -138,13 +137,14 @@ class OfflineCompiler {
bool inputFileSpirV = false;
bool outputNoSuffix = false;
bool forceStatelessToStatefulOptimization = false;
bool isSpirV = false;
bool showHelp = false;
std::vector<uint8_t> elfBinary;
char *genBinary = nullptr;
size_t genBinarySize = 0;
char *irBinary = nullptr;
size_t irBinarySize = 0;
bool isSpirV = false;
char *debugDataBinary = nullptr;
size_t debugDataBinarySize = 0;
struct buildInfo;