Skip to content

Commit e42fc39

Browse files
agrubbaCompute-Runtime-Automation
authored andcommitted
test: refactor: Mock filesystem in ults 4/n
Related-To: NEO-15069 Signed-off-by: Arek G <arkadiusz.grubba@intel.com>
1 parent 21e8313 commit e42fc39

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

opencl/test/unit_test/compiler_interface/cl_compiler_interface_tests.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "shared/source/compiler_interface/compiler_cache.h"
99
#include "shared/source/helpers/file_io.h"
10+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1011
#include "shared/test/common/helpers/gtest_helpers.h"
1112
#include "shared/test/common/helpers/test_files.h"
1213
#include "shared/test/common/libult/global_environment.h"
@@ -18,11 +19,10 @@
1819

1920
using namespace NEO;
2021

21-
class ClCompilerInterfaceTest : public ClDeviceFixture,
22-
public ::testing::Test {
22+
class ClCompilerInterfaceTestMockedBinaryFilesTest : public ClDeviceFixture,
23+
public ::testing::Test {
2324
public:
2425
void SetUp() override {
25-
USE_REAL_FILE_SYSTEM();
2626
ClDeviceFixture::setUp();
2727

2828
// create the compiler interface
@@ -31,58 +31,59 @@ class ClCompilerInterfaceTest : public ClDeviceFixture,
3131
ASSERT_TRUE(initRet);
3232
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(pCompilerInterface);
3333

34-
std::string testFile;
35-
36-
testFile.append(clFiles);
37-
testFile.append("CopyBuffer_simd16.cl");
38-
39-
pSource = loadDataFromFile(
40-
testFile.c_str(),
41-
sourceSize);
42-
43-
ASSERT_NE(0u, sourceSize);
44-
ASSERT_NE(nullptr, pSource);
45-
46-
inputArgs.src = ArrayRef<char>(pSource.get(), sourceSize);
34+
inputArgs.src = ArrayRef<const char>(sSource.c_str(), sSource.size() + 1);
4735
inputArgs.internalOptions = ArrayRef<const char>(pClDevice->peekCompilerExtensions().c_str(), pClDevice->peekCompilerExtensions().size());
36+
37+
igcDebugVars.binaryToReturn = fakeBinFile;
38+
igcDebugVars.binaryToReturnSize = sizeof(fakeBinFile);
39+
igcDebugVars.debugDataToReturn = fakeBinFile;
40+
igcDebugVars.debugDataToReturnSize = sizeof(fakeBinFile);
41+
gEnvironment->igcPushDebugVars(igcDebugVars);
42+
43+
fclDebugVars.binaryToReturn = fakeBinFile;
44+
fclDebugVars.binaryToReturnSize = sizeof(fakeBinFile);
45+
fclDebugVars.debugDataToReturn = fakeBinFile;
46+
fclDebugVars.debugDataToReturnSize = sizeof(fakeBinFile);
47+
gEnvironment->fclPushDebugVars(fclDebugVars);
4848
}
4949

5050
void TearDown() override {
51-
pSource.reset();
52-
51+
gEnvironment->fclPopDebugVars();
52+
gEnvironment->igcPopDebugVars();
5353
ClDeviceFixture::tearDown();
5454
}
5555

5656
MockCompilerInterface *pCompilerInterface;
5757
TranslationInput inputArgs = {IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
58-
std::unique_ptr<char[]> pSource = nullptr;
59-
size_t sourceSize = 0;
58+
std::string sSource = "some_kernel(){}";
59+
60+
DebugManagerStateRestore dbgRestore;
61+
MockCompilerDebugVars igcDebugVars;
62+
MockCompilerDebugVars fclDebugVars;
63+
char fakeBinFile[1] = {8};
64+
65+
FORBID_REAL_FILE_SYSTEM_CALLS();
6066
};
6167

62-
TEST_F(ClCompilerInterfaceTest, WhenBuildIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
63-
USE_REAL_FILE_SYSTEM();
68+
TEST_F(ClCompilerInterfaceTestMockedBinaryFilesTest, WhenBuildIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
6469
CompilerCacheConfig config = {};
6570
config.enabled = false;
6671
auto tempCompilerCache = std::make_unique<CompilerCache>(config);
6772
pCompilerInterface->cache.reset(tempCompilerCache.release());
6873
std::string receivedInternalOptions;
6974

70-
auto debugVars = NEO::getFclDebugVars();
71-
debugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
72-
gEnvironment->fclPushDebugVars(debugVars);
75+
fclDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
76+
gEnvironment->fclPushDebugVars(fclDebugVars);
7377
TranslationOutput translationOutput = {};
7478
auto err = pCompilerInterface->build(*pDevice, inputArgs, translationOutput);
7579
EXPECT_EQ(TranslationOutput::ErrorCode::success, err);
7680
EXPECT_TRUE(hasSubstr(receivedInternalOptions, pClDevice->peekCompilerExtensions()));
7781
gEnvironment->fclPopDebugVars();
7882
}
7983

80-
TEST_F(ClCompilerInterfaceTest, WhenCompileIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
81-
USE_REAL_FILE_SYSTEM();
84+
TEST_F(ClCompilerInterfaceTestMockedBinaryFilesTest, WhenCompileIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
8285
std::string receivedInternalOptions;
8386

84-
MockCompilerDebugVars fclDebugVars;
85-
retrieveBinaryKernelFilename(fclDebugVars.fileName, "CopyBuffer_simd16_", ".spv");
8687
fclDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
8788
gEnvironment->fclPushDebugVars(fclDebugVars);
8889
TranslationOutput translationOutput = {};

0 commit comments

Comments
 (0)