From efeb096c409fe0d60d573661f1964be4d48aeaca Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Fri, 8 Sep 2023 13:34:48 -0700 Subject: [PATCH] libtrusty: Remove PAGE_SIZE usage bionic provides PAGE_SIZE macro which happens to also match the 4096 chunk size in the tips_test. PAGE_SIZE is being removed as no other libc provides this and Android is moving towards being page-size-agnostic. Use 4096 chunk size for tipc-tests; fix incorrect size in munmap cleanup; and add failure log for send-fd test. Test: tipc-test -t "send-fd" Bug: 294914413 Change-Id: I7e5ec6480fff6bc1b4e8eed57eadf081cf82a72f Signed-off-by: Kalesh Singh --- trusty/libtrusty/tipc-test/tipc_test.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/trusty/libtrusty/tipc-test/tipc_test.c b/trusty/libtrusty/tipc-test/tipc_test.c index 81c988110..0f5078753 100644 --- a/trusty/libtrusty/tipc-test/tipc_test.c +++ b/trusty/libtrusty/tipc-test/tipc_test.c @@ -44,6 +44,7 @@ static const char *closer2_name = "com.android.ipc-unittest.srv.closer2"; static const char *closer3_name = "com.android.ipc-unittest.srv.closer3"; static const char *main_ctrl_name = "com.android.ipc-unittest.ctrl"; static const char* receiver_name = "com.android.trusty.memref.receiver"; +static const size_t memref_chunk_size = 4096; static const char* _sopts = "hsvDS:t:r:m:b:"; /* clang-format off */ @@ -878,7 +879,7 @@ static int send_fd_test(void) { volatile char* buf = MAP_FAILED; BufferAllocator* allocator = NULL; - const size_t num_pages = 10; + const size_t num_chunks = 10; fd = tipc_connect(dev_name, receiver_name); if (fd < 0) { @@ -894,7 +895,7 @@ static int send_fd_test(void) { goto cleanup; } - size_t buf_size = PAGE_SIZE * num_pages; + size_t buf_size = memref_chunk_size * num_chunks; dma_buf = DmabufHeapAlloc(allocator, "system", buf_size, 0, 0 /* legacy align */); if (dma_buf < 0) { ret = dma_buf; @@ -927,13 +928,17 @@ static int send_fd_test(void) { tipc_close(fd); ret = 0; - for (size_t skip = 0; skip < num_pages; skip++) { - ret |= strcmp("Hello from Trusty!", (const char*)&buf[skip * PAGE_SIZE]) ? (-1) : 0; + for (size_t skip = 0; skip < num_chunks; skip++) { + int cmp = strcmp("Hello from Trusty!", + (const char*)&buf[skip * memref_chunk_size]) ? (-1) : 0; + if (cmp) + fprintf(stderr, "Failed: Unexpected content at page %zu in dmabuf\n", skip); + ret |= cmp; } cleanup: if (buf != MAP_FAILED) { - munmap((char*)buf, PAGE_SIZE); + munmap((char*)buf, buf_size); } close(dma_buf); if (allocator) {