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 | d8f24ef | 2017-04-12 14:43:57 +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 | d8f24ef | 2017-04-12 14:43:57 +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[] = { |
| 18 | 0x04, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 20 | }; |
| 21 | |
| 22 | static const uint8_t close_window_no_flag[] = { |
| 23 | 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 25 | }; |
| 26 | |
| 27 | static const uint8_t response_no_flag[] = { |
| 28 | 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
| 30 | }; |
| 31 | |
| 32 | static const uint8_t close_window_short_lifetime[] = { |
| 33 | 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 35 | }; |
| 36 | |
| 37 | static const uint8_t response_short_lifetime[] = { |
| 38 | 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
| 40 | }; |
| 41 | |
| 42 | #define MEM_SIZE 3 |
| 43 | #define ERASE_SIZE 1 |
| 44 | #define N_WINDOWS 1 |
| 45 | #define WINDOW_SIZE 3 |
| 46 | |
| 47 | int setup(struct mbox_context *ctx) |
| 48 | { |
| 49 | int rc; |
| 50 | |
| 51 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 52 | assert(rc == 1); |
| 53 | |
| 54 | rc = mbox_command_dispatch(ctx, create_read_window, |
| 55 | sizeof(create_read_window)); |
| 56 | assert(rc == 1); |
| 57 | |
| 58 | return rc; |
| 59 | } |
| 60 | |
| 61 | int no_flag(struct mbox_context *ctx) |
| 62 | { |
| 63 | int rc; |
| 64 | |
| 65 | setup(ctx); |
| 66 | |
| 67 | rc = mbox_command_dispatch(ctx, close_window_no_flag, |
| 68 | sizeof(close_window_no_flag)); |
| 69 | assert(rc == 1); |
| 70 | |
| 71 | rc = mbox_cmp(ctx, response_no_flag, sizeof(response_no_flag)); |
| 72 | assert(rc == 0); |
| 73 | |
| 74 | return rc; |
| 75 | } |
| 76 | |
| 77 | int short_lifetime(struct mbox_context *ctx) |
| 78 | { |
| 79 | int rc; |
| 80 | |
| 81 | setup(ctx); |
| 82 | |
| 83 | rc = mbox_command_dispatch(ctx, close_window_short_lifetime, |
| 84 | sizeof(close_window_short_lifetime)); |
| 85 | assert(rc == 1); |
| 86 | |
| 87 | rc = mbox_cmp(ctx, response_short_lifetime, |
| 88 | sizeof(response_short_lifetime)); |
| 89 | assert(rc == 0); |
| 90 | |
| 91 | return rc; |
| 92 | } |
| 93 | |
| 94 | int main(void) |
| 95 | { |
| 96 | struct mbox_context *ctx; |
| 97 | |
| 98 | system_set_reserved_size(MEM_SIZE); |
| 99 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 100 | |
| 101 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 102 | |
| 103 | no_flag(ctx); |
| 104 | |
| 105 | short_lifetime(ctx); |
| 106 | |
| 107 | return 0; |
| 108 | }; |