Extended DRM memory manager with function to copy memory to allocation

Related-To: NEO-2687

Change-Id: I2cd20c1d59dc0c28609fca7a11a5d805e2f21de4
This commit is contained in:
Milczarek, Slawomir
2019-07-07 20:33:17 +02:00
committed by sys_ocldev
parent a38e9da034
commit 6b77f94275
12 changed files with 85 additions and 16 deletions

View File

@ -290,9 +290,7 @@ class DrmMockCustom : public Drm {
} 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);
ioctlExtra(request, arg);
}
if (ext->no != -1 && ext->no == ioctl_cnt.total.load()) {
@ -303,6 +301,16 @@ class DrmMockCustom : public Drm {
return ioctl_res.load();
};
virtual int ioctlExtra(unsigned long request, void *arg) {
switch (request) {
default:
std::cout << "unexpected IOCTL: " << std::hex << request << std::endl;
UNRECOVERABLE_IF(true);
break;
}
return 0;
}
IoctlResExt NONE = {-1, 0};
void reset() {
ioctl_res = 0;

View File

@ -8,12 +8,14 @@
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/os_interface/linux/drm_memory_manager.h"
#include "runtime/os_interface/linux/os_interface.h"
#include "test.h"
#include "unit_tests/mocks/linux/mock_drm_memory_manager.h"
#include "unit_tests/mocks/mock_execution_environment.h"
#include "unit_tests/os_interface/linux/drm_memory_manager_tests.h"
#include "gtest/gtest.h"
using namespace NEO;
using namespace ::testing;
using AllocationData = TestedDrmMemoryManager::AllocationData;
@ -32,3 +34,34 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIs
EXPECT_EQ(nullptr, allocation);
EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status);
}
using DrmMemoryManagerWithLocalMemoryTest = Test<DrmMemoryManagerWithLocalMemoryFixture>;
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnAllocationInLocalMemoryThenReturnNullPtr) {
DrmAllocation drmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory, false);
auto ptr = memoryManager->lockResource(&drmAllocation);
EXPECT_EQ(nullptr, ptr);
memoryManager->unlockResource(&drmAllocation);
}
using DrmMemoryManagerTest = Test<DrmMemoryManagerFixture>;
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
std::vector<uint8_t> dataToCopy(MemoryConstants::pageSize, 1u);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({dataToCopy.size(), GraphicsAllocation::AllocationType::BUFFER});
ASSERT_NE(nullptr, allocation);
auto ret = memoryManager->copyMemoryToAllocation(allocation, dataToCopy.data(), dataToCopy.size());
EXPECT_TRUE(ret);
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), dataToCopy.data(), dataToCopy.size()));
memoryManager->freeGraphicsMemory(allocation);
}

View File

@ -1890,7 +1890,7 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferOb
auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false);
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setDrm(mock);
executionEnvironment->osInterface->get()->setDrm(mock.get());
auto testedCsr = new TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
device->resetCommandStreamReceiver(testedCsr);
@ -1918,7 +1918,7 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf
auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false);
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setDrm(mock);
executionEnvironment->osInterface->get()->setDrm(mock.get());
auto testedCsr = new TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
device->resetCommandStreamReceiver(testedCsr);

View File

@ -32,19 +32,23 @@ class DrmMemoryManagerBasic : public ::testing::Test {
class DrmMemoryManagerFixture : public MemoryManagementFixture {
public:
std::unique_ptr<DrmMockCustom> mock;
TestedDrmMemoryManager *memoryManager = nullptr;
DrmMockCustom *mock;
MockDevice *device = nullptr;
void SetUp() override {
SetUp(new DrmMockCustom, false);
}
void SetUp(DrmMockCustom *mock, bool localMemoryEnabled) {
MemoryManagementFixture::SetUp();
this->mock = new DrmMockCustom;
this->mock = std::unique_ptr<DrmMockCustom>(mock);
executionEnvironment = new MockExecutionEnvironment(*platformDevices);
executionEnvironment->incRefInternal();
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setDrm(mock);
memoryManager = new (std::nothrow) TestedDrmMemoryManager(*executionEnvironment);
memoryManager = new (std::nothrow) TestedDrmMemoryManager(localMemoryEnabled, false, false, *executionEnvironment);
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
if (memoryManager->getgemCloseWorker()) {
@ -60,8 +64,6 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
this->mock->testIoctls();
delete this->mock;
this->mock = nullptr;
MemoryManagementFixture::TearDown();
}
@ -71,6 +73,16 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
AllocationData allocationData;
};
class DrmMemoryManagerWithLocalMemoryFixture : public DrmMemoryManagerFixture {
public:
void SetUp() override {
DrmMemoryManagerFixture::SetUp(new DrmMockCustom, true);
}
void TearDown() override {
DrmMemoryManagerFixture::TearDown();
}
};
class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation {
public:
std::unique_ptr<TestedDrmMemoryManager> memoryManager;