Ocloc - emit warning on input type mismatch

Change-Id: I57edcbd3025616698dbe7710f04d975db93ffdb9
This commit is contained in:
Jaroslaw Chodor
2020-11-02 16:24:48 +01:00
committed by sys_ocldev
parent d181a2e5a3
commit 78dc305291
4 changed files with 109 additions and 1 deletions

View File

@ -14,6 +14,7 @@ namespace NEO {
class MockOfflineCompiler : public OfflineCompiler {
public:
using OfflineCompiler::argHelper;
using OfflineCompiler::deviceName;
using OfflineCompiler::elfBinary;
using OfflineCompiler::fclDeviceCtx;
@ -73,6 +74,11 @@ class MockOfflineCompiler : public OfflineCompiler {
OfflineCompiler::writeOutAllFiles();
}
void clearLog() {
uniqueHelper = std::make_unique<OclocArgHelper>();
argHelper = uniqueHelper.get();
}
int buildSourceCodeStatus = 0;
bool overrideBuildSourceCodeStatus = false;
uint32_t generateElfBinaryCalled = 0u;

View File

@ -7,6 +7,7 @@
#include "offline_compiler_tests.h"
#include "shared/source/compiler_interface/intermediate_representations.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/file_io.h"
#include "shared/source/helpers/hw_info.h"
@ -1287,4 +1288,74 @@ INSTANTIATE_TEST_CASE_P(
OfflineCompilerTestWithParams,
testing::ValuesIn(workaroundApplicableForDeviceArray));
TEST(OclocCompile, whenDetectedPotentialInputTypeMismatchThenEmitsWarning) {
std::string sourceOclC = "__kernel void k() { }";
std::string sourceLlvmBc = NEO::llvmBcMagic.str();
std::string sourceSpirv = NEO::spirvMagic.str();
std::string sourceSpirvInv = NEO::spirvMagicInv.str();
std::string notSpirvWarning = "Warning : file does not look like spirv bitcode (wrong magic numbers)";
std::string notLlvmBcWarning = "Warning : file does not look like llvm bitcode (wrong magic numbers)";
std::string isSpirvWarning = "Warning : file looks like spirv bitcode (based on magic numbers) - please make sure proper CLI flags are present";
std::string isLlvmBcWarning = "Warning : file looks like llvm bitcode (based on magic numbers) - please make sure proper CLI flags are present";
std::string allWarnings[] = {notSpirvWarning, notLlvmBcWarning, isLlvmBcWarning, isSpirvWarning};
struct Case {
std::string input;
bool isSpirv;
bool isLlvm;
std::string expectedWarning;
};
Case cases[] = {
{sourceOclC, false, false, ""},
{sourceOclC, true, false, notSpirvWarning},
{sourceOclC, false, true, notLlvmBcWarning},
{sourceLlvmBc, false, false, isLlvmBcWarning},
{sourceLlvmBc, true, false, notSpirvWarning},
{sourceLlvmBc, false, true, ""},
{sourceSpirv, false, false, isSpirvWarning},
{sourceSpirv, true, false, ""},
{sourceSpirv, false, true, notLlvmBcWarning},
{sourceSpirvInv, false, false, isSpirvWarning},
{sourceSpirvInv, true, false, ""},
{sourceSpirvInv, false, true, notLlvmBcWarning},
};
MockOfflineCompiler ocloc;
std::vector<std::string> argv = {
"ocloc",
"-q",
"-file",
"test_files/copybuffer.cl",
"-device",
gEnvironment->devicePrefix.c_str()};
ocloc.getHardwareInfo(gEnvironment->devicePrefix.c_str());
int retVal = ocloc.initialize(argv.size(), argv);
ASSERT_EQ(0, retVal);
int caseNum = 0;
for (auto &c : cases) {
ocloc.sourceCode = c.input;
ocloc.inputFileLlvm = c.isLlvm;
ocloc.inputFileSpirV = c.isSpirv;
ocloc.build();
auto log = ocloc.argHelper->getPrinterRef().getLog().str();
ocloc.clearLog();
if (c.expectedWarning.empty()) {
for (auto &w : allWarnings) {
EXPECT_THAT(log.c_str(), testing::Not(testing::HasSubstr(w.c_str()))) << " Case : " << caseNum;
}
} else {
EXPECT_THAT(log.c_str(), testing::HasSubstr(c.expectedWarning.c_str())) << " Case : " << caseNum;
}
caseNum++;
}
}
} // namespace NEO