From b48c1a45409fced91ace381d9fc333b05097f93c Mon Sep 17 00:00:00 2001 From: Yuanzheng Song Date: Mon, 13 Jun 2022 10:09:47 +0800 Subject: [PATCH] add heapFlags field into DmabufHeapBuffer issue: #I5BWYV Signed-off-by: Yuanzheng Song --- libdmabufheap/include/dmabuf_alloc.h | 1 + libdmabufheap/src/dmabuf_alloc.c | 3 ++- .../unittest/libdmabufheap/dmabuf_alloc_test.cpp | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libdmabufheap/include/dmabuf_alloc.h b/libdmabufheap/include/dmabuf_alloc.h index 7e15867..07ec54b 100644 --- a/libdmabufheap/include/dmabuf_alloc.h +++ b/libdmabufheap/include/dmabuf_alloc.h @@ -37,6 +37,7 @@ typedef enum { typedef struct { unsigned int fd; size_t size; + unsigned int heapFlags; } DmabufHeapBuffer; int DmabufHeapOpen(const char *heapName); diff --git a/libdmabufheap/src/dmabuf_alloc.c b/libdmabufheap/src/dmabuf_alloc.c index 8230882..eddf211 100644 --- a/libdmabufheap/src/dmabuf_alloc.c +++ b/libdmabufheap/src/dmabuf_alloc.c @@ -36,7 +36,7 @@ static bool IsHeapNameValid(const char *heapName) { if ((heapName == NULL) || (strlen(heapName) == 0) || - (strlen(heapName) >= HEAP_NAME_MAX_LEN)) { + (strlen(heapName) > HEAP_NAME_MAX_LEN)) { return false; } @@ -87,6 +87,7 @@ int DmabufHeapBufferAlloc(unsigned int heapFd, DmabufHeapBuffer *buffer) struct dma_heap_allocation_data data = { .len = buffer->size, .fd_flags = O_RDWR | O_CLOEXEC, + .heap_flags = buffer->heapFlags, }; int ret = ioctl(heapFd, DMA_HEAP_IOCTL_ALLOC, &data); if (ret < 0) { diff --git a/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp b/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp index e6daa2e..0cd07b3 100644 --- a/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp +++ b/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp @@ -61,7 +61,7 @@ HWTEST_F(DmabufAllocTest, AllocSingleBuffer, TestSize.Level1) int heapFd = DmabufHeapOpen("system"); ASSERT_GE(heapFd, 0); - DmabufHeapBuffer buffer = { .size = BUFFER_SIZE }; + DmabufHeapBuffer buffer = { .size = BUFFER_SIZE, .heapFlags = 0 }; ASSERT_EQ(0, DmabufHeapBufferAlloc(heapFd, &buffer)); void *ptr = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0); @@ -87,7 +87,7 @@ HWTEST_F(DmabufAllocTest, ShareBufferBetweenProcess, Function|MediumTest|Level1) int heapFd = DmabufHeapOpen("system"); ASSERT_GE(heapFd, 0); - DmabufHeapBuffer buffer = { .size = BUFFER_SIZE }; + DmabufHeapBuffer buffer = { .size = BUFFER_SIZE, .heapFlags = 0 }; ASSERT_EQ(0, DmabufHeapBufferAlloc(heapFd, &buffer)); void *ptr = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0); @@ -168,7 +168,7 @@ HWTEST_F(DmabufAllocTest, BufferSyncWithWrongFd, Function|MediumTest|Level1) int heapFd = DmabufHeapOpen("system"); ASSERT_GE(heapFd, 0); - DmabufHeapBuffer buffer = { .size = BUFFER_SIZE }; + DmabufHeapBuffer buffer = { .size = BUFFER_SIZE, .heapFlags = 0 }; ASSERT_EQ(0, DmabufHeapBufferAlloc(heapFd, &buffer)); void *ptr = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0); @@ -192,7 +192,7 @@ HWTEST_F(DmabufAllocTest, BufferSyncWithWrongSyncType, Function|MediumTest|Level int heapFd = DmabufHeapOpen("system"); ASSERT_GE(heapFd, 0); - DmabufHeapBuffer buffer = { .size = BUFFER_SIZE }; + DmabufHeapBuffer buffer = { .size = BUFFER_SIZE, .heapFlags = 0 }; ASSERT_EQ(0, DmabufHeapBufferAlloc(heapFd, &buffer)); void *ptr = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0); @@ -214,7 +214,7 @@ HWTEST_F(DmabufAllocTest, SyncBufferTwice, Function|MediumTest|Level1) int heapFd = DmabufHeapOpen("system"); ASSERT_GE(heapFd, 0); - DmabufHeapBuffer buffer = { .size = BUFFER_SIZE }; + DmabufHeapBuffer buffer = { .size = BUFFER_SIZE, .heapFlags = 0 }; ASSERT_EQ(0, DmabufHeapBufferAlloc(heapFd, &buffer)); void *ptr = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0); @@ -244,7 +244,7 @@ HWTEST_F(DmabufAllocTest, ExchangeBufferSyncOrder, Function|MediumTest|Level1) int heapFd = DmabufHeapOpen("system"); ASSERT_GE(heapFd, 0); - DmabufHeapBuffer buffer = { .size = BUFFER_SIZE }; + DmabufHeapBuffer buffer = { .size = BUFFER_SIZE, .heapFlags = 0 }; ASSERT_EQ(0, DmabufHeapBufferAlloc(heapFd, &buffer)); void *ptr = mmap(NULL, BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, buffer.fd, 0); -- Gitee