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 | 3e3cf28 | 2017-04-12 14:40:31 +0930 | [diff] [blame] | 3 | |
| 4 | #include <assert.h> |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 5 | #include <string.h> |
Andrew Jeffery | 3e3cf28 | 2017-04-12 14:40:31 +0930 | [diff] [blame] | 6 | |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 7 | #include "mboxd.h" |
Andrew Jeffery | 457a6e5 | 2018-08-08 11:21:08 +0930 | [diff] [blame] | 8 | #include "transport_mbox.h" |
Andrew Jeffery | 3e3cf28 | 2017-04-12 14:40:31 +0930 | [diff] [blame] | 9 | |
| 10 | #include "test/mbox.h" |
| 11 | #include "test/system.h" |
| 12 | |
| 13 | static const uint8_t get_info[] = { |
| 14 | 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 16 | }; |
| 17 | |
| 18 | static const uint8_t create_read_window[] = { |
| 19 | 0x04, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 21 | }; |
| 22 | |
| 23 | static const uint8_t response[] = { |
| 24 | 0x04, 0x01, 0xfd, 0xff, 0x03, 0x00, 0x00, 0x00, |
| 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
| 26 | }; |
| 27 | |
| 28 | uint8_t data[3] = { 0xaa, 0x55, 0xaa }; |
| 29 | |
| 30 | #define MEM_SIZE sizeof(data) |
| 31 | #define ERASE_SIZE 1 |
| 32 | #define N_WINDOWS 1 |
| 33 | #define WINDOW_SIZE sizeof(data) |
| 34 | |
| 35 | int main(void) |
| 36 | { |
| 37 | struct mbox_context *ctx; |
| 38 | int rc; |
| 39 | |
| 40 | system_set_reserved_size(MEM_SIZE); |
| 41 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 42 | |
| 43 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 44 | rc = mbox_set_mtd_data(ctx, data, sizeof(data)); |
| 45 | assert(rc == 0); |
| 46 | |
| 47 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 48 | assert(rc == 1); |
| 49 | |
| 50 | rc = mbox_command_dispatch(ctx, create_read_window, |
| 51 | sizeof(create_read_window)); |
| 52 | assert(rc == 1); |
| 53 | |
| 54 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 55 | assert(rc == 0); |
| 56 | |
Andrew Jeffery | ccaec50 | 2017-04-12 14:42:36 +0930 | [diff] [blame] | 57 | /* Compare the reserved memory to the flash */ |
Andrew Jeffery | 3e3cf28 | 2017-04-12 14:40:31 +0930 | [diff] [blame] | 58 | rc = memcmp(ctx->mem, data, sizeof(data)); |
| 59 | assert(rc == 0); |
| 60 | |
| 61 | return rc; |
| 62 | }; |