Add quotes to options in cmdline printed by ocloc

When ocloc prints the command it was called with, enclose the -options
and -internal_options with quotes.
This allows easier copy-paste of the cmdline.

Related-To: NEO-6002

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek 2021-12-16 17:43:11 +00:00 committed by Compute-Runtime-Automation
parent f4c151cce5
commit b6ec17843d
4 changed files with 69 additions and 2 deletions

View File

@ -15,6 +15,7 @@
#include "gtest/gtest.h"
#include "hw_cmds.h"
#include <algorithm>
#include <string>
extern Environment *gEnvironment;
@ -181,6 +182,58 @@ TEST(OclocApiTests, WhenArgsWithMissingFileAreGivenThenErrorMessageIsProduced) {
EXPECT_NE(std::string::npos, output.find("Command was: ocloc -q -file test_files/IDoNotExist.cl -device "s + argv[5]));
}
TEST(OfflineCompilerTest, givenInputOptionsAndInternalOptionsWhenCmdlineIsPrintedThenBothAreInQuotes) {
const char *argv[] = {
"ocloc",
"-q",
"-file",
"test_files/IDoNotExist.cl",
"-device",
gEnvironment->devicePrefix.c_str(),
"-options", "-D DEBUG -cl-kernel-arg-info", "-internal_options", "-internalOption1 -internal-option-2"};
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_NE(retVal, NEO::OfflineCompiler::ErrorCode::SUCCESS);
EXPECT_TRUE(output.find("Command was: ocloc -q -file test_files/IDoNotExist.cl -device "s +
gEnvironment->devicePrefix.c_str() +
" -options \"-D DEBUG -cl-kernel-arg-info\" -internal_options \"-internalOption1 -internal-option-2\"") != std::string::npos);
size_t quotesCount = std::count(output.begin(), output.end(), '\"');
EXPECT_EQ(quotesCount, 4u);
}
TEST(OfflineCompilerTest, givenInputOptionsCalledOptionsWhenCmdlineIsPrintedThenQuotesAreCorrect) {
const char *argv[] = {
"ocloc",
"-q",
"-file",
"test_files/IDoNotExist.cl",
"-device",
gEnvironment->devicePrefix.c_str(),
"-options", "-options", "-internal_options", "-internalOption"};
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_NE(retVal, NEO::OfflineCompiler::ErrorCode::SUCCESS);
EXPECT_TRUE(output.find("Command was: ocloc -q -file test_files/IDoNotExist.cl -device "s +
gEnvironment->devicePrefix.c_str() +
" -options \"-options\" -internal_options \"-internalOption\"") != std::string::npos);
size_t quotesCount = std::count(output.begin(), output.end(), '\"');
EXPECT_EQ(quotesCount, 4u);
}
TEST(OclocApiTests, GivenIncludeHeadersWhenCompilingThenPassesToFclHeadersPackedAsElf) {
auto prevFclDebugVars = NEO::getFclDebugVars();
auto debugVars = prevFclDebugVars;

View File

@ -64,8 +64,17 @@ Examples:
extern "C" {
void printOclocCmdLine(unsigned int numArgs, const char *argv[], std::unique_ptr<OclocArgHelper> &helper) {
printf("Command was:");
for (auto i = 0u; i < numArgs; ++i)
printf(" %s", argv[i]);
bool useQuotes = false;
for (auto i = 0u; i < numArgs; ++i) {
const char *currArg = argv[i];
if (useQuotes) {
printf(" \"%s\"", currArg);
useQuotes = false;
} else {
printf(" %s", currArg);
useQuotes = helper->areQuotesRequired(currArg);
}
}
printf("\n");
}

View File

@ -346,6 +346,10 @@ unsigned int OclocArgHelper::returnIGFXforGen(const std::string &device) {
return it->second;
}
bool OclocArgHelper::areQuotesRequired(const std::string_view &argName) {
return argName == "-options" || argName == "-internal_options";
}
PRODUCT_CONFIG OclocArgHelper::findConfigMatch(const std::string &device, bool firstAppearance) {
auto numeration = getMajorMinorRevision(device);
if (numeration.empty()) {

View File

@ -147,4 +147,5 @@ class OclocArgHelper {
std::string returnProductNameForDevice(unsigned short deviceId);
bool isGen(const std::string &device);
unsigned int returnIGFXforGen(const std::string &device);
bool areQuotesRequired(const std::string_view &argName);
};