2018-08-01 20:47:14 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-08-01 20:47:14 +08:00
|
|
|
|
|
|
|
#include "runtime/os_interface/linux/drm_memory_manager.h"
|
2018-10-24 14:46:54 +08:00
|
|
|
#include "unit_tests/mocks/mock_host_ptr_manager.h"
|
2018-11-15 22:11:14 +08:00
|
|
|
#include <atomic>
|
2018-08-01 20:47:14 +08:00
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
static off_t lseekReturn = 4096u;
|
2018-11-15 22:11:14 +08:00
|
|
|
static std::atomic<int> lseekCalledCount(0);
|
|
|
|
static std::atomic<int> mmapMockCallCount(0);
|
|
|
|
static std::atomic<int> munmapMockCallCount(0);
|
2018-08-01 20:47:14 +08:00
|
|
|
|
|
|
|
off_t lseekMock(int fd, off_t offset, int whence) noexcept {
|
|
|
|
lseekCalledCount++;
|
|
|
|
return lseekReturn;
|
|
|
|
}
|
|
|
|
void *mmapMock(void *addr, size_t length, int prot, int flags,
|
|
|
|
int fd, long offset) noexcept {
|
|
|
|
mmapMockCallCount++;
|
|
|
|
return reinterpret_cast<void *>(0x1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
int munmapMock(void *addr, size_t length) noexcept {
|
|
|
|
munmapMockCallCount++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int closeMock(int) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestedDrmMemoryManager : public DrmMemoryManager {
|
|
|
|
public:
|
2018-11-30 18:01:33 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr;
|
2018-08-01 20:47:14 +08:00
|
|
|
using DrmMemoryManager::allocUserptr;
|
|
|
|
using DrmMemoryManager::setDomainCpu;
|
|
|
|
using DrmMemoryManager::sharingBufferObjects;
|
|
|
|
|
2018-10-01 22:10:54 +08:00
|
|
|
TestedDrmMemoryManager(Drm *drm, ExecutionEnvironment &executionEnvironment) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {
|
2018-08-01 20:47:14 +08:00
|
|
|
this->lseekFunction = &lseekMock;
|
|
|
|
this->mmapFunction = &mmapMock;
|
|
|
|
this->munmapFunction = &munmapMock;
|
|
|
|
this->closeFunction = &closeMock;
|
|
|
|
lseekReturn = 4096;
|
|
|
|
lseekCalledCount = 0;
|
|
|
|
mmapMockCallCount = 0;
|
|
|
|
munmapMockCallCount = 0;
|
2018-10-24 14:46:54 +08:00
|
|
|
hostPtrManager.reset(new MockHostPtrManager);
|
2018-08-01 20:47:14 +08:00
|
|
|
};
|
2018-10-01 22:10:54 +08:00
|
|
|
TestedDrmMemoryManager(Drm *drm, bool allowForcePin, bool validateHostPtrMemory, ExecutionEnvironment &executionEnvironment) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerInactive, allowForcePin, validateHostPtrMemory, executionEnvironment) {
|
2018-08-01 20:47:14 +08:00
|
|
|
this->lseekFunction = &lseekMock;
|
|
|
|
this->mmapFunction = &mmapMock;
|
|
|
|
this->munmapFunction = &munmapMock;
|
|
|
|
this->closeFunction = &closeMock;
|
|
|
|
lseekReturn = 4096;
|
|
|
|
lseekCalledCount = 0;
|
|
|
|
mmapMockCallCount = 0;
|
|
|
|
munmapMockCallCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unreference(BufferObject *bo) {
|
|
|
|
DrmMemoryManager::unreference(bo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void injectPinBB(BufferObject *newPinBB) {
|
|
|
|
BufferObject *currentPinBB = pinBB;
|
|
|
|
pinBB = nullptr;
|
|
|
|
DrmMemoryManager::unreference(currentPinBB);
|
|
|
|
pinBB = newPinBB;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmGemCloseWorker *getgemCloseWorker() { return this->gemCloseWorker.get(); }
|
2018-11-16 02:43:12 +08:00
|
|
|
void forceLimitedRangeAllocator(uint64_t range) { initInternalRangeAllocator(range); }
|
2018-08-01 20:47:14 +08:00
|
|
|
|
2018-11-16 02:43:12 +08:00
|
|
|
Allocator32bit *getDrmInternal32BitAllocator() const { return internal32bitAllocator.get(); }
|
|
|
|
AllocatorLimitedRange *getDrmLimitedRangeAllocator() const { return limitedGpuAddressRangeAllocator.get(); }
|
2018-08-01 20:47:14 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|