mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 05:56:36 +08:00
test: move drm mocks/fixtures and related tests to shared
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
4bb5a49eda
commit
b6a9ed98c9
@@ -12,5 +12,13 @@ if(UNIX)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_cache_info.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_device_blob.h
|
||||
)
|
||||
add_subdirectories()
|
||||
if(NEO_ENABLE_i915_PRELIM_DETECTION)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_fixture_context.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_fixture_context.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_fixture_prelim.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_prelim_fixtures.h
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
add_subdirectories()
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/os_interface/linux/device_command_stream_fixture_context.h"
|
||||
|
||||
#include "shared/test/common/mocks/linux/mock_drm_wrappers.h"
|
||||
|
||||
#include "third_party/uapi/prelim/drm/i915_drm.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int DrmMockCustomPrelimContext::ioctlExtra(unsigned long request, void *arg) {
|
||||
switch (request) {
|
||||
case PRELIM_DRM_IOCTL_I915_GEM_CREATE_EXT: {
|
||||
auto createExtParams = reinterpret_cast<prelim_drm_i915_gem_create_ext *>(arg);
|
||||
createExtSize = createExtParams->size;
|
||||
createExtHandle = createExtParams->handle;
|
||||
createExtExtensions = createExtParams->extensions;
|
||||
} break;
|
||||
case PRELIM_DRM_IOCTL_I915_GEM_VM_BIND: {
|
||||
} break;
|
||||
case PRELIM_DRM_IOCTL_I915_GEM_VM_UNBIND: {
|
||||
} break;
|
||||
case PRELIM_DRM_IOCTL_I915_GEM_WAIT_USER_FENCE: {
|
||||
const auto wait = reinterpret_cast<prelim_drm_i915_gem_wait_user_fence *>(arg);
|
||||
receivedGemWaitUserFence = WaitUserFence{
|
||||
wait->extensions,
|
||||
wait->addr,
|
||||
wait->ctx_id,
|
||||
wait->op,
|
||||
wait->flags,
|
||||
wait->value,
|
||||
wait->mask,
|
||||
wait->timeout,
|
||||
};
|
||||
gemWaitUserFenceCalled++;
|
||||
} break;
|
||||
default: {
|
||||
std::cout << std::hex << DRM_IOCTL_I915_GEM_WAIT << std::endl;
|
||||
std::cout << "unexpected IOCTL: " << std::hex << request << std::endl;
|
||||
UNRECOVERABLE_IF(true);
|
||||
} break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DrmMockCustomPrelimContext::execBufferExtensions(void *arg) {
|
||||
const auto execbuf = reinterpret_cast<NEO::MockExecBuffer *>(arg);
|
||||
if ((execbuf->hasUseExtensionsFlag()) &&
|
||||
(execbuf->getCliprectsPtr() != 0)) {
|
||||
DrmUserExtension *base = reinterpret_cast<DrmUserExtension *>(execbuf->getCliprectsPtr());
|
||||
if (base->name == PRELIM_DRM_I915_GEM_EXECBUFFER_EXT_USER_FENCE) {
|
||||
prelim_drm_i915_gem_execbuffer_ext_user_fence *userFenceExt =
|
||||
reinterpret_cast<prelim_drm_i915_gem_execbuffer_ext_user_fence *>(execbuf->getCliprectsPtr());
|
||||
this->completionAddress = userFenceExt->addr;
|
||||
this->completionValue = userFenceExt->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/test/common/libult/linux/drm_mock_prelim_context.h"
|
||||
|
||||
struct DrmMockCustomPrelimContext {
|
||||
//PRELIM_DRM_IOCTL_I915_GEM_CREATE_EXT
|
||||
uint64_t createExtSize = 0;
|
||||
uint32_t createExtHandle = 0;
|
||||
uint64_t createExtExtensions = 0;
|
||||
|
||||
//PRELIM_DRM_IOCTL_I915_GEM_WAIT_USER_FENCE
|
||||
WaitUserFence receivedGemWaitUserFence{};
|
||||
uint32_t gemWaitUserFenceCalled = 0;
|
||||
|
||||
//PRELIM_DRM_I915_GEM_EXECBUFFER_EXT_USER_FENCE
|
||||
uint64_t completionAddress = 0;
|
||||
uint64_t completionValue = 0;
|
||||
|
||||
int ioctlExtra(unsigned long request, void *arg);
|
||||
void execBufferExtensions(void *arg);
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/os_interface/linux/ioctl_strings.h"
|
||||
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
|
||||
|
||||
class DrmMockCustomImpl : public DrmMockCustom {
|
||||
public:
|
||||
using Drm::memoryInfo;
|
||||
|
||||
class Ioctls {
|
||||
public:
|
||||
void reset() {
|
||||
gemCreateExt = 0;
|
||||
gemMmapOffset = 0;
|
||||
}
|
||||
std::atomic<int32_t> gemCreateExt;
|
||||
std::atomic<int32_t> gemMmapOffset;
|
||||
};
|
||||
|
||||
Ioctls ioctlImpl_cnt;
|
||||
Ioctls ioctlImpl_expected;
|
||||
|
||||
void testIoctls() {
|
||||
#define NEO_IOCTL_EXPECT_EQ(PARAM) \
|
||||
if (this->ioctlImpl_expected.PARAM >= 0) { \
|
||||
EXPECT_EQ(this->ioctlImpl_expected.PARAM, this->ioctlImpl_cnt.PARAM); \
|
||||
}
|
||||
NEO_IOCTL_EXPECT_EQ(gemMmapOffset);
|
||||
#undef NEO_IOCTL_EXPECT_EQ
|
||||
}
|
||||
|
||||
//DRM_IOCTL_I915_GEM_CREATE_EXT
|
||||
__u64 createExtSize = 0;
|
||||
__u32 createExtHandle = 0;
|
||||
__u64 createExtExtensions = 0;
|
||||
|
||||
int ioctlExtra(unsigned long request, void *arg) override {
|
||||
switch (request) {
|
||||
case DRM_IOCTL_I915_GEM_CREATE_EXT: {
|
||||
auto createExtParams = reinterpret_cast<drm_i915_gem_create_ext *>(arg);
|
||||
createExtSize = createExtParams->size;
|
||||
createExtHandle = createExtParams->handle;
|
||||
createExtExtensions = createExtParams->extensions;
|
||||
ioctlImpl_cnt.gemCreateExt++;
|
||||
} break;
|
||||
default: {
|
||||
std::cout << "unexpected IOCTL: " << NEO::IoctlToStringHelper::getIoctlString(request) << std::endl;
|
||||
UNRECOVERABLE_IF(true);
|
||||
} break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DrmMockCustomImpl(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMockCustom(rootDeviceEnvironment) {
|
||||
ioctlImpl_cnt.reset();
|
||||
ioctlImpl_expected.reset();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
|
||||
#include "shared/test/common/os_interface/linux/device_command_stream_fixture_context.h"
|
||||
|
||||
class DrmMockCustomPrelim : public DrmMockCustom {
|
||||
public:
|
||||
using Drm::cacheInfo;
|
||||
using Drm::ioctlHelper;
|
||||
using Drm::memoryInfo;
|
||||
|
||||
DrmMockCustomPrelim(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMockCustom(rootDeviceEnvironment) {
|
||||
setupIoctlHelper(IGFX_UNKNOWN);
|
||||
}
|
||||
|
||||
void getPrelimVersion(std::string &prelimVersion) override {
|
||||
prelimVersion = "2.0";
|
||||
}
|
||||
|
||||
int ioctlExtra(unsigned long request, void *arg) override {
|
||||
return context.ioctlExtra(request, arg);
|
||||
}
|
||||
|
||||
void execBufferExtensions(void *arg) override {
|
||||
return context.execBufferExtensions(arg);
|
||||
}
|
||||
|
||||
DrmMockCustomPrelimContext context{};
|
||||
};
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/libult/linux/drm_mock_helper.h"
|
||||
#include "shared/test/common/libult/linux/drm_query_mock.h"
|
||||
#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/os_interface/linux/device_command_stream_fixture_prelim.h"
|
||||
#include "shared/test/common/os_interface/linux/drm_memory_manager_tests.h"
|
||||
#include "shared/test/common/os_interface/linux/drm_mock_memory_info.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
class DrmMemoryManagerLocalMemoryPrelimTest : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
DebugManager.flags.EnableLocalMemory.set(localMemoryEnabled);
|
||||
|
||||
executionEnvironment = new ExecutionEnvironment();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(defaultHwInfo.get());
|
||||
|
||||
mock = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
|
||||
auto memoryInfo = new MockExtendedMemoryInfo();
|
||||
mock->memoryInfo.reset(memoryInfo);
|
||||
|
||||
auto &multiTileArchInfo = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getMutableHardwareInfo()->gtSystemInfo.MultiTileArchInfo;
|
||||
multiTileArchInfo.TileCount = (memoryInfo->getDrmRegionInfos().size() - 1);
|
||||
multiTileArchInfo.IsValid = (multiTileArchInfo.TileCount > 0);
|
||||
|
||||
mock->queryEngineInfo();
|
||||
|
||||
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
|
||||
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
|
||||
|
||||
memoryManager = new TestedDrmMemoryManager(localMemoryEnabled, false, false, *executionEnvironment);
|
||||
executionEnvironment->memoryManager.reset(memoryManager);
|
||||
|
||||
device.reset(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, rootDeviceIndex));
|
||||
}
|
||||
|
||||
protected:
|
||||
DebugManagerStateRestore restorer{};
|
||||
ExecutionEnvironment *executionEnvironment{nullptr};
|
||||
DrmQueryMock *mock{nullptr};
|
||||
std::unique_ptr<MockDevice> device;
|
||||
TestedDrmMemoryManager *memoryManager{nullptr};
|
||||
|
||||
constexpr static uint32_t rootDeviceIndex{0u};
|
||||
constexpr static bool localMemoryEnabled{true};
|
||||
};
|
||||
|
||||
class DrmMemoryManagerLocalMemoryWithCustomPrelimMockTest : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const bool localMemoryEnabled = true;
|
||||
executionEnvironment = new ExecutionEnvironment;
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
|
||||
mock = new DrmMockCustomPrelim(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
|
||||
|
||||
device.reset(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
|
||||
memoryManager = std::make_unique<TestedDrmMemoryManager>(localMemoryEnabled, false, false, *executionEnvironment);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<MockDevice> device;
|
||||
std::unique_ptr<TestedDrmMemoryManager> memoryManager;
|
||||
DrmMockCustomPrelim *mock;
|
||||
ExecutionEnvironment *executionEnvironment;
|
||||
};
|
||||
|
||||
class DrmMemoryManagerFixturePrelim : public DrmMemoryManagerFixture {
|
||||
public:
|
||||
void SetUp() override {
|
||||
regionInfo.resize(2);
|
||||
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 1};
|
||||
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)};
|
||||
|
||||
MemoryManagementFixture::SetUp();
|
||||
executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), numRootDevices - 1);
|
||||
mock = new DrmMockCustomPrelim(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
mock->memoryInfo.reset(new MemoryInfo(regionInfo));
|
||||
|
||||
DrmMemoryManagerFixture::SetUp(mock, true);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
mock->testIoctls();
|
||||
DrmMemoryManagerFixture::TearDown();
|
||||
}
|
||||
|
||||
std::vector<MemoryRegion> regionInfo;
|
||||
DrmMockCustomPrelim *mock;
|
||||
};
|
||||
36
shared/test/common/os_interface/linux/drm_mock_memory_info.h
Normal file
36
shared/test/common/os_interface/linux/drm_mock_memory_info.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/os_interface/linux/memory_info.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
const std::vector<NEO::MemoryRegion> memoryRegions = {
|
||||
{{I915_MEMORY_CLASS_SYSTEM, 0}, 64 * GB, 0},
|
||||
{{I915_MEMORY_CLASS_DEVICE, 0}, 8 * GB, 0}};
|
||||
|
||||
struct MockMemoryInfo : public NEO::MemoryInfo {
|
||||
MockMemoryInfo() : MemoryInfo(memoryRegions) {}
|
||||
~MockMemoryInfo() override = default;
|
||||
};
|
||||
|
||||
const std::vector<NEO::MemoryRegion> extendedMemoryRegions = {
|
||||
{{I915_MEMORY_CLASS_SYSTEM, 1}, 64 * GB, 0},
|
||||
{{I915_MEMORY_CLASS_DEVICE, 0x100}, 8 * GB, 0},
|
||||
{{I915_MEMORY_CLASS_DEVICE, 0x200}, 8 * GB, 0},
|
||||
{{I915_MEMORY_CLASS_DEVICE, 0x400}, 8 * GB, 0},
|
||||
{{I915_MEMORY_CLASS_DEVICE, 0x800}, 8 * GB, 0}};
|
||||
|
||||
struct MockExtendedMemoryInfo : public NEO::MemoryInfo {
|
||||
MockExtendedMemoryInfo() : MemoryInfo(extendedMemoryRegions) {}
|
||||
~MockExtendedMemoryInfo() override = default;
|
||||
};
|
||||
Reference in New Issue
Block a user