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 | b34cc54 | 2017-04-13 16:09:19 +0930 | [diff] [blame] | 3 | |
| 4 | #include <assert.h> |
| 5 | |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 6 | #include "mboxd.h" |
Andrew Jeffery | 457a6e5 | 2018-08-08 11:21:08 +0930 | [diff] [blame] | 7 | #include "transport_mbox.h" |
Andrew Jeffery | b34cc54 | 2017-04-13 16:09:19 +0930 | [diff] [blame] | 8 | |
| 9 | #include "test/mbox.h" |
| 10 | #include "test/system.h" |
| 11 | |
| 12 | static const uint8_t get_info[] = { |
| 13 | 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 15 | }; |
| 16 | |
| 17 | static const uint8_t create_read_window_block_0[] = { |
| 18 | 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 20 | }; |
| 21 | |
| 22 | static const uint8_t create_read_window_block_1[] = { |
| 23 | 0x04, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 25 | }; |
| 26 | |
| 27 | static const uint8_t create_read_window_block_2[] = { |
| 28 | 0x04, 0x03, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 30 | }; |
| 31 | |
| 32 | uint8_t data[] = { 0x00, 0x01, 0x02 }; |
| 33 | |
| 34 | #define MEM_SIZE sizeof(data) |
| 35 | #define ERASE_SIZE 1 |
| 36 | #define N_WINDOWS MEM_SIZE - 1 |
| 37 | #define WINDOW_SIZE 1 |
| 38 | |
| 39 | int main(void) |
| 40 | { |
| 41 | struct mbox_context *ctx; |
| 42 | int rc; |
| 43 | int i; |
| 44 | |
| 45 | system_set_reserved_size(N_WINDOWS); |
| 46 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 47 | |
| 48 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 49 | rc = mbox_set_mtd_data(ctx, data, sizeof(data)); |
| 50 | assert(rc == 0); |
| 51 | |
| 52 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 53 | assert(rc == 1); |
| 54 | |
| 55 | /* Make each block appear in each window */ |
| 56 | for (i = 0; i < 2; i++) { |
| 57 | rc = mbox_command_dispatch(ctx, create_read_window_block_0, |
| 58 | sizeof(create_read_window_block_0)); |
| 59 | assert(rc == 1); |
| 60 | assert(((uint8_t *)ctx->mem)[(0 + i) & 1] == data[0]); |
| 61 | |
| 62 | rc = mbox_command_dispatch(ctx, create_read_window_block_1, |
| 63 | sizeof(create_read_window_block_1)); |
| 64 | assert(rc == 1); |
| 65 | assert(((uint8_t *)ctx->mem)[(1 + i) & 1] == data[1]); |
| 66 | |
| 67 | rc = mbox_command_dispatch(ctx, create_read_window_block_2, |
| 68 | sizeof(create_read_window_block_2)); |
| 69 | assert(rc == 1); |
| 70 | assert(((uint8_t *)ctx->mem)[(2 + i) & 1] == data[2]); |
| 71 | } |
| 72 | |
| 73 | return !(rc == 1); |
| 74 | }; |