File: mock_execution_environment.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (94 lines) | stat: -rw-r--r-- 3,651 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) 2022-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/test/common/mocks/mock_execution_environment.h"

#include "shared/source/built_ins/built_ins.h"
#include "shared/test/common/fixtures/mock_aub_center_fixture.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/helpers/unit_test_helper.h"

#include "gtest/gtest.h"

namespace NEO {
extern bool useMockGmm;

void MockRootDeviceEnvironment::initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) {
    if (!initAubCenterCalled) {
        initAubCenterCalled = true;
        localMemoryEnabledReceived = localMemoryEnabled;
        aubFileNameReceived = aubFileName;
    }
    if (useMockAubCenter) {
        MockAubCenterFixture::setMockAubCenter(*this);
    }
    RootDeviceEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType);
}
bool MockRootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) {
    initOsInterfaceCalled++;
    if (!initOsInterfaceResults.empty()) {
        auto retVal = initOsInterfaceResults[initOsInterfaceCalled - 1];
        if (retVal) {
            RootDeviceEnvironment::initOsInterface(std::move(hwDeviceId), rootDeviceIndex);
        }
        return retVal;
    }
    return RootDeviceEnvironment::initOsInterface(std::move(hwDeviceId), rootDeviceIndex);
}
bool MockRootDeviceEnvironment::initAilConfiguration() {
    if (ailInitializationResult.has_value()) {
        return *ailInitializationResult;
    } else {
        return RootDeviceEnvironment::initAilConfiguration();
    }
}

MockRootDeviceEnvironment::~MockRootDeviceEnvironment() {
    if (initOsInterfaceExpectedCallCount) {
        EXPECT_EQ(*initOsInterfaceExpectedCallCount, initOsInterfaceCalled);
    }
}

void MockRootDeviceEnvironment::resetBuiltins(RootDeviceEnvironment *rootDeviceEnvironment, BuiltIns *newValue) {
    if (rootDeviceEnvironment->builtins) {
        rootDeviceEnvironment->builtins->freeSipKernels(rootDeviceEnvironment->executionEnvironment.memoryManager.get());
    }
    rootDeviceEnvironment->builtins.reset(newValue);
}

MockExecutionEnvironment::MockExecutionEnvironment() : MockExecutionEnvironment(defaultHwInfo.get()) {}
MockExecutionEnvironment::MockExecutionEnvironment(const HardwareInfo *hwInfo) : MockExecutionEnvironment(hwInfo, true, 1u) {
}
MockExecutionEnvironment::MockExecutionEnvironment(const HardwareInfo *hwInfo, bool useMockAubCenter, uint32_t numRootDevices) {
    prepareRootDeviceEnvironments(numRootDevices);
    for (auto rootDeviceIndex = 0u; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
        auto rootDeviceEnvironment = new MockRootDeviceEnvironment(*this);
        rootDeviceEnvironment->useMockAubCenter = useMockAubCenter;
        rootDeviceEnvironments[rootDeviceIndex].reset(rootDeviceEnvironment);

        if (hwInfo) {
            rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(hwInfo);
        } else {
            rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(defaultHwInfo.get());
        }
        if (useMockGmm) {
            rootDeviceEnvironments[rootDeviceIndex]->initGmm();
        }

        UnitTestSetter::setRcsExposure(*rootDeviceEnvironments[rootDeviceIndex]);
        UnitTestSetter::setCcsExposure(*rootDeviceEnvironments[rootDeviceIndex]);
    }

    calculateMaxOsContextCount();
}
void MockExecutionEnvironment::initGmm() {
    for (auto &rootDeviceEnvironment : rootDeviceEnvironments) {
        rootDeviceEnvironment->initGmm();
    }
}

} // namespace NEO