From 7b8b4db88b3cee4a283a15944ba8b82b20a86600 Mon Sep 17 00:00:00 2001 From: David Riley Date: Wed, 17 Apr 2019 16:19:20 -0700 Subject: [PATCH] vtest: add functions to read from buffer Signed-off-by: David Riley Reviewed-By: Gert Wollny --- vtest/vtest.h | 7 +++++++ vtest/vtest_renderer.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/vtest/vtest.h b/vtest/vtest.h index 73e8a2b..8b942cd 100644 --- a/vtest/vtest.h +++ b/vtest/vtest.h @@ -27,9 +27,15 @@ #include +struct vtest_buffer { + const void *buffer; + int size; +}; + struct vtest_input { union { int fd; + struct vtest_buffer *buffer; } data; int (*read)(struct vtest_input *input, void *buf, int size); }; @@ -50,6 +56,7 @@ int vtest_transfer_put(uint32_t length_dw); int vtest_transfer_put2(uint32_t length_dw); int vtest_block_read(struct vtest_input *input, void *buf, int size); +int vtest_buf_read(struct vtest_input *input, void *buf, int size); int vtest_resource_busy_wait(uint32_t length_dw); int vtest_renderer_create_fence(void); diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index f5c6115..5fc705b 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -187,6 +187,20 @@ static int vtest_send_fd(int socket_fd, int fd) return 0; } +int vtest_buf_read(struct vtest_input *input, void *buf, int size) +{ + struct vtest_buffer *inbuf = input->data.buffer; + if (size > inbuf->size) { + return 0; + } + + memcpy(buf, inbuf->buffer, size); + inbuf->buffer += size; + inbuf->size -= size; + + return size; +} + int vtest_create_renderer(struct vtest_input *input, int out_fd, uint32_t length, int ctx_flags) {