Add unit tests for completion fence

Related-To: NEO-6575

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2022-01-20 11:07:57 +00:00
committed by Compute-Runtime-Automation
parent 6968bfdb33
commit ec40b6562e
13 changed files with 252 additions and 74 deletions

View File

@@ -146,6 +146,7 @@ set(neo_libult_common_SRCS_LIB_ULT_LINUX
${NEO_SHARED_TEST_DIRECTORY}/common/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp
${NEO_SHARED_TEST_DIRECTORY}/common/os_interface/linux/device_command_stream_fixture.cpp
${NEO_SHARED_TEST_DIRECTORY}/common/os_interface/linux/device_command_stream_fixture.h
${NEO_SHARED_TEST_DIRECTORY}/common/os_interface/linux/drm_buffer_object_fixture.h
)
set_property(GLOBAL PROPERTY neo_libult_common_SRCS_LIB_ULT_LINUX ${neo_libult_common_SRCS_LIB_ULT_LINUX})

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -28,6 +28,7 @@ class TestedDrmCommandStreamReceiver : public DrmCommandStreamReceiver<GfxFamily
using CommandStreamReceiver::useGpuIdleImplicitFlush;
using CommandStreamReceiver::useNewResourceImplicitFlush;
using CommandStreamReceiver::useNotifyEnableForPostSync;
using DrmCommandStreamReceiver<GfxFamily>::exec;
using DrmCommandStreamReceiver<GfxFamily>::residency;
using DrmCommandStreamReceiver<GfxFamily>::useContextForUserFenceWait;
using DrmCommandStreamReceiver<GfxFamily>::useUserFenceWait;

View File

@@ -69,6 +69,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::allocateGraphicsMemoryWithAlignment;
using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr;
using DrmMemoryManager::allocateMemoryByKMD;
using DrmMemoryManager::allocationTypeForCompletionFence;
using DrmMemoryManager::allocUserptr;
using DrmMemoryManager::createAllocWithAlignment;
using DrmMemoryManager::createAllocWithAlignmentFromUserptr;
@@ -80,6 +81,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::getRootDeviceIndex;
using DrmMemoryManager::getUserptrAlignment;
using DrmMemoryManager::gfxPartitions;
using DrmMemoryManager::handleFenceCompletion;
using DrmMemoryManager::lockResourceInLocalMemoryImpl;
using DrmMemoryManager::memoryForPinBBs;
using DrmMemoryManager::mmapFunction;
@@ -94,6 +96,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::sharingBufferObjects;
using DrmMemoryManager::supportsMultiStorageResources;
using DrmMemoryManager::unlockResourceInLocalMemoryImpl;
using DrmMemoryManager::waitOnCompletionFence;
using MemoryManager::allocateGraphicsMemoryInDevicePool;
using MemoryManager::heapAssigner;
using MemoryManager::registeredEngines;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -12,6 +12,7 @@
namespace NEO {
struct MockAllocationProperties : public AllocationProperties {
MockAllocationProperties(uint32_t rootDeviceIndex, size_t size) : AllocationProperties(rootDeviceIndex, true, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false, mockDeviceBitfield) {}
MockAllocationProperties(uint32_t rootDeviceIndex, size_t size, GraphicsAllocation::AllocationType type) : AllocationProperties(rootDeviceIndex, true, size, type, false, mockDeviceBitfield) {}
MockAllocationProperties(uint32_t rootDeviceIndex, size_t size, DeviceBitfield deviceBitfield) : AllocationProperties(rootDeviceIndex, true, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false, deviceBitfield) {}
MockAllocationProperties(uint32_t rootDeviceIndex, bool allocateMemory, size_t size) : AllocationProperties(rootDeviceIndex, allocateMemory, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false, mockDeviceBitfield) {}
MockAllocationProperties(uint32_t rootDeviceIndex, bool allocateMemory, size_t size, DeviceBitfield deviceBitfield) : AllocationProperties(rootDeviceIndex, allocateMemory, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, false, deviceBitfield) {}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -70,6 +70,7 @@ int DrmMockCustom::ioctl(unsigned long request, void *arg) {
this->execBufferBufferObjects =
*reinterpret_cast<drm_i915_gem_exec_object2 *>(this->execBuffer.buffers_ptr);
ioctl_cnt.execbuffer2++;
execBufferExtensions(execbuf);
} break;
case DRM_IOCTL_I915_GEM_USERPTR: {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -68,6 +68,7 @@ class DrmMockCustom : public Drm {
public:
using Drm::bindAvailable;
using Drm::cacheInfo;
using Drm::completionFenceSupported;
using Drm::memoryInfo;
struct IoctlResExt {
@@ -143,6 +144,9 @@ class DrmMockCustom : public Drm {
ioctl_res_ext = &NONE;
}
virtual void execBufferExtensions(drm_i915_gem_execbuffer2 *execbuf) {
}
Ioctls ioctl_cnt;
Ioctls ioctl_expected;

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/linux/drm_buffer_object.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "drm/i915_drm.h"
#include <memory>
class TestedBufferObject : public BufferObject {
public:
using BufferObject::handle;
TestedBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) {
}
TestedBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, size, 1) {
}
void tileBy(uint32_t mode) {
this->tiling_mode = mode;
}
void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) override {
BufferObject::fillExecObject(execObject, osContext, vmHandleId, drmContextId);
execObjectPointerFilled = &execObject;
}
void setSize(size_t size) {
this->size = size;
}
int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId,
BufferObject *const residency[], size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage, uint64_t completionGpuAddress, uint32_t completionValue) override {
this->receivedCompletionGpuAddress = completionGpuAddress;
this->receivedCompletionValue = completionValue;
return BufferObject::exec(used, startOffset, flags, requiresCoherency, osContext, vmHandleId, drmContextId, residency, residencyCount, execObjectsStorage, completionGpuAddress, completionValue);
}
uint64_t receivedCompletionGpuAddress = 0;
drm_i915_gem_exec_object2 *execObjectPointerFilled = nullptr;
uint32_t receivedCompletionValue = 0;
};
template <typename DrmClass>
class DrmBufferObjectFixture {
public:
std::unique_ptr<DrmClass> mock;
TestedBufferObject *bo;
drm_i915_gem_exec_object2 execObjectsStorage[256];
std::unique_ptr<OsContextLinux> osContext;
void SetUp() {
this->mock = std::make_unique<DrmClass>(*executionEnvironment.rootDeviceEnvironments[0]);
ASSERT_NE(nullptr, this->mock);
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
osContext.reset(new OsContextLinux(*this->mock, 0u, EngineDescriptorHelper::getDefaultDescriptor()));
this->mock->reset();
bo = new TestedBufferObject(this->mock.get());
ASSERT_NE(nullptr, bo);
}
void TearDown() {
delete bo;
if (this->mock->ioctl_expected.total >= 0) {
EXPECT_EQ(this->mock->ioctl_expected.total, this->mock->ioctl_cnt.total);
}
mock->reset();
osContext.reset(nullptr);
mock.reset(nullptr);
}
MockExecutionEnvironment executionEnvironment;
};