summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-03-22 16:49:40 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-04-04 07:56:22 +0000
commitca1dfc9e902eddd8031baaaeb9dd6b3f4be4b1a2 (patch)
tree92277a999ff34837adfdfb78f2dc4abc39e3fc6b
parentcc0bd3c4a25b2359d77b36f9b60d3e5571282bc6 (diff)
downloadphosphor-mboxd-ca1dfc9e902eddd8031baaaeb9dd6b3f4be4b1a2.zip
phosphor-mboxd-ca1dfc9e902eddd8031baaaeb9dd6b3f4be4b1a2.tar.gz
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 <andrew@aj.id.au>
-rw-r--r--test/mbox.c18
-rw-r--r--test/mbox.h7
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 <stddef.h>
#include <stdint.h>
-#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,
OpenPOWER on IntegriCloud