mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
refactor: Mock file system in ULTs
Functions: fileExists and loadDataToFile use IO functions from namespace IoFunctions Now tests that use these functions are mocked by default, but some still require access to real files and have been restored the ability to read files. They will be mocked in next PRs. Related-To: NEO-7006 Signed-off-by: Marcel Skierkowski <marcel.skierkowski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
077fe1ab48
commit
5d01677454
@@ -11,6 +11,7 @@
|
||||
#include "shared/source/compiler_interface/intermediate_representations.h"
|
||||
#include "shared/source/helpers/aligned_memory.h"
|
||||
#include "shared/source/helpers/array_count.h"
|
||||
#include "shared/source/helpers/file_io.h"
|
||||
#include "shared/source/helpers/hash.h"
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
@@ -372,6 +373,7 @@ TEST(CompilerCacheTests, GivenEmptyBinaryWhenCachingThenBinaryIsNotCached) {
|
||||
}
|
||||
|
||||
TEST(CompilerCacheTests, GivenNonExistantConfigWhenLoadingFromCacheThenNullIsReturned) {
|
||||
VariableBackup<decltype(NEO::IoFunctions::fopenPtr)> mockFopen(&NEO::IoFunctions::fopenPtr, [](const char *filename, const char *mode) -> FILE * { return NULL; });
|
||||
CompilerCache cache(CompilerCacheConfig{});
|
||||
size_t size;
|
||||
auto ret = cache.loadCachedBinary("----do-not-exists----", size);
|
||||
@@ -409,6 +411,8 @@ TEST(CompilerInterfaceCachedTests, GivenNoCachedBinaryWhenBuildingThenErrorIsRet
|
||||
}
|
||||
|
||||
TEST(CompilerInterfaceCachedTests, GivenCachedBinaryWhenBuildingThenSuccessIsReturned) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
|
||||
auto src = "#include \"header.h\"\n__kernel k() {}";
|
||||
@@ -635,6 +639,8 @@ TEST_F(CompilerInterfaceOclElfCacheTest, givenNonEmptyTranslationOutputWhenProce
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceOclElfCacheTest, GivenKernelWithIncludesWhenBuildingThenPackBinaryOnCacheSaveAndUnpackBinaryOnLoadFromCache) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
gEnvironment->igcPushDebugVars(igcDebugVarsDeviceBinary);
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
@@ -669,6 +675,8 @@ TEST_F(CompilerInterfaceOclElfCacheTest, GivenKernelWithIncludesWhenBuildingThen
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceOclElfCacheTest, GivenKernelWithIncludesWhenLoadedCacheDoesNotUnpackCorrectlyThenDoNotEndInCacheAndContinueCompilation) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
gEnvironment->igcPushDebugVars(igcDebugVarsInvalidDeviceBinary);
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
@@ -700,6 +708,8 @@ TEST_F(CompilerInterfaceOclElfCacheTest, GivenKernelWithIncludesWhenLoadedCacheD
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceOclElfCacheTest, GivenKernelWithIncludesAndDebugDataWhenBuildingThenPackBinaryOnCacheSaveAndUnpackBinaryOnLoadFromCache) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
gEnvironment->igcPushDebugVars(igcDebugVarsDeviceBinaryDebugData);
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
@@ -734,6 +744,8 @@ TEST_F(CompilerInterfaceOclElfCacheTest, GivenKernelWithIncludesAndDebugDataWhen
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceOclElfCacheTest, GivenBinaryWhenBuildingThenPackBinaryOnCacheSaveAndUnpackBinaryOnLoadFromCache) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
gEnvironment->igcPushDebugVars(igcDebugVarsDeviceBinary);
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
@@ -768,6 +780,8 @@ TEST_F(CompilerInterfaceOclElfCacheTest, GivenBinaryWhenBuildingThenPackBinaryOn
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceOclElfCacheTest, GivenBinaryWhenLoadedCacheDoesNotUnpackCorrectlyThenDoNotEndInCacheAndContinueCompilation) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
gEnvironment->igcPushDebugVars(igcDebugVarsInvalidDeviceBinary);
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
@@ -796,6 +810,8 @@ TEST_F(CompilerInterfaceOclElfCacheTest, GivenBinaryWhenLoadedCacheDoesNotUnpack
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceOclElfCacheTest, GivenBinaryAndDebugDataWhenBuildingThenPackBinaryOnCacheSaveAndUnpackBinaryOnLoadFromCache) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
gEnvironment->igcPushDebugVars(igcDebugVarsDeviceBinaryDebugData);
|
||||
|
||||
TranslationInput inputArgs{IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
|
||||
@@ -967,4 +983,4 @@ TEST_F(CompilerCacheHelperMockedWhitelistedIncludesTests, GivenEnabledCacheAndNo
|
||||
EXPECT_EQ(CachingMode::preProcess, CompilerCacheHelper::getCachingMode(&cache, testCase.second, sourceRef))
|
||||
<< "Failed for source: " << testCase.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class CompilerInterfaceTest : public DeviceFixture,
|
||||
public:
|
||||
void SetUp() override {
|
||||
DeviceFixture::setUp();
|
||||
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
// create the compiler interface
|
||||
this->pCompilerInterface = new MockCompilerInterface();
|
||||
bool initRet = pCompilerInterface->initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), true);
|
||||
@@ -152,12 +152,16 @@ TEST(CompilerInterfaceCreateInstance, WhenInitializeFailedThenReturnNull) {
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, WhenCompilingToIsaThenSuccessIsReturned) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
TranslationOutput translationOutput;
|
||||
auto err = pCompilerInterface->build(*pDevice, inputArgs, translationOutput);
|
||||
EXPECT_EQ(TranslationOutput::ErrorCode::success, err);
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, WhenPreferredIntermediateRepresentationSpecifiedThenPreserveIt) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
CompilerCacheConfig config = {};
|
||||
config.enabled = false;
|
||||
auto tempCompilerCache = std::make_unique<CompilerCache>(config);
|
||||
@@ -191,6 +195,8 @@ TEST_F(CompilerInterfaceTest, whenFclTranslatorReturnsNullptrThenBuildFailsGrace
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, whenIgcTranslatorReturnsNullptrThenBuildFailsGracefully) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
CompilerCacheConfig config = {};
|
||||
config.enabled = false;
|
||||
auto tempCompilerCache = std::make_unique<CompilerCache>(config);
|
||||
@@ -203,6 +209,8 @@ TEST_F(CompilerInterfaceTest, whenIgcTranslatorReturnsNullptrThenBuildFailsGrace
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, GivenOptionsWhenCompilingToIsaThenSuccessIsReturned) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
std::string internalOptions = "SOME_OPTION";
|
||||
|
||||
MockCompilerDebugVars fclDebugVars;
|
||||
@@ -226,6 +234,8 @@ TEST_F(CompilerInterfaceTest, GivenOptionsWhenCompilingToIsaThenSuccessIsReturne
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, WhenCompilingToIrThenSuccessIsReturned) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
MockCompilerDebugVars fclDebugVars;
|
||||
retrieveBinaryKernelFilename(fclDebugVars.fileName, "CopyBufferShared_simd32_", ".spv");
|
||||
gEnvironment->fclPushDebugVars(fclDebugVars);
|
||||
@@ -307,6 +317,8 @@ TEST_F(CompilerInterfaceTest, GivenForceBuildFailureWhenLinkingIrThenLinkFailure
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, WhenLinkIsCalledThenOclGenBinIsTheTranslationTarget) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
// link only from .ll to gen ISA
|
||||
MockCompilerDebugVars igcDebugVars;
|
||||
retrieveBinaryKernelFilename(igcDebugVars.fileName, "CopyBufferShared_simd32_", ".spv");
|
||||
@@ -375,6 +387,8 @@ TEST_F(CompilerInterfaceTest, GivenForceBuildFailureWhenCreatingLibraryThenLinkF
|
||||
}
|
||||
|
||||
TEST_F(CompilerInterfaceTest, WhenCreateLibraryIsCalledThenLlvmBcIsUsedAsIntermediateRepresentation) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
// create library from .ll to IR
|
||||
MockCompilerDebugVars igcDebugVars;
|
||||
retrieveBinaryKernelFilename(igcDebugVars.fileName, "CopyBufferShared_simd32_", ".spv");
|
||||
@@ -741,6 +755,8 @@ struct WasLockedListener {
|
||||
};
|
||||
|
||||
TEST_F(CompilerInterfaceTest, givenUpdatedSpecConstValuesWhenBuildProgramThenProperValuesArePassed) {
|
||||
USE_REAL_FILE_SYSTEM();
|
||||
|
||||
struct MockTranslationContextSpecConst : public MockIgcOclTranslationCtx {
|
||||
IGC::OclTranslationOutputBase *TranslateImpl(
|
||||
CIF::Version_t outVersion,
|
||||
@@ -1478,4 +1494,4 @@ TEST(getOclCExtensionVersion, whenCheckingVersionOfUntrackedExtensionThenReturns
|
||||
cl_version defaultVer = CL_MAKE_VERSION(7, 2, 5);
|
||||
cl_version ver = NEO::getOclCExtensionVersion("other", defaultVer);
|
||||
EXPECT_EQ(defaultVer, ver);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user