Improve code coverage of OfflineCompiler class

This change introduces unit tests related to
member functions of OfflineCompiler class.
OfflineCompiler::initialize() is not covered
and it will be added in a separate commit.

Related-To: NEO-6834
Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
Patryk Wrobel
2022-04-04 16:09:41 +00:00
committed by Compute-Runtime-Automation
parent db9c0d1103
commit 76349b8030
6 changed files with 340 additions and 2 deletions

View File

@@ -1143,10 +1143,10 @@ void OfflineCompiler::writeOutAllFiles() {
dirList.push_back(tmp);
pos = tmp.find_last_of("/\\", pos);
tmp = tmp.substr(0, pos);
} while (pos != std::string::npos);
} while (pos != std::string::npos && !tmp.empty());
while (!dirList.empty()) {
MakeDirectory(dirList.back().c_str());
createDir(dirList.back());
dirList.pop_back();
}
}
@@ -1192,6 +1192,10 @@ void OfflineCompiler::writeOutAllFiles() {
}
}
void OfflineCompiler::createDir(const std::string &path) {
MakeDirectory(path.c_str());
}
bool OfflineCompiler::readOptionsFromFile(std::string &options, const std::string &file, OclocArgHelper *helper) {
if (!helper->fileExists(file)) {
return false;

View File

@@ -114,6 +114,7 @@ class OfflineCompiler {
return suffix;
}
MOCKABLE_VIRTUAL void writeOutAllFiles();
MOCKABLE_VIRTUAL void createDir(const std::string &path);
void unifyExcludeIrFlags();
HardwareInfo hwInfo;
@@ -167,4 +168,5 @@ class OfflineCompiler {
OclocArgHelper *argHelper = nullptr;
};
} // namespace NEO

View File

@@ -493,6 +493,10 @@ CIF::ICIF *MockIgcOclDeviceCtx::Create(CIF::InterfaceId_t intId, CIF::Version_t
IGC::IgcOclTranslationCtxBase *MockIgcOclDeviceCtx::CreateTranslationCtxImpl(CIF::Version_t ver,
IGC::CodeType::CodeType_t inType,
IGC::CodeType::CodeType_t outType) {
if (igcDebugVars->shouldFailCreationOfTranslationContext) {
return nullptr;
}
requestedTranslationCtxs.emplace_back(inType, outType);
return new MockIgcOclTranslationCtx;
}
@@ -662,6 +666,11 @@ CIF::ICIF *MockFclOclDeviceCtx::Create(CIF::InterfaceId_t intId, CIF::Version_t
IGC::FclOclTranslationCtxBase *MockFclOclDeviceCtx::CreateTranslationCtxImpl(CIF::Version_t ver,
IGC::CodeType::CodeType_t inType,
IGC::CodeType::CodeType_t outType) {
if (fclDebugVars->shouldFailCreationOfTranslationContext) {
return nullptr;
}
requestedTranslationCtxs.emplace_back(inType, outType);
return new MockFclOclTranslationCtx;
}
@@ -669,6 +678,15 @@ IGC::FclOclTranslationCtxBase *MockFclOclDeviceCtx::CreateTranslationCtxImpl(CIF
IGC::CodeType::CodeType_t inType,
IGC::CodeType::CodeType_t outType,
CIF::Builtins::BufferSimple *err) {
if (!fclDebugVars->translationContextCreationError.empty() && err) {
err->PushBackRawBytes(fclDebugVars->translationContextCreationError.c_str(), fclDebugVars->translationContextCreationError.size());
}
if (fclDebugVars->shouldFailCreationOfTranslationContext) {
return nullptr;
}
requestedTranslationCtxs.emplace_back(inType, outType);
return new MockFclOclTranslationCtx;
}

View File

@@ -26,6 +26,7 @@ struct MockCompilerDebugVars {
bindless
};
bool shouldReturnInvalidTranslationOutput = false;
bool shouldFailCreationOfTranslationContext = false;
bool forceBuildFailure = false;
bool forceCreateFailure = false;
bool forceRegisterFail = false;
@@ -45,6 +46,7 @@ struct MockCompilerDebugVars {
std::string *receivedInput = nullptr;
std::string fileName;
std::string translationContextCreationError;
};
struct MockCompilerEnableGuard {
@@ -287,6 +289,9 @@ struct MockFclOclDeviceCtx : MockCIF<IGC::FclOclDeviceCtxTagOCL> {
uint32_t oclApiVersion = 120;
MockCIFPlatform *platform = nullptr;
using TranslationOpT = std::pair<IGC::CodeType::CodeType_t, IGC::CodeType::CodeType_t>;
std::vector<TranslationOpT> requestedTranslationCtxs;
};
} // namespace NEO