From d1c86096291331df721e7682bd515e41437615e8 Mon Sep 17 00:00:00 2001 From: Piotr Fusik Date: Tue, 23 Jul 2019 11:45:10 +0200 Subject: [PATCH] Clean up DrmMock. Related-To: NEO-3008 Change-Id: I52543d676c4946c6142ba4345278abac8f4597a9 Signed-off-by: Piotr Fusik --- runtime/os_interface/linux/drm_neo.cpp | 32 +--- unit_tests/os_interface/linux/CMakeLists.txt | 2 +- unit_tests/os_interface/linux/drm_mock.cpp | 134 ++++++++++++++- unit_tests/os_interface/linux/drm_mock.h | 172 +------------------ 4 files changed, 138 insertions(+), 202 deletions(-) diff --git a/runtime/os_interface/linux/drm_neo.cpp b/runtime/os_interface/linux/drm_neo.cpp index bbbed56721..31deb68b61 100644 --- a/runtime/os_interface/linux/drm_neo.cpp +++ b/runtime/os_interface/linux/drm_neo.cpp @@ -42,19 +42,11 @@ int Drm::getParamIoctl(int param, int *dstValue) { } int Drm::getDeviceID(int &devId) { -#if defined(I915_PARAM_CHIPSET_ID) return getParamIoctl(I915_PARAM_CHIPSET_ID, &devId); -#else - return 0; -#endif } int Drm::getDeviceRevID(int &revId) { -#if defined(I915_PARAM_REVISION) return getParamIoctl(I915_PARAM_REVISION, &revId); -#else - return 0; -#endif } int Drm::getExecSoftPin(int &execSoftPin) { @@ -70,11 +62,7 @@ int Drm::enableTurboBoost() { } int Drm::getEnabledPooledEu(int &enabled) { -#if defined(I915_PARAM_HAS_POOLED_EU) return getParamIoctl(I915_PARAM_HAS_POOLED_EU, &enabled); -#else - return 0; -#endif } int Drm::getMaxGpuFrequency(int &maxGpuFrequency) { @@ -169,33 +157,15 @@ void Drm::destroyDrmContext(uint32_t drmContextId) { } int Drm::getEuTotal(int &euTotal) { -#if defined(I915_PARAM_EU_TOTAL) || defined(I915_PARAM_EU_COUNT) - int param = -#if defined(I915_PARAM_EU_TOTAL) - I915_PARAM_EU_TOTAL; -#elif defined(I915_PARAM_EU_COUNT) - I915_PARAM_EU_COUNT; -#endif - return getParamIoctl(param, &euTotal); -#else - return 0; -#endif + return getParamIoctl(I915_PARAM_EU_TOTAL, &euTotal); } int Drm::getSubsliceTotal(int &subsliceTotal) { -#if defined(I915_PARAM_SUBSLICE_TOTAL) return getParamIoctl(I915_PARAM_SUBSLICE_TOTAL, &subsliceTotal); -#else - return 0; -#endif } int Drm::getMinEuInPool(int &minEUinPool) { -#if defined(I915_PARAM_MIN_EU_IN_POOL) return getParamIoctl(I915_PARAM_MIN_EU_IN_POOL, &minEUinPool); -#else - return 0; -#endif } int Drm::getErrno() { diff --git a/unit_tests/os_interface/linux/CMakeLists.txt b/unit_tests/os_interface/linux/CMakeLists.txt index 3d1c4fef96..49c94afbcb 100644 --- a/unit_tests/os_interface/linux/CMakeLists.txt +++ b/unit_tests/os_interface/linux/CMakeLists.txt @@ -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 diff --git a/unit_tests/os_interface/linux/drm_mock.cpp b/unit_tests/os_interface/linux/drm_mock.cpp index ed5e64369c..8311e03c1f 100644 --- a/unit_tests/os_interface/linux/drm_mock.cpp +++ b/unit_tests/os_interface/linux/drm_mock.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(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(arg); + create->ctx_id = this->StoredCtxId; + return this->StoredRetVal; + } + + if ((request == DRM_IOCTL_I915_GEM_CONTEXT_DESTROY) && (arg != nullptr)) { + auto destroy = static_cast(arg); + this->receivedDestroyContextId = destroy->ctx_id; + return this->StoredRetVal; + } + + if ((request == DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM) && (arg != nullptr)) { + receivedContextParamRequestCount++; + receivedContextParamRequest = *static_cast(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(arg); + if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_GTT_SIZE) { + static_cast(arg)->value = this->storedGTTSize; + return this->StoredRetVal; + } + } + + if (request == DRM_IOCTL_I915_GEM_EXECBUFFER2) { + auto execbuf = static_cast(arg); + this->execBuffer = *execbuf; + return 0; + } + if (request == DRM_IOCTL_I915_GEM_USERPTR) { + auto userPtrParams = static_cast(arg); + userPtrParams->handle = returnHandle; + returnHandle++; + return 0; + } + if (request == DRM_IOCTL_I915_GEM_CREATE) { + auto createParams = static_cast(arg); + this->createParamsSize = createParams->size; + this->createParamsHandle = createParams->handle = 1u; + return 0; + } + if (request == DRM_IOCTL_I915_GEM_SET_TILING) { + auto setTilingParams = static_cast(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(arg); + //return BO + primeToHandleParams->handle = outputHandle; + inputFd = primeToHandleParams->fd; + return 0; + } + if (request == DRM_IOCTL_I915_GEM_GET_APERTURE) { + auto aperture = static_cast(arg); + aperture->aper_available_size = gpuMemSize; + aperture->aper_size = gpuMemSize; + return 0; + } + if (request == DRM_IOCTL_I915_GEM_MMAP) { + auto mmap_arg = static_cast(arg); + mmap_arg->addr_ptr = reinterpret_cast<__u64>(lockedPtr); + return 0; + } + if (request == DRM_IOCTL_I915_GEM_WAIT) { + return 0; + } + + return handleRemainingRequests(request, arg); +} diff --git a/unit_tests/os_interface/linux/drm_mock.h b/unit_tests/os_interface/linux/drm_mock.h index 6c8cdaf714..62d4996263 100644 --- a/unit_tests/os_interface/linux/drm_mock.h +++ b/unit_tests/os_interface/linux/drm_mock.h @@ -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 #include 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(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(arg); - if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_GTT_SIZE) { - reinterpret_cast(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(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; };