| 1 |
/* |
| 2 |
* Copyright (C) 2020-2025 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
#include "shared/source/os_interface/linux/engine_info.h" |
| 10 |
#include "shared/source/os_interface/linux/i915.h" |
| 11 |
#include "shared/test/common/libult/linux/drm_mock.h" |
| 12 |
|
| 13 |
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" |
| 14 |
#include "level_zero/tools/source/sysman/engine/engine_imp.h" |
| 15 |
#include "level_zero/tools/source/sysman/engine/linux/os_engine_imp.h" |
| 16 |
#include "level_zero/tools/source/sysman/linux/fs_access.h" |
| 17 |
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" |
| 18 |
#include "level_zero/tools/source/sysman/linux/pmu/pmu_imp.h" |
| 19 |
|
| 20 |
using namespace NEO; |
| 21 |
namespace L0 { |
| 22 |
namespace ult { |
| 23 |
constexpr int64_t mockPmuFd = 10; |
| 24 |
constexpr uint64_t mockTimestamp = 87654321; |
| 25 |
constexpr uint64_t mockActiveTime = 987654321; |
| 26 |
const uint32_t microSecondsToNanoSeconds = 1000u; |
| 27 |
constexpr uint16_t invalidEngineClass = UINT16_MAX; |
| 28 |
const std::string deviceDir("device"); |
| 29 |
struct MockMemoryManagerInEngineSysman : public MemoryManagerMock { |
| 30 |
MockMemoryManagerInEngineSysman(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {} |
| 31 |
}; |
| 32 |
|
| 33 |
struct MockEngineNeoDrm : public Drm { |
| 34 |
using Drm::getEngineInfo; |
| 35 |
using Drm::setupIoctlHelper; |
| 36 |
const int mockFd = 0; |
| 37 |
MockEngineNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {} |
| 38 |
|
| 39 |
bool mockSysmanQueryEngineInfoReturnFalse = true; |
| 40 |
bool sysmanQueryEngineInfo() override { |
| 41 |
if (mockSysmanQueryEngineInfoReturnFalse != true) { |
| 42 |
return mockSysmanQueryEngineInfoReturnFalse; |
| 43 |
} |
| 44 |
|
| 45 |
std::vector<NEO::EngineCapabilities> i915engineInfo(6); |
| 46 |
i915engineInfo[0].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER; |
| 47 |
i915engineInfo[0].engine.engineInstance = 0; |
| 48 |
i915engineInfo[1].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_RENDER; |
| 49 |
i915engineInfo[1].engine.engineInstance = 1; |
| 50 |
i915engineInfo[2].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO; |
| 51 |
i915engineInfo[2].engine.engineInstance = 1; |
| 52 |
i915engineInfo[3].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_COPY; |
| 53 |
i915engineInfo[3].engine.engineInstance = 0; |
| 54 |
i915engineInfo[4].engine.engineClass = drm_i915_gem_engine_class::I915_ENGINE_CLASS_VIDEO_ENHANCE; |
| 55 |
i915engineInfo[4].engine.engineInstance = 0; |
| 56 |
i915engineInfo[5].engine.engineClass = invalidEngineClass; |
| 57 |
i915engineInfo[5].engine.engineInstance = 0; |
| 58 |
|
| 59 |
StackVec<std::vector<NEO::EngineCapabilities>, 2> engineInfosPerTile{i915engineInfo}; |
| 60 |
|
| 61 |
this->engineInfo.reset(new EngineInfo(this, engineInfosPerTile)); |
| 62 |
return true; |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
struct MockEnginePmuInterfaceImp : public PmuInterfaceImp { |
| 67 |
using PmuInterfaceImp::perfEventOpen; |
| 68 |
MockEnginePmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) : PmuInterfaceImp(pLinuxSysmanImp) {} |
| 69 |
|
| 70 |
int64_t mockPerfEventFailureReturnValue = 0; |
| 71 |
int32_t mockErrorNumber = -ENOSPC; |
| 72 |
int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) override { |
| 73 |
if (mockPerfEventFailureReturnValue == -1) { |
| 74 |
errno = mockErrorNumber; |
| 75 |
return mockPerfEventFailureReturnValue; |
| 76 |
} |
| 77 |
|
| 78 |
return mockPmuFd; |
| 79 |
} |
| 80 |
|
| 81 |
int mockPmuReadFailureReturnValue = 0; |
| 82 |
int pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) override { |
| 83 |
if (mockPmuReadFailureReturnValue == -1) { |
| 84 |
return mockPmuReadFailureReturnValue; |
| 85 |
} |
| 86 |
|
| 87 |
data[0] = mockActiveTime; |
| 88 |
data[1] = mockTimestamp; |
| 89 |
return 0; |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
struct MockEngineFsAccess : public FsAccess { |
| 94 |
uint32_t mockReadVal = 23; |
| 95 |
ze_result_t mockReadErrorVal = ZE_RESULT_SUCCESS; |
| 96 |
ze_result_t readResult = ZE_RESULT_SUCCESS; |
| 97 |
ze_result_t read(const std::string file, uint32_t &val) override { |
| 98 |
val = mockReadVal; |
| 99 |
if (mockReadErrorVal != ZE_RESULT_SUCCESS) { |
| 100 |
readResult = mockReadErrorVal; |
| 101 |
} |
| 102 |
|
| 103 |
return readResult; |
| 104 |
} |
| 105 |
}; |
| 106 |
|
| 107 |
struct MockEngineSysfsAccess : public SysfsAccess { |
| 108 |
ze_result_t mockReadSymLinkError = ZE_RESULT_SUCCESS; |
| 109 |
ze_result_t readSymLinkResult = ZE_RESULT_SUCCESS; |
| 110 |
uint32_t readSymLinkCalled = 0u; |
| 111 |
ze_result_t readSymLink(const std::string file, std::string &val) override { |
| 112 |
readSymLinkCalled++; |
| 113 |
if ((mockReadSymLinkError != ZE_RESULT_SUCCESS) && (readSymLinkCalled == 1)) { |
| 114 |
return mockReadSymLinkError; |
| 115 |
} |
| 116 |
|
| 117 |
if (file.compare(deviceDir) == 0) { |
| 118 |
val = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0"; |
| 119 |
} |
| 120 |
return readSymLinkResult; |
| 121 |
} |
| 122 |
|
| 123 |
MockEngineSysfsAccess() = default; |
| 124 |
}; |
| 125 |
|
| 126 |
using DrmMockEngineInfoFailing = DrmMock; |
| 127 |
|
| 128 |
} // namespace ult |
| 129 |
} // namespace L0 |