Return same fd handle on multiple calls to peekHandle

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2022-10-11 16:33:43 -07:00
committed by Compute-Runtime-Automation
parent 4055acaf01
commit 5c48e027b9
6 changed files with 72 additions and 4 deletions

View File

@@ -225,6 +225,7 @@ class DrmMock : public Drm {
int fdToHandleRetVal = 0;
//DRM_IOCTL_HANDLE_TO_FD
int32_t outputFd = 0;
bool incrementOutputFdAfterCall = false;
//DRM_IOCTL_I915_GEM_USERPTR
uint32_t returnHandle = 0;
uint64_t gpuMemSize = 3u * MemoryConstants::gigaByte;

View File

@@ -124,6 +124,9 @@ int DrmMockCustom::ioctl(DrmIoctl request, void *arg) {
inputHandle = handleToPrimeParams->handle;
inputFlags = handleToPrimeParams->flags;
handleToPrimeParams->fileDescriptor = outputFd;
if (incrementOutputFdAfterCall) {
outputFd++;
}
ioctl_cnt.handleToPrimeFd++;
} break;
case DrmIoctl::GemSetDomain: {

View File

@@ -191,6 +191,7 @@ class DrmMockCustom : public Drm {
//DRM_IOCTL_PRIME_HANDLE_TO_FD
uint32_t inputHandle = 0;
int32_t outputFd = 0;
bool incrementOutputFdAfterCall = false;
int32_t inputFlags = 0;
//DRM_IOCTL_I915_GEM_USERPTR
uint32_t returnHandle = 0;

View File

@@ -441,7 +441,7 @@ TEST_F(DrmMemoryManagerTest, WhenAskedAndAllowedAndBigAllocationThenPinAfterAllo
memoryManager->freeGraphicsMemory(alloc);
}
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledThenBoIsReturend) {
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledThenBoIsReturned) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
@@ -454,7 +454,32 @@ TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledThenBoIsReturend) {
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleWithHandleIdIsCalledThenBoIsReturend) {
TEST_F(DrmMemoryManagerTest, whenCallingPeekInternalHandleSeveralTimesThenSameHandleIsReturned) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
mock->ioctl_expected.handleToPrimeFd = 1;
uint64_t expectedFd = 1337;
mock->outputFd = static_cast<int32_t>(expectedFd);
mock->incrementOutputFdAfterCall = true;
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
ASSERT_NE(allocation->getBO(), nullptr);
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
uint64_t handle0 = allocation->peekInternalHandle(this->memoryManager);
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
uint64_t handle1 = allocation->peekInternalHandle(this->memoryManager);
uint64_t handle2 = allocation->peekInternalHandle(this->memoryManager);
ASSERT_EQ(handle0, expectedFd);
ASSERT_EQ(handle1, expectedFd);
ASSERT_EQ(handle2, expectedFd);
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleWithHandleIdIsCalledThenBoIsReturned) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
@@ -469,6 +494,32 @@ TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleWithHandleIdIsCalledThenBoIsR
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, whenCallingPeekInternalHandleWithIdSeveralTimesThenSameHandleIsReturned) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
mock->ioctl_expected.handleToPrimeFd = 1;
uint64_t expectedFd = 1337;
mock->outputFd = static_cast<int32_t>(expectedFd);
mock->incrementOutputFdAfterCall = true;
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
ASSERT_NE(allocation->getBO(), nullptr);
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
uint32_t handleId = 0;
uint64_t handle0 = allocation->peekInternalHandle(this->memoryManager, handleId);
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
uint64_t handle1 = allocation->peekInternalHandle(this->memoryManager, handleId);
uint64_t handle2 = allocation->peekInternalHandle(this->memoryManager, handleId);
ASSERT_EQ(handle0, expectedFd);
ASSERT_EQ(handle1, expectedFd);
ASSERT_EQ(handle2, expectedFd);
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, givenDrmContextIdWhenAllocationIsCreatedThenPinWithPassedDrmContextId) {
mock->ioctl_expected.gemUserptr = 2;
mock->ioctl_expected.execbuffer2 = 1;