From 76349b8030c20225e56a39fb1e0fbdc3f6f5ef2e Mon Sep 17 00:00:00 2001 From: Patryk Wrobel Date: Mon, 4 Apr 2022 16:09:41 +0000 Subject: [PATCH] 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 --- .../mock/mock_offline_compiler.h | 13 + .../offline_compiler_tests.cpp | 296 ++++++++++++++++++ .../source/offline_compiler.cpp | 8 +- .../source/offline_compiler.h | 2 + shared/test/common/mocks/mock_compilers.cpp | 18 ++ shared/test/common/mocks/mock_compilers.h | 5 + 6 files changed, 340 insertions(+), 2 deletions(-) diff --git a/opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h b/opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h index 483ab7b64c..d2264a679f 100644 --- a/opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h +++ b/opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h @@ -20,6 +20,7 @@ class MockOfflineCompiler : public OfflineCompiler { public: using OfflineCompiler::appendExtraInternalOptions; using OfflineCompiler::argHelper; + using OfflineCompiler::buildIrBinary; using OfflineCompiler::deviceName; using OfflineCompiler::elfBinary; using OfflineCompiler::excludeIr; @@ -33,6 +34,7 @@ class MockOfflineCompiler : public OfflineCompiler { using OfflineCompiler::hwInfo; using OfflineCompiler::igcDeviceCtx; using OfflineCompiler::initHardwareInfo; + using OfflineCompiler::inputFile; using OfflineCompiler::inputFileLlvm; using OfflineCompiler::inputFileSpirV; using OfflineCompiler::internalOptions; @@ -42,6 +44,7 @@ class MockOfflineCompiler : public OfflineCompiler { using OfflineCompiler::options; using OfflineCompiler::outputDirectory; using OfflineCompiler::outputFile; + using OfflineCompiler::outputNoSuffix; using OfflineCompiler::parseCommandLine; using OfflineCompiler::parseDebugSettings; using OfflineCompiler::setStatelessToStatefullBufferOffsetFlag; @@ -101,6 +104,14 @@ class MockOfflineCompiler : public OfflineCompiler { argHelper = uniqueHelper.get(); } + void createDir(const std::string &path) override { + if (interceptCreatedDirs) { + createdDirs.push_back(path); + } else { + OfflineCompiler::createDir(path); + } + } + std::map filesMap{}; int buildSourceCodeStatus = 0; bool overrideBuildSourceCodeStatus = false; @@ -109,6 +120,8 @@ class MockOfflineCompiler : public OfflineCompiler { std::unique_ptr uniqueHelper; int buildCalledCount{0}; std::optional buildReturnValue{}; + bool interceptCreatedDirs{false}; + std::vector createdDirs{}; }; } // namespace NEO diff --git a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp index 6829ac55f6..9500b93ba2 100644 --- a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -913,6 +914,28 @@ TEST_F(OfflineCompilerTests, givenExcludeIrArgumentWhenInitIsPerformedThenIrExcl EXPECT_TRUE(excludeIrFromZebinEnabled); } +TEST_F(OfflineCompilerTests, givenExcludeIrArgumentAndExcludeIrFromZebinInternalOptionWhenInitIsPerformedThenExcludeIrFromZebinInternalOptionOccursJustOnce) { + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-exclude_ir", + "-internal_options", + "-ze-allow-zebin -ze-exclude-ir-from-zebin", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + mockOfflineCompiler.initialize(argv.size(), argv); + + const auto expectedInternalOption{"-ze-exclude-ir-from-zebin"}; + const auto firstExcludeIrFromZebin{mockOfflineCompiler.internalOptions.find(expectedInternalOption)}; + ASSERT_NE(std::string::npos, firstExcludeIrFromZebin); + + const auto lastExcludeIrFromZebin{mockOfflineCompiler.internalOptions.rfind(expectedInternalOption)}; + EXPECT_EQ(firstExcludeIrFromZebin, lastExcludeIrFromZebin); +} + TEST_F(OfflineCompilerTests, givenExcludeIrArgumentWhenCompilingKernelThenIrShouldBeExcluded) { std::vector argv = { "ocloc", @@ -962,6 +985,140 @@ TEST_F(OfflineCompilerTests, givenLackOfExcludeIrArgumentWhenCompilingKernelThen EXPECT_TRUE(isAnyIrSectionDefined(elf.sectionHeaders)); } +TEST_F(OfflineCompilerTests, givenZeroSizeInputFileWhenInitializationIsPerformedThenInvalidFileIsReturned) { + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + mockOfflineCompiler.uniqueHelper->callBaseLoadDataFromFile = false; + mockOfflineCompiler.uniqueHelper->shouldLoadDataFromFileReturnZeroSize = true; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + EXPECT_EQ(OclocErrorCode::INVALID_FILE, initResult); +} + +TEST_F(OfflineCompilerTests, givenInvalidIgcOutputWhenCompilingKernelThenOutOfHostMemoryIsReturned) { + MockCompilerDebugVars igcDebugVars{gEnvironment->igcDebugVars}; + igcDebugVars.shouldReturnInvalidTranslationOutput = true; + NEO::setIgcDebugVars(igcDebugVars); + + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + EXPECT_EQ(OclocErrorCode::SUCCESS, initResult); + + const auto buildResult{mockOfflineCompiler.build()}; + EXPECT_EQ(OclocErrorCode::OUT_OF_HOST_MEMORY, buildResult); + + NEO::setIgcDebugVars(gEnvironment->igcDebugVars); +} + +TEST_F(OfflineCompilerTests, givenIgcBuildFailureWhenCompilingKernelThenBuildProgramFailureIsReturned) { + MockCompilerDebugVars igcDebugVars{gEnvironment->igcDebugVars}; + igcDebugVars.forceBuildFailure = true; + NEO::setIgcDebugVars(igcDebugVars); + + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + EXPECT_EQ(OclocErrorCode::SUCCESS, initResult); + + const auto buildResult{mockOfflineCompiler.build()}; + EXPECT_EQ(OclocErrorCode::BUILD_PROGRAM_FAILURE, buildResult); + + NEO::setIgcDebugVars(gEnvironment->igcDebugVars); +} + +TEST_F(OfflineCompilerTests, givenInvalidFclOutputWhenCompilingKernelThenOutOfHostMemoryIsReturned) { + MockCompilerDebugVars fclDebugVars{gEnvironment->fclDebugVars}; + fclDebugVars.shouldReturnInvalidTranslationOutput = true; + NEO::setFclDebugVars(fclDebugVars); + + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + EXPECT_EQ(OclocErrorCode::SUCCESS, initResult); + + const auto buildResult{mockOfflineCompiler.build()}; + EXPECT_EQ(OclocErrorCode::OUT_OF_HOST_MEMORY, buildResult); + + NEO::setFclDebugVars(gEnvironment->fclDebugVars); +} + +TEST_F(OfflineCompilerTests, givenFclTranslationContextCreationFailureWhenCompilingKernelThenOutOfHostMemoryIsReturned) { + MockCompilerDebugVars fclDebugVars{gEnvironment->fclDebugVars}; + fclDebugVars.shouldFailCreationOfTranslationContext = true; + NEO::setFclDebugVars(fclDebugVars); + + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + EXPECT_EQ(OclocErrorCode::SUCCESS, initResult); + + const auto buildResult{mockOfflineCompiler.build()}; + EXPECT_EQ(OclocErrorCode::OUT_OF_HOST_MEMORY, buildResult); + + NEO::setFclDebugVars(gEnvironment->fclDebugVars); +} + +TEST_F(OfflineCompilerTests, givenFclTranslationContextCreationFailureAndErrorMessageWhenCompilingKernelThenProgramBuildFailureIsReturnedAndBuildLogIsUpdated) { + MockCompilerDebugVars fclDebugVars{gEnvironment->fclDebugVars}; + fclDebugVars.shouldFailCreationOfTranslationContext = true; + fclDebugVars.translationContextCreationError = "Error: Could not create context!"; + NEO::setFclDebugVars(fclDebugVars); + + std::vector argv = { + "ocloc", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + MockOfflineCompiler mockOfflineCompiler{}; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + EXPECT_EQ(OclocErrorCode::SUCCESS, initResult); + + const auto buildResult{mockOfflineCompiler.build()}; + EXPECT_EQ(OclocErrorCode::BUILD_PROGRAM_FAILURE, buildResult); + + EXPECT_EQ("Error: Could not create context!", mockOfflineCompiler.getBuildLog()); + + NEO::setFclDebugVars(gEnvironment->fclDebugVars); +} + TEST_F(OfflineCompilerTests, givenVariousClStdValuesWhenCompilingSourceThenCorrectExtensionsArePassed) { std::string clStdOptionValues[] = {"", "-cl-std=CL1.2", "-cl-std=CL2.0", "-cl-std=CL3.0"}; @@ -1498,6 +1655,17 @@ TEST(OfflineCompilerTest, givenErrorStringsWithExtraNullCharactersWhenUpdatingBu EXPECT_EQ(mockOfflineCompiler->getBuildLog(), expectedBuildLogString); } +TEST(OfflineCompilerTest, givenValidSizeAndInvalidLogPointerWhenUpdatingBuildLogThenNothingIsWritten) { + MockOfflineCompiler mockOfflineCompiler{}; + + const char *const invalidLog{nullptr}; + const size_t logSize{7}; + mockOfflineCompiler.updateBuildLog(invalidLog, logSize); + + const auto buildLog = mockOfflineCompiler.getBuildLog(); + EXPECT_TRUE(buildLog.empty()) << buildLog; +} + TEST(OfflineCompilerTest, GivenSourceCodeWhenBuildingThenSuccessIsReturned) { auto mockOfflineCompiler = std::unique_ptr(new MockOfflineCompiler()); ASSERT_NE(nullptr, mockOfflineCompiler); @@ -1603,6 +1771,99 @@ TEST(OfflineCompilerTest, WhenGeneratingElfBinaryThenBinaryIsCreated) { EXPECT_FALSE(mockOfflineCompiler->elfBinary.empty()); } +TEST(OfflineCompilerTest, givenInvalidGenBinarySizeAndNotNullPointerWhenGeneratingElfBinaryThenNothingHappensAndFalseIsReturned) { + MockOfflineCompiler mockOfflineCompiler; + + // Destructor of OfflineCompiler will deallocate the memory. + mockOfflineCompiler.genBinary = new char[0]; + mockOfflineCompiler.genBinarySize = 0; + + EXPECT_FALSE(mockOfflineCompiler.generateElfBinary()); + EXPECT_TRUE(mockOfflineCompiler.elfBinary.empty()); +} + +TEST(OfflineCompilerTest, givenNonEmptyOptionsWhenGeneratingElfBinaryThenOptionsSectionIsIncludedInElfAndTrueIsReturned) { + MockOfflineCompiler mockOfflineCompiler; + mockOfflineCompiler.options = "-some_option"; + + // Destructor of OfflineCompiler will deallocate the memory. + mockOfflineCompiler.genBinary = new char[8]{}; + mockOfflineCompiler.genBinarySize = 8; + + EXPECT_TRUE(mockOfflineCompiler.generateElfBinary()); + ASSERT_FALSE(mockOfflineCompiler.elfBinary.empty()); + + std::string errorReason{}; + std::string warning{}; + + const auto elf{Elf::decodeElf(mockOfflineCompiler.elfBinary, errorReason, warning)}; + ASSERT_TRUE(errorReason.empty()); + ASSERT_TRUE(warning.empty()); + + const auto isOptionsSection = [](const auto §ion) { + return section.header && section.header->type == Elf::SHT_OPENCL_OPTIONS; + }; + + const auto isAnyOptionsSectionDefined = std::any_of(elf.sectionHeaders.begin(), elf.sectionHeaders.end(), isOptionsSection); + EXPECT_TRUE(isAnyOptionsSectionDefined); +} + +TEST(OfflineCompilerTest, givenOutputNoSuffixFlagAndNonEmptyOutputFileNameAndNonEmptyElfContentWhenWritingOutAllFilesThenFileWithCorrectNameIsWritten) { + MockOfflineCompiler mockOfflineCompiler{}; + mockOfflineCompiler.uniqueHelper->interceptOutput = true; + + mockOfflineCompiler.outputNoSuffix = true; + mockOfflineCompiler.outputFile = "some_output_filename"; + mockOfflineCompiler.elfBinary = {49, 50, 51, 52, 53, 54, 55, 56}; // ASCII codes of "12345678" + + mockOfflineCompiler.writeOutAllFiles(); + + const auto outputFileIt = mockOfflineCompiler.uniqueHelper->interceptedFiles.find("some_output_filename"); + ASSERT_NE(mockOfflineCompiler.uniqueHelper->interceptedFiles.end(), outputFileIt); + + EXPECT_EQ("12345678", outputFileIt->second); +} + +TEST(OfflineCompilerTest, givenInputFileNameAndOutputNoSuffixFlagAndEmptyOutputFileNameAndNonEmptyElfContentWhenWritingOutAllFilesThenFileWithTruncatedInputNameIsWritten) { + MockOfflineCompiler mockOfflineCompiler{}; + mockOfflineCompiler.uniqueHelper->interceptOutput = true; + + mockOfflineCompiler.outputNoSuffix = true; + mockOfflineCompiler.inputFile = "/home/important_file.spv"; + mockOfflineCompiler.elfBinary = {49, 50, 51, 52, 53, 54, 55, 56}; // ASCII codes of "12345678" + + mockOfflineCompiler.writeOutAllFiles(); + + const auto outputFileIt = mockOfflineCompiler.uniqueHelper->interceptedFiles.find("important_file"); + ASSERT_NE(mockOfflineCompiler.uniqueHelper->interceptedFiles.end(), outputFileIt); + + EXPECT_EQ("12345678", outputFileIt->second); +} + +TEST(OfflineCompilerTest, givenNonEmptyOutputDirectoryWhenWritingOutAllFilesTheDirectoriesAreCreatedAndFileIsWrittenToIt) { + MockOfflineCompiler mockOfflineCompiler{}; + mockOfflineCompiler.interceptCreatedDirs = true; + mockOfflineCompiler.uniqueHelper->interceptOutput = true; + + mockOfflineCompiler.outputDirectory = "/home/important/compilation"; + mockOfflineCompiler.outputNoSuffix = true; + mockOfflineCompiler.outputFile = "some_output_filename"; + mockOfflineCompiler.elfBinary = {49, 50, 51, 52, 53, 54, 55, 56}; // ASCII codes of "12345678" + + mockOfflineCompiler.writeOutAllFiles(); + + ASSERT_EQ(3u, mockOfflineCompiler.createdDirs.size()); + + EXPECT_EQ("/home", mockOfflineCompiler.createdDirs[0]); + EXPECT_EQ("/home/important", mockOfflineCompiler.createdDirs[1]); + EXPECT_EQ("/home/important/compilation", mockOfflineCompiler.createdDirs[2]); + + const auto outputFileIt = mockOfflineCompiler.uniqueHelper->interceptedFiles.find("/home/important/compilation/some_output_filename"); + ASSERT_NE(mockOfflineCompiler.uniqueHelper->interceptedFiles.end(), outputFileIt); + + EXPECT_EQ("12345678", outputFileIt->second); +} + TEST(OfflineCompilerTest, givenLlvmInputOptionPassedWhenCmdLineParsedThenInputFileLlvmIsSetTrue) { std::vector argv = { "ocloc", @@ -1685,6 +1946,31 @@ TEST(OfflineCompilerTest, givenIntermediateRepresentationInputWhenBuildSourceCod testing::internal::GetCapturedStdout(); } +TEST(OfflineCompilerTest, givenUseLlvmBcFlagWhenBuildingIrBinaryThenProperTranslationContextIsUsed) { + MockOfflineCompiler mockOfflineCompiler; + std::vector argv = { + "ocloc", + "-file", + "test_files/emptykernel.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + const auto initResult = mockOfflineCompiler.initialize(argv.size(), argv); + ASSERT_EQ(CL_SUCCESS, initResult); + + auto mockFclOclDeviceCtx = new NEO::MockFclOclDeviceCtx(); + mockOfflineCompiler.fclDeviceCtx = CIF::RAII::Pack(mockFclOclDeviceCtx); + + mockOfflineCompiler.useLlvmBc = true; + const auto buildResult = mockOfflineCompiler.buildIrBinary(); + EXPECT_EQ(CL_SUCCESS, buildResult); + + ASSERT_EQ(1U, mockFclOclDeviceCtx->requestedTranslationCtxs.size()); + + NEO::MockIgcOclDeviceCtx::TranslationOpT expectedTranslation = {IGC::CodeType::oclC, IGC::CodeType::llvmBc}; + EXPECT_EQ(expectedTranslation, mockFclOclDeviceCtx->requestedTranslationCtxs[0]); +} + TEST(OfflineCompilerTest, givenBinaryInputThenDontTruncateSourceAtFirstZero) { std::vector argvLlvm = {"ocloc", "-llvm_input", "-file", "test_files/binary_with_zeroes", "-device", gEnvironment->devicePrefix.c_str()}; @@ -2051,6 +2337,7 @@ TEST(OfflineCompilerTest, givenEnabledOptsSuffixWhenGenerateOptsSuffixIsCalledTh std::string suffix = compiler.generateOptsSuffix(); EXPECT_STREQ("A_B_C", suffix.c_str()); } + TEST(OfflineCompilerTest, givenCompilerWhenBuildSourceCodeFailsThenGenerateElfBinaryAndWriteOutAllFilesAreCalled) { MockOfflineCompiler compiler; compiler.overrideBuildSourceCodeStatus = true; @@ -2169,6 +2456,15 @@ TEST(OfflineCompilerTest, givenNoRevisionIdWhenCompilerIsInitializedThenHwInfoHa EXPECT_EQ(mockOfflineCompiler->hwInfo.platform.usRevId, revId); } +TEST(OfflineCompilerTest, givenEmptyDeviceNameWhenInitializingHardwareInfoThenInvalidDeviceIsReturned) { + MockOfflineCompiler mockOfflineCompiler{}; + + const std::string emptyDeviceName{}; + const auto result = mockOfflineCompiler.initHardwareInfo(emptyDeviceName); + + EXPECT_EQ(OclocErrorCode::INVALID_DEVICE, result); +} + TEST(OfflineCompilerTest, whenDeviceIsSpecifiedThenDefaultConfigFromTheDeviceIsUsed) { auto mockOfflineCompiler = std::unique_ptr(new MockOfflineCompiler()); ASSERT_NE(nullptr, mockOfflineCompiler); diff --git a/shared/offline_compiler/source/offline_compiler.cpp b/shared/offline_compiler/source/offline_compiler.cpp index 354cfe3ae3..62b173084e 100644 --- a/shared/offline_compiler/source/offline_compiler.cpp +++ b/shared/offline_compiler/source/offline_compiler.cpp @@ -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; diff --git a/shared/offline_compiler/source/offline_compiler.h b/shared/offline_compiler/source/offline_compiler.h index 5c1e5f51e8..7a5ac26d4d 100644 --- a/shared/offline_compiler/source/offline_compiler.h +++ b/shared/offline_compiler/source/offline_compiler.h @@ -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 diff --git a/shared/test/common/mocks/mock_compilers.cpp b/shared/test/common/mocks/mock_compilers.cpp index 512655e34c..d6a8ded941 100644 --- a/shared/test/common/mocks/mock_compilers.cpp +++ b/shared/test/common/mocks/mock_compilers.cpp @@ -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; } diff --git a/shared/test/common/mocks/mock_compilers.h b/shared/test/common/mocks/mock_compilers.h index 1e357cb290..b4a3e7e229 100644 --- a/shared/test/common/mocks/mock_compilers.h +++ b/shared/test/common/mocks/mock_compilers.h @@ -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 { uint32_t oclApiVersion = 120; MockCIFPlatform *platform = nullptr; + + using TranslationOpT = std::pair; + std::vector requestedTranslationCtxs; }; } // namespace NEO