diff options
Diffstat (limited to 'trusty/libtrusty/tipc-test/tipc_test.c')
-rw-r--r-- | trusty/libtrusty/tipc-test/tipc_test.c | 128 |
1 files changed, 25 insertions, 103 deletions
diff --git a/trusty/libtrusty/tipc-test/tipc_test.c b/trusty/libtrusty/tipc-test/tipc_test.c index 29c6f939f..d20d4eebf 100644 --- a/trusty/libtrusty/tipc-test/tipc_test.c +++ b/trusty/libtrusty/tipc-test/tipc_test.c @@ -21,12 +21,8 @@ #include <stdlib.h> #include <unistd.h> #include <getopt.h> -#define __USE_GNU -#include <sys/mman.h> #include <sys/uio.h> -#include <BufferAllocator/BufferAllocatorWrapper.h> - #include <trusty/tipc.h> #define TIPC_DEFAULT_DEVNAME "/dev/trusty-ipc-dev0" @@ -43,7 +39,6 @@ static const char *closer1_name = "com.android.ipc-unittest.srv.closer1"; 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 char *_sopts = "hsvD:t:r:m:b:"; static const struct option _lopts[] = { @@ -71,25 +66,25 @@ static const char *usage = "\n" ; -static const char* usage_long = - "\n" - "The following tests are available:\n" - " connect - connect to datasink service\n" - " connect_foo - connect to non existing service\n" - " burst_write - send messages to datasink service\n" - " echo - send/receive messages to echo service\n" - " select - test select call\n" - " blocked_read - test blocked read\n" - " closer1 - connection closed by remote (test1)\n" - " closer2 - connection closed by remote (test2)\n" - " closer3 - connection closed by remote (test3)\n" - " ta2ta-ipc - execute TA to TA unittest\n" - " dev-uuid - print device uuid\n" - " ta-access - test ta-access flags\n" - " writev - writev test\n" - " readv - readv test\n" - " send-fd - transmit dma_buf to trusty, use as shm\n" - "\n"; +static const char *usage_long = +"\n" +"The following tests are available:\n" +" connect - connect to datasink service\n" +" connect_foo - connect to non existing service\n" +" burst_write - send messages to datasink service\n" +" echo - send/receive messages to echo service\n" +" select - test select call\n" +" blocked_read - test blocked read\n" +" closer1 - connection closed by remote (test1)\n" +" closer2 - connection closed by remote (test2)\n" +" closer3 - connection closed by remote (test3)\n" +" ta2ta-ipc - execute TA to TA unittest\n" +" dev-uuid - print device uuid\n" +" ta-access - test ta-access flags\n" +" writev - writev test\n" +" readv - readv test\n" +"\n" +; static uint opt_repeat = 1; static uint opt_msgsize = 32; @@ -890,77 +885,6 @@ static int readv_test(uint repeat, uint msgsz, bool var) return 0; } -static int send_fd_test(void) { - int ret; - int dma_buf = -1; - int fd = -1; - volatile char* buf = MAP_FAILED; - BufferAllocator* allocator = NULL; - - const size_t num_pages = 10; - - fd = tipc_connect(dev_name, receiver_name); - if (fd < 0) { - fprintf(stderr, "Failed to connect to test support TA - is it missing?\n"); - ret = -1; - goto cleanup; - } - - allocator = CreateDmabufHeapBufferAllocator(); - if (!allocator) { - fprintf(stderr, "Failed to create dma-buf allocator.\n"); - ret = -1; - goto cleanup; - } - - size_t buf_size = PAGE_SIZE * num_pages; - dma_buf = DmabufHeapAlloc(allocator, "system", buf_size, 0, 0 /* legacy align */); - if (dma_buf < 0) { - ret = dma_buf; - fprintf(stderr, "Failed to create dma-buf fd of size %zu err (%d)\n", buf_size, ret); - goto cleanup; - } - - buf = mmap(0, buf_size, PROT_READ | PROT_WRITE, MAP_SHARED, dma_buf, 0); - if (buf == MAP_FAILED) { - fprintf(stderr, "Failed to map dma-buf: %s\n", strerror(errno)); - ret = -1; - goto cleanup; - } - - strcpy((char*)buf, "From NS"); - - struct trusty_shm shm = { - .fd = dma_buf, - .transfer = TRUSTY_SHARE, - }; - - ssize_t rc = tipc_send(fd, NULL, 0, &shm, 1); - if (rc < 0) { - fprintf(stderr, "tipc_send failed: %zd\n", rc); - ret = rc; - goto cleanup; - } - char c; - read(fd, &c, 1); - 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; - } - -cleanup: - if (buf != MAP_FAILED) { - munmap((char*)buf, PAGE_SIZE); - } - close(dma_buf); - if (allocator) { - FreeDmabufHeapBufferAllocator(allocator); - } - tipc_close(fd); - return ret; -} int main(int argc, char **argv) { @@ -1009,12 +933,10 @@ int main(int argc, char **argv) rc = writev_test(opt_repeat, opt_msgsize, opt_variable); } else if (strcmp(test_name, "readv") == 0) { rc = readv_test(opt_repeat, opt_msgsize, opt_variable); - } else if (strcmp(test_name, "send-fd") == 0) { - rc = send_fd_test(); - } else { - fprintf(stderr, "Unrecognized test name '%s'\n", test_name); - print_usage_and_exit(argv[0], EXIT_FAILURE, true); - } - - return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + } else { + fprintf(stderr, "Unrecognized test name '%s'\n", test_name); + print_usage_and_exit(argv[0], EXIT_FAILURE, true); + } + + return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } |