From ca1dfc9e902eddd8031baaaeb9dd6b3f4be4b1a2 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Thu, 22 Mar 2018 16:49:40 +1030 Subject: test: mbox: Add mbox_rspcpy() mbox_rspcpy() copies the mboxd response into a struct mbox_msg for use by the caller. This is useful in test cases that want to read contiguous chunks of the flash. mbox_rspcpy() allows them to extract the current window's offset and length to dynamically construct the CREATE_READ_WINDOW request for the subsequent blocks. Change-Id: I4d35889a0785b2d9ab737eba6755892caed53270 Signed-off-by: Andrew Jeffery --- test/mbox.c | 18 ++++++++++++++++++ test/mbox.h | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/mbox.c b/test/mbox.c index 3dc1611..6c62ddb 100644 --- a/test/mbox.c +++ b/test/mbox.c @@ -87,6 +87,24 @@ int mbox_cmp(struct mbox_context *context, const uint8_t *expected, size_t len) return rc; } +void mbox_rspcpy(struct mbox_context *context, struct mbox_msg *msg) +{ + struct stat details; + uint8_t *map; + int fd; + + fd = context->fds[MBOX_FD].fd; + fstat(fd, &details); + + map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + assert(map != MAP_FAILED); + assert(details.st_size >= (RESPONSE_OFFSET + RESPONSE_SIZE)); + + memcpy(msg, &map[RESPONSE_OFFSET], RESPONSE_SIZE); + + munmap(map, details.st_size); +} + int mbox_command_write(struct mbox_context *context, const uint8_t *command, size_t len) { diff --git a/test/mbox.h b/test/mbox.h index 5b89790..4344622 100644 --- a/test/mbox.h +++ b/test/mbox.h @@ -7,8 +7,9 @@ #include #include -#include "../common.h" -#include "../mbox.h" +#include "common.h" +#include "mbox.h" +#include "mboxd_msg.h" #include "tmpf.h" @@ -19,6 +20,8 @@ int mbox_set_mtd_data(struct mbox_context *context, const void *data, void mbox_dump(struct mbox_context *context); +void mbox_rspcpy(struct mbox_context *context, struct mbox_msg *msg); + int mbox_cmp(struct mbox_context *context, const uint8_t *expected, size_t len); int mbox_command_write(struct mbox_context *context, const uint8_t *command, -- cgit v1.2.1