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 | |
| 10 | #include "mbox.h" |
| 11 | #include "mboxd_msg.h" |
| 12 | |
| 13 | #include "test/mbox.h" |
| 14 | #include "test/system.h" |
| 15 | |
| 16 | #define FLAGS 0xc3 |
| 17 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 18 | static const uint8_t get_info[] = { |
| 19 | 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 21 | }; |
| 22 | |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 23 | static const uint8_t command[] = { |
| 24 | 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS |
| 26 | }; |
| 27 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 28 | uint8_t data[3] = { 0xaa, 0x55, 0xaa }; |
| 29 | |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 30 | #define MEM_SIZE 3 |
| 31 | #define ERASE_SIZE 1 |
| 32 | #define N_WINDOWS 1 |
| 33 | #define WINDOW_SIZE 1 |
| 34 | |
| 35 | int main(void) |
| 36 | { |
| 37 | struct mbox_context *ctx; |
| 38 | struct stat details; |
| 39 | uint8_t *map; |
| 40 | int rc; |
| 41 | |
| 42 | system_set_reserved_size(MEM_SIZE); |
| 43 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 44 | |
| 45 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 46 | rc = mbox_set_mtd_data(ctx, data, sizeof(data)); |
| 47 | assert(rc == 0); |
| 48 | |
| 49 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 50 | assert(rc == 1); |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 51 | |
| 52 | set_bmc_events(ctx, FLAGS, SET_BMC_EVENT); |
| 53 | |
| 54 | rc = mbox_command_dispatch(ctx, command, sizeof(command)); |
| 55 | assert(rc == 1); |
| 56 | |
| 57 | rc = fstat(ctx->fds[MBOX_FD].fd, &details); |
| 58 | assert(rc == 0); |
| 59 | |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 60 | map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE, |
| 61 | ctx->fds[MBOX_FD].fd, 0); |
| 62 | assert(map != MAP_FAILED); |
| 63 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 64 | assert(details.st_size >= 16); |
| 65 | assert(map[15] == 0xc0); |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 66 | |
Andrew Jeffery | b5685b3 | 2018-08-07 14:10:54 +0930 | [diff] [blame] | 67 | return 0; |
Andrew Jeffery | 1770ce8 | 2017-04-12 14:50:32 +0930 | [diff] [blame] | 68 | } |