Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 3 | |
| 4 | #include <assert.h> |
| 5 | #include <sys/mman.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/stat.h> |
| 8 | #include <unistd.h> |
| 9 | |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 10 | #include "mboxd.h" |
| 11 | #include "protocol.h" |
Andrew Jeffery | 457a6e5 | 2018-08-08 11:21:08 +0930 | [diff] [blame] | 12 | #include "transport_mbox.h" |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 13 | |
| 14 | #include "test/mbox.h" |
| 15 | #include "test/system.h" |
| 16 | |
| 17 | #define FLAGS 0xc3 |
| 18 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 19 | static const uint8_t get_info[] = { |
| 20 | 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 22 | }; |
| 23 | |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 24 | static const uint8_t command[] = { |
| 25 | 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS |
| 27 | }; |
| 28 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 29 | uint8_t data[3] = { 0xaa, 0x55, 0xaa }; |
| 30 | |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 31 | #define MEM_SIZE 3 |
| 32 | #define ERASE_SIZE 1 |
| 33 | #define N_WINDOWS 1 |
| 34 | #define WINDOW_SIZE 1 |
| 35 | |
| 36 | int main(void) |
| 37 | { |
| 38 | struct mbox_context *ctx; |
| 39 | struct stat details; |
| 40 | uint8_t *map; |
| 41 | int rc; |
| 42 | |
| 43 | system_set_reserved_size(MEM_SIZE); |
| 44 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 45 | |
| 46 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 47 | rc = mbox_set_mtd_data(ctx, data, sizeof(data)); |
| 48 | assert(rc == 0); |
| 49 | |
| 50 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 51 | assert(rc == 1); |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 52 | |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 53 | protocol_events_set(ctx, FLAGS); |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 54 | |
| 55 | rc = mbox_command_dispatch(ctx, command, sizeof(command)); |
| 56 | assert(rc == 1); |
| 57 | |
| 58 | rc = fstat(ctx->fds[MBOX_FD].fd, &details); |
| 59 | assert(rc == 0); |
| 60 | |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 61 | map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE, |
| 62 | ctx->fds[MBOX_FD].fd, 0); |
| 63 | assert(map != MAP_FAILED); |
| 64 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 65 | assert(details.st_size >= 16); |
| 66 | assert(map[15] == 0xc0); |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 67 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 68 | return 0; |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 69 | } |