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 | 9d4b888 | 2017-04-13 15:39:45 +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 | 9d4b888 | 2017-04-13 15:39:45 +0930 | [diff] [blame] | 8 | |
| 9 | #include "test/mbox.h" |
| 10 | #include "test/system.h" |
| 11 | |
| 12 | static const uint8_t get_mbox_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 invalid[] = { |
| 18 | 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 20 | }; |
| 21 | |
| 22 | static const uint8_t response[] = { |
| 23 | 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, |
| 25 | }; |
| 26 | |
| 27 | #define MEM_SIZE 3 |
| 28 | #define ERASE_SIZE 1 |
| 29 | #define N_WINDOWS 1 |
| 30 | #define WINDOW_SIZE 1 |
| 31 | |
| 32 | int invalid_uninitialised(struct mbox_context *ctx) |
| 33 | { |
| 34 | int rc; |
| 35 | |
| 36 | rc = mbox_command_dispatch(ctx, invalid, sizeof(invalid)); |
| 37 | assert(rc == 2); |
| 38 | |
| 39 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 40 | assert(rc == 0); |
| 41 | |
| 42 | return rc; |
| 43 | } |
| 44 | |
| 45 | int invalid_initialised(struct mbox_context *ctx) |
| 46 | { |
| 47 | int rc; |
| 48 | |
| 49 | rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info)); |
| 50 | assert(rc == 1); |
| 51 | |
| 52 | rc = mbox_command_dispatch(ctx, invalid, sizeof(invalid)); |
| 53 | assert(rc == 2); |
| 54 | |
| 55 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 56 | assert(rc == 0); |
| 57 | |
| 58 | return rc; |
| 59 | } |
| 60 | |
| 61 | int main(void) |
| 62 | { |
| 63 | struct mbox_context *ctx; |
| 64 | |
| 65 | system_set_reserved_size(MEM_SIZE); |
| 66 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 67 | |
| 68 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 69 | |
| 70 | invalid_uninitialised(ctx); |
| 71 | |
| 72 | invalid_initialised(ctx); |
| 73 | |
| 74 | return 0; |
| 75 | } |