File: cl_compiler_interface_tests.cpp

package info (click to toggle)
intel-compute-runtime 25.48.36300.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,652 kB
  • sloc: cpp: 939,022; lisp: 2,090; sh: 722; makefile: 162; python: 21
file content (94 lines) | stat: -rw-r--r-- 4,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2021-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/compiler_interface/compiler_cache.h"
#include "shared/source/helpers/file_io.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/gtest_helpers.h"
#include "shared/test/common/helpers/test_files.h"
#include "shared/test/common/libult/global_environment.h"
#include "shared/test/common/mocks/mock_compiler_interface.h"
#include "shared/test/common/test_macros/test.h"

#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"

using namespace NEO;

class ClCompilerInterfaceTestMockedBinaryFilesTest : public ClDeviceFixture,
                                                     public ::testing::Test {
  public:
    void SetUp() override {
        ClDeviceFixture::setUp();

        // create the compiler interface
        this->pCompilerInterface = new MockCompilerInterface();
        bool initRet = pCompilerInterface->initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), true);
        ASSERT_TRUE(initRet);
        pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(pCompilerInterface);

        inputArgs.src = ArrayRef<const char>(sSource.c_str(), sSource.size() + 1);
        inputArgs.internalOptions = ArrayRef<const char>(pClDevice->peekCompilerExtensions().c_str(), pClDevice->peekCompilerExtensions().size());

        igcDebugVars.binaryToReturn = fakeBinFile;
        igcDebugVars.binaryToReturnSize = sizeof(fakeBinFile);
        igcDebugVars.debugDataToReturn = fakeBinFile;
        igcDebugVars.debugDataToReturnSize = sizeof(fakeBinFile);
        gEnvironment->igcPushDebugVars(igcDebugVars);

        fclDebugVars.binaryToReturn = fakeBinFile;
        fclDebugVars.binaryToReturnSize = sizeof(fakeBinFile);
        fclDebugVars.debugDataToReturn = fakeBinFile;
        fclDebugVars.debugDataToReturnSize = sizeof(fakeBinFile);
        gEnvironment->fclPushDebugVars(fclDebugVars);
    }

    void TearDown() override {
        gEnvironment->fclPopDebugVars();
        gEnvironment->igcPopDebugVars();
        ClDeviceFixture::tearDown();
    }

    MockCompilerInterface *pCompilerInterface;
    TranslationInput inputArgs = {IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
    std::string sSource = "some_kernel(){}";

    DebugManagerStateRestore dbgRestore;
    MockCompilerDebugVars igcDebugVars;
    MockCompilerDebugVars fclDebugVars;
    char fakeBinFile[1] = {8};

    FORBID_REAL_FILE_SYSTEM_CALLS();
};

TEST_F(ClCompilerInterfaceTestMockedBinaryFilesTest, WhenBuildIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
    CompilerCacheConfig config = {};
    config.enabled = false;
    auto tempCompilerCache = std::make_unique<CompilerCache>(config);
    pCompilerInterface->cache.reset(tempCompilerCache.release());
    std::string receivedInternalOptions;

    fclDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
    gEnvironment->fclPushDebugVars(fclDebugVars);
    TranslationOutput translationOutput = {};
    auto err = pCompilerInterface->build(*pDevice, inputArgs, translationOutput);
    EXPECT_EQ(TranslationOutput::ErrorCode::success, err);
    EXPECT_TRUE(hasSubstr(receivedInternalOptions, pClDevice->peekCompilerExtensions()));
    gEnvironment->fclPopDebugVars();
}

TEST_F(ClCompilerInterfaceTestMockedBinaryFilesTest, WhenCompileIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
    std::string receivedInternalOptions;

    fclDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
    gEnvironment->fclPushDebugVars(fclDebugVars);
    TranslationOutput translationOutput = {};
    auto err = pCompilerInterface->compile(*pDevice, inputArgs, translationOutput);
    EXPECT_EQ(TranslationOutput::ErrorCode::success, err);
    EXPECT_TRUE(hasSubstr(receivedInternalOptions, pClDevice->peekCompilerExtensions()));
    gEnvironment->fclPopDebugVars();
}