149 lines
4.6 KiB
C++
149 lines
4.6 KiB
C++
/*
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
#include "shared/source/helpers/constants.h"
|
|
#include "shared/source/helpers/hw_helper.h"
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
|
|
|
#include "opencl/source/platform/platform.h"
|
|
#include "opencl/test/unit_test/linux/mock_os_layer.h"
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
|
|
|
#include "drm/i915_drm.h"
|
|
|
|
#include <cstdio>
|
|
#include <fstream>
|
|
#include <limits.h>
|
|
|
|
using namespace NEO;
|
|
|
|
// Mock DRM class that responds to DRM_IOCTL_I915_GETPARAMs
|
|
class DrmMock : public Drm {
|
|
public:
|
|
using Drm::checkQueueSliceSupport;
|
|
using Drm::engineInfo;
|
|
using Drm::getQueueSliceCount;
|
|
using Drm::memoryInfo;
|
|
using Drm::nonPersistentContextsSupported;
|
|
using Drm::preemptionSupported;
|
|
using Drm::query;
|
|
using Drm::requirePerContextVM;
|
|
using Drm::sliceCountChangeSupported;
|
|
using Drm::virtualMemoryIds;
|
|
|
|
DrmMock(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd, ""), rootDeviceEnvironment) {
|
|
sliceCountChangeSupported = true;
|
|
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
|
|
createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
|
|
}
|
|
}
|
|
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(mockFd, rootDeviceEnvironment) {}
|
|
DrmMock() : DrmMock(*platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
|
|
|
|
int ioctl(unsigned long request, void *arg) override;
|
|
|
|
void writeConfigFile(const char *name, int deviceID) {
|
|
std::ofstream tempfile(name, std::ios::binary);
|
|
if (tempfile.is_open()) {
|
|
PCIConfig config;
|
|
config.DeviceID = deviceID;
|
|
tempfile.write(reinterpret_cast<char *>(&config), sizeof(config));
|
|
tempfile.close();
|
|
}
|
|
}
|
|
|
|
void deleteConfigFile(const char *name) {
|
|
std::ofstream tempfile(name);
|
|
if (tempfile.is_open()) {
|
|
tempfile.close();
|
|
remove(name);
|
|
}
|
|
}
|
|
|
|
void setFileDescriptor(int fd) {
|
|
hwDeviceId = std::make_unique<HwDeviceId>(fd, "");
|
|
}
|
|
|
|
void setPciPath(const char *pciPath) {
|
|
hwDeviceId = std::make_unique<HwDeviceId>(getFileDescriptor(), pciPath);
|
|
}
|
|
|
|
void setDeviceID(int deviceId) { this->deviceId = deviceId; }
|
|
void setDeviceRevID(int revisionId) { this->revisionId = revisionId; }
|
|
|
|
static const int mockFd = 33;
|
|
|
|
bool failRetTopology = false;
|
|
int StoredEUVal = 8;
|
|
int StoredSSVal = 2;
|
|
int StoredSVal = 1;
|
|
int StoredDeviceID = 1;
|
|
int StoredDeviceRevID = 1;
|
|
int StoredHasPooledEU = 1;
|
|
int StoredMinEUinPool = 1;
|
|
int StoredPersistentContextsSupport = 1;
|
|
int StoredRetVal = 0;
|
|
int StoredRetValForGetGttSize = 0;
|
|
int StoredRetValForGetSSEU = 0;
|
|
int StoredRetValForSetSSEU = 0;
|
|
int StoredRetValForDeviceID = 0;
|
|
int StoredRetValForEUVal = 0;
|
|
int StoredRetValForSSVal = 0;
|
|
int StoredRetValForDeviceRevID = 0;
|
|
int StoredRetValForPooledEU = 0;
|
|
int StoredRetValForMinEUinPool = 0;
|
|
int StoredRetValForPersistant = 0;
|
|
int StoredPreemptionSupport =
|
|
I915_SCHEDULER_CAP_ENABLED |
|
|
I915_SCHEDULER_CAP_PRIORITY |
|
|
I915_SCHEDULER_CAP_PREEMPTION;
|
|
int StoredExecSoftPin = 0;
|
|
|
|
bool disableSomeTopology = false;
|
|
|
|
uint32_t receivedCreateContextId = 0;
|
|
uint32_t receivedDestroyContextId = 0;
|
|
uint32_t ioctlCallsCount = 0;
|
|
|
|
uint32_t receivedContextParamRequestCount = 0;
|
|
drm_i915_gem_context_param receivedContextParamRequest = {};
|
|
|
|
//DRM_IOCTL_I915_GEM_EXECBUFFER2
|
|
drm_i915_gem_execbuffer2 execBuffer = {0};
|
|
|
|
//DRM_IOCTL_I915_GEM_CREATE
|
|
__u64 createParamsSize = 0;
|
|
__u32 createParamsHandle = 0;
|
|
//DRM_IOCTL_I915_GEM_SET_TILING
|
|
__u32 setTilingMode = 0;
|
|
__u32 setTilingHandle = 0;
|
|
__u32 setTilingStride = 0;
|
|
//DRM_IOCTL_PRIME_FD_TO_HANDLE
|
|
__u32 outputHandle = 0;
|
|
__s32 inputFd = 0;
|
|
//DRM_IOCTL_I915_GEM_USERPTR
|
|
__u32 returnHandle = 0;
|
|
__u64 gpuMemSize = 3u * MemoryConstants::gigaByte;
|
|
//DRM_IOCTL_I915_GEM_MMAP
|
|
uint64_t lockedPtr[4];
|
|
|
|
uint64_t storedGTTSize = 1ull << 47;
|
|
uint64_t storedParamSseu = ULONG_MAX;
|
|
|
|
virtual int handleRemainingRequests(unsigned long request, void *arg) { return -1; }
|
|
};
|
|
|
|
class DrmMockNonFailing : public DrmMock {
|
|
public:
|
|
using DrmMock::DrmMock;
|
|
int handleRemainingRequests(unsigned long request, void *arg) override { return 0; }
|
|
};
|