mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-12 17:33:00 +08:00
Clean up DrmMock.
Related-To: NEO-3008 Change-Id: I52543d676c4946c6142ba4345278abac8f4597a9 Signed-off-by: Piotr Fusik <piotr.fusik@intel.com>
This commit is contained in:
@@ -24,8 +24,8 @@ set(IGDRCL_SRCS_tests_os_interface_linux
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_tests.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_memory_manager_allocate_in_device_pool_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_mock.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_neo_create.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp
|
||||
|
||||
@@ -7,6 +7,134 @@
|
||||
|
||||
#include "unit_tests/os_interface/linux/drm_mock.h"
|
||||
|
||||
int DrmMock::handleRemainingRequests(unsigned long request, void *arg) {
|
||||
return -1;
|
||||
};
|
||||
int DrmMock::ioctl(unsigned long request, void *arg) {
|
||||
ioctlCallsCount++;
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GETPARAM) && (arg != nullptr)) {
|
||||
auto gp = static_cast<drm_i915_getparam_t *>(arg);
|
||||
if (gp->param == I915_PARAM_EU_TOTAL) {
|
||||
if (0 == this->StoredRetValForEUVal) {
|
||||
*gp->value = this->StoredEUVal;
|
||||
}
|
||||
return this->StoredRetValForEUVal;
|
||||
}
|
||||
if (gp->param == I915_PARAM_SUBSLICE_TOTAL) {
|
||||
if (0 == this->StoredRetValForSSVal) {
|
||||
*gp->value = this->StoredSSVal;
|
||||
}
|
||||
return this->StoredRetValForSSVal;
|
||||
}
|
||||
if (gp->param == I915_PARAM_CHIPSET_ID) {
|
||||
if (0 == this->StoredRetValForDeviceID) {
|
||||
*gp->value = this->StoredDeviceID;
|
||||
}
|
||||
return this->StoredRetValForDeviceID;
|
||||
}
|
||||
if (gp->param == I915_PARAM_REVISION) {
|
||||
if (0 == this->StoredRetValForDeviceRevID) {
|
||||
*gp->value = this->StoredDeviceRevID;
|
||||
}
|
||||
return this->StoredRetValForDeviceRevID;
|
||||
}
|
||||
if (gp->param == I915_PARAM_HAS_POOLED_EU) {
|
||||
if (0 == this->StoredRetValForPooledEU) {
|
||||
*gp->value = this->StoredHasPooledEU;
|
||||
}
|
||||
return this->StoredRetValForPooledEU;
|
||||
}
|
||||
if (gp->param == I915_PARAM_MIN_EU_IN_POOL) {
|
||||
if (0 == this->StoredRetValForMinEUinPool) {
|
||||
*gp->value = this->StoredMinEUinPool;
|
||||
}
|
||||
return this->StoredRetValForMinEUinPool;
|
||||
}
|
||||
if (gp->param == I915_PARAM_HAS_SCHEDULER) {
|
||||
*gp->value = this->StoredPreemptionSupport;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
if (gp->param == I915_PARAM_HAS_EXEC_SOFTPIN) {
|
||||
*gp->value = this->StoredExecSoftPin;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_CREATE) && (arg != nullptr)) {
|
||||
auto create = static_cast<drm_i915_gem_context_create *>(arg);
|
||||
create->ctx_id = this->StoredCtxId;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_DESTROY) && (arg != nullptr)) {
|
||||
auto destroy = static_cast<drm_i915_gem_context_destroy *>(arg);
|
||||
this->receivedDestroyContextId = destroy->ctx_id;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM) && (arg != nullptr)) {
|
||||
receivedContextParamRequestCount++;
|
||||
receivedContextParamRequest = *static_cast<drm_i915_gem_context_param *>(arg);
|
||||
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PRIORITY) {
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
if ((receivedContextParamRequest.param == I915_CONTEXT_PRIVATE_PARAM_BOOST) && (receivedContextParamRequest.value == 1)) {
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM) && (arg != nullptr)) {
|
||||
receivedContextParamRequestCount++;
|
||||
receivedContextParamRequest = *static_cast<drm_i915_gem_context_param *>(arg);
|
||||
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_GTT_SIZE) {
|
||||
static_cast<drm_i915_gem_context_param *>(arg)->value = this->storedGTTSize;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
}
|
||||
|
||||
if (request == DRM_IOCTL_I915_GEM_EXECBUFFER2) {
|
||||
auto execbuf = static_cast<drm_i915_gem_execbuffer2 *>(arg);
|
||||
this->execBuffer = *execbuf;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_USERPTR) {
|
||||
auto userPtrParams = static_cast<drm_i915_gem_userptr *>(arg);
|
||||
userPtrParams->handle = returnHandle;
|
||||
returnHandle++;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_CREATE) {
|
||||
auto createParams = static_cast<drm_i915_gem_create *>(arg);
|
||||
this->createParamsSize = createParams->size;
|
||||
this->createParamsHandle = createParams->handle = 1u;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_SET_TILING) {
|
||||
auto setTilingParams = static_cast<drm_i915_gem_set_tiling *>(arg);
|
||||
setTilingMode = setTilingParams->tiling_mode;
|
||||
setTilingHandle = setTilingParams->handle;
|
||||
setTilingStride = setTilingParams->stride;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_PRIME_FD_TO_HANDLE) {
|
||||
auto primeToHandleParams = static_cast<drm_prime_handle *>(arg);
|
||||
//return BO
|
||||
primeToHandleParams->handle = outputHandle;
|
||||
inputFd = primeToHandleParams->fd;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_GET_APERTURE) {
|
||||
auto aperture = static_cast<drm_i915_gem_get_aperture *>(arg);
|
||||
aperture->aper_available_size = gpuMemSize;
|
||||
aperture->aper_size = gpuMemSize;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_MMAP) {
|
||||
auto mmap_arg = static_cast<drm_i915_gem_mmap *>(arg);
|
||||
mmap_arg->addr_ptr = reinterpret_cast<__u64>(lockedPtr);
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_WAIT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return handleRemainingRequests(request, arg);
|
||||
}
|
||||
|
||||
@@ -7,22 +7,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/helpers/options.h"
|
||||
#include "runtime/memory_manager/memory_constants.h"
|
||||
#include "runtime/os_interface/linux/drm_neo.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
#if !defined(I915_PARAM_HAS_PREEMPTION)
|
||||
#define I915_PARAM_HAS_PREEMPTION 0x806
|
||||
#endif
|
||||
|
||||
// Mock DRM class that responds to DRM_IOCTL_I915_GETPARAMs
|
||||
class DrmMock : public Drm {
|
||||
public:
|
||||
@@ -31,7 +25,6 @@ class DrmMock : public Drm {
|
||||
using Drm::query;
|
||||
|
||||
DrmMock() : Drm(mockFd) {
|
||||
sysFsDefaultGpuPathToRestore = nullptr;
|
||||
}
|
||||
|
||||
~DrmMock() {
|
||||
@@ -39,164 +32,8 @@ class DrmMock : public Drm {
|
||||
sysFsDefaultGpuPath = sysFsDefaultGpuPathToRestore;
|
||||
}
|
||||
}
|
||||
int ioctl(unsigned long request, void *arg) override {
|
||||
ioctlCallsCount++;
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GETPARAM) && (arg != nullptr)) {
|
||||
drm_i915_getparam_t *gp = (drm_i915_getparam_t *)arg;
|
||||
if (false
|
||||
#if defined(I915_PARAM_EU_TOTAL)
|
||||
|| (gp->param == I915_PARAM_EU_TOTAL)
|
||||
#endif
|
||||
#if defined(I915_PARAM_EU_COUNT)
|
||||
|| (gp->param == I915_PARAM_EU_COUNT)
|
||||
#endif
|
||||
) {
|
||||
if (0 == this->StoredRetValForEUVal) {
|
||||
*((int *)(gp->value)) = this->StoredEUVal;
|
||||
}
|
||||
return this->StoredRetValForEUVal;
|
||||
}
|
||||
if (false
|
||||
#if defined(I915_PARAM_SUBSLICE_TOTAL)
|
||||
|| (gp->param == I915_PARAM_SUBSLICE_TOTAL)
|
||||
#endif
|
||||
) {
|
||||
if (0 == this->StoredRetValForSSVal) {
|
||||
*((int *)(gp->value)) = this->StoredSSVal;
|
||||
}
|
||||
return this->StoredRetValForSSVal;
|
||||
}
|
||||
if (false
|
||||
#if defined(I915_PARAM_CHIPSET_ID)
|
||||
|| (gp->param == I915_PARAM_CHIPSET_ID)
|
||||
#endif
|
||||
) {
|
||||
if (0 == this->StoredRetValForDeviceID) {
|
||||
*((int *)(gp->value)) = this->StoredDeviceID;
|
||||
}
|
||||
return this->StoredRetValForDeviceID;
|
||||
}
|
||||
if (false
|
||||
#if defined(I915_PARAM_REVISION)
|
||||
|| (gp->param == I915_PARAM_REVISION)
|
||||
#endif
|
||||
) {
|
||||
if (0 == this->StoredRetValForDeviceRevID) {
|
||||
*((int *)(gp->value)) = this->StoredDeviceRevID;
|
||||
}
|
||||
return this->StoredRetValForDeviceRevID;
|
||||
}
|
||||
if (false
|
||||
#if defined(I915_PARAM_HAS_POOLED_EU)
|
||||
|| (gp->param == I915_PARAM_HAS_POOLED_EU)
|
||||
#endif
|
||||
) {
|
||||
if (0 == this->StoredRetValForPooledEU) {
|
||||
*((int *)(gp->value)) = this->StoredHasPooledEU;
|
||||
}
|
||||
return this->StoredRetValForPooledEU;
|
||||
}
|
||||
if (false
|
||||
#if defined(I915_PARAM_MIN_EU_IN_POOL)
|
||||
|| (gp->param == I915_PARAM_MIN_EU_IN_POOL)
|
||||
#endif
|
||||
) {
|
||||
if (0 == this->StoredRetValForMinEUinPool) {
|
||||
*((int *)(gp->value)) = this->StoredMinEUinPool;
|
||||
}
|
||||
return this->StoredRetValForMinEUinPool;
|
||||
}
|
||||
if (gp->param == I915_PARAM_HAS_SCHEDULER) {
|
||||
*((int *)(gp->value)) = this->StoredPreemptionSupport;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
if (gp->param == I915_PARAM_HAS_EXEC_SOFTPIN) {
|
||||
*((int *)(gp->value)) = this->StoredExecSoftPin;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_CREATE) && (arg != nullptr)) {
|
||||
drm_i915_gem_context_create *create = (drm_i915_gem_context_create *)arg;
|
||||
create->ctx_id = this->StoredCtxId;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_DESTROY) && (arg != nullptr)) {
|
||||
drm_i915_gem_context_destroy *destroy = (drm_i915_gem_context_destroy *)arg;
|
||||
this->receivedDestroyContextId = destroy->ctx_id;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM) && (arg != nullptr)) {
|
||||
receivedContextParamRequestCount++;
|
||||
receivedContextParamRequest = *reinterpret_cast<drm_i915_gem_context_param *>(arg);
|
||||
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PRIORITY) {
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
if ((receivedContextParamRequest.param == I915_CONTEXT_PRIVATE_PARAM_BOOST) && (receivedContextParamRequest.value == 1)) {
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
}
|
||||
|
||||
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM) && (arg != nullptr)) {
|
||||
receivedContextParamRequestCount++;
|
||||
receivedContextParamRequest = *reinterpret_cast<drm_i915_gem_context_param *>(arg);
|
||||
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_GTT_SIZE) {
|
||||
reinterpret_cast<drm_i915_gem_context_param *>(arg)->value = this->storedGTTSize;
|
||||
return this->StoredRetVal;
|
||||
}
|
||||
}
|
||||
|
||||
if (request == DRM_IOCTL_I915_GEM_EXECBUFFER2) {
|
||||
drm_i915_gem_execbuffer2 *execbuf = (drm_i915_gem_execbuffer2 *)arg;
|
||||
this->execBuffer = *execbuf;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_USERPTR) {
|
||||
auto *userPtrParams = (drm_i915_gem_userptr *)arg;
|
||||
userPtrParams->handle = returnHandle;
|
||||
returnHandle++;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_CREATE) {
|
||||
auto *createParams = (drm_i915_gem_create *)arg;
|
||||
this->createParamsSize = createParams->size;
|
||||
this->createParamsHandle = createParams->handle = 1u;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_SET_TILING) {
|
||||
auto *setTilingParams = (drm_i915_gem_set_tiling *)arg;
|
||||
setTilingMode = setTilingParams->tiling_mode;
|
||||
setTilingHandle = setTilingParams->handle;
|
||||
setTilingStride = setTilingParams->stride;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_PRIME_FD_TO_HANDLE) {
|
||||
auto *primeToHandleParams = (drm_prime_handle *)arg;
|
||||
//return BO
|
||||
primeToHandleParams->handle = outputHandle;
|
||||
inputFd = primeToHandleParams->fd;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_GET_APERTURE) {
|
||||
auto aperture = (drm_i915_gem_get_aperture *)arg;
|
||||
aperture->aper_available_size = gpuMemSize;
|
||||
aperture->aper_size = gpuMemSize;
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_MMAP) {
|
||||
auto mmap_arg = static_cast<drm_i915_gem_mmap *>(arg);
|
||||
mmap_arg->addr_ptr = reinterpret_cast<__u64>(lockedPtr);
|
||||
return 0;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_WAIT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return handleRemainingRequests(request, arg);
|
||||
}
|
||||
int ioctl(unsigned long request, void *arg) override;
|
||||
|
||||
void setSysFsDefaultGpuPath(const char *path) {
|
||||
sysFsDefaultGpuPathToRestore = sysFsDefaultGpuPath;
|
||||
@@ -220,6 +57,7 @@ class DrmMock : public Drm {
|
||||
remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
void setFileDescriptor(int fd) {
|
||||
this->fd = fd;
|
||||
}
|
||||
@@ -275,8 +113,8 @@ class DrmMock : public Drm {
|
||||
|
||||
uint64_t storedGTTSize = 1ull << 47;
|
||||
|
||||
virtual int handleRemainingRequests(unsigned long request, void *arg);
|
||||
virtual int handleRemainingRequests(unsigned long request, void *arg) { return -1; }
|
||||
|
||||
private:
|
||||
const char *sysFsDefaultGpuPathToRestore;
|
||||
const char *sysFsDefaultGpuPathToRestore = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user