14fe996c2SAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
24fe996c2SAndrew Jeffery // Copyright (C) 2018 IBM Corp.
3b34cc542SAndrew Jeffery
4b34cc542SAndrew Jeffery #include <assert.h>
5b34cc542SAndrew Jeffery
626558dbbSAndrew Jeffery #include "mboxd.h"
7457a6e5fSAndrew Jeffery #include "transport_mbox.h"
8b34cc542SAndrew Jeffery
9b34cc542SAndrew Jeffery #include "test/mbox.h"
10b34cc542SAndrew Jeffery #include "test/system.h"
11b34cc542SAndrew Jeffery
12b34cc542SAndrew Jeffery static const uint8_t get_info[] = {
13b34cc542SAndrew Jeffery 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
14b34cc542SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
15b34cc542SAndrew Jeffery };
16b34cc542SAndrew Jeffery
17b34cc542SAndrew Jeffery static const uint8_t create_read_window_block_0[] = {
18b34cc542SAndrew Jeffery 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
19b34cc542SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
20b34cc542SAndrew Jeffery };
21b34cc542SAndrew Jeffery
22b34cc542SAndrew Jeffery static const uint8_t create_read_window_block_1[] = {
23b34cc542SAndrew Jeffery 0x04, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
24b34cc542SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
25b34cc542SAndrew Jeffery };
26b34cc542SAndrew Jeffery
27b34cc542SAndrew Jeffery static const uint8_t create_read_window_block_2[] = {
28b34cc542SAndrew Jeffery 0x04, 0x03, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
29b34cc542SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
30b34cc542SAndrew Jeffery };
31b34cc542SAndrew Jeffery
32b34cc542SAndrew Jeffery uint8_t data[] = { 0x00, 0x01, 0x02 };
33b34cc542SAndrew Jeffery
34b34cc542SAndrew Jeffery #define MEM_SIZE sizeof(data)
35b34cc542SAndrew Jeffery #define ERASE_SIZE 1
36b34cc542SAndrew Jeffery #define N_WINDOWS MEM_SIZE - 1
37b34cc542SAndrew Jeffery #define WINDOW_SIZE 1
38b34cc542SAndrew Jeffery
main(void)39b34cc542SAndrew Jeffery int main(void)
40b34cc542SAndrew Jeffery {
41b34cc542SAndrew Jeffery struct mbox_context *ctx;
42b34cc542SAndrew Jeffery int rc;
43b34cc542SAndrew Jeffery int i;
44b34cc542SAndrew Jeffery
45b34cc542SAndrew Jeffery system_set_reserved_size(N_WINDOWS);
46b34cc542SAndrew Jeffery system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
47b34cc542SAndrew Jeffery
48b34cc542SAndrew Jeffery ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
49b34cc542SAndrew Jeffery rc = mbox_set_mtd_data(ctx, data, sizeof(data));
50b34cc542SAndrew Jeffery assert(rc == 0);
51b34cc542SAndrew Jeffery
52b34cc542SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
53b34cc542SAndrew Jeffery assert(rc == 1);
54b34cc542SAndrew Jeffery
55b34cc542SAndrew Jeffery /* Make each block appear in each window */
56b34cc542SAndrew Jeffery for (i = 0; i < 2; i++) {
57b34cc542SAndrew Jeffery rc = mbox_command_dispatch(ctx, create_read_window_block_0,
58b34cc542SAndrew Jeffery sizeof(create_read_window_block_0));
59b34cc542SAndrew Jeffery assert(rc == 1);
60b34cc542SAndrew Jeffery assert(((uint8_t *)ctx->mem)[(0 + i) & 1] == data[0]);
61b34cc542SAndrew Jeffery
62b34cc542SAndrew Jeffery rc = mbox_command_dispatch(ctx, create_read_window_block_1,
63b34cc542SAndrew Jeffery sizeof(create_read_window_block_1));
64b34cc542SAndrew Jeffery assert(rc == 1);
65b34cc542SAndrew Jeffery assert(((uint8_t *)ctx->mem)[(1 + i) & 1] == data[1]);
66b34cc542SAndrew Jeffery
67b34cc542SAndrew Jeffery rc = mbox_command_dispatch(ctx, create_read_window_block_2,
68b34cc542SAndrew Jeffery sizeof(create_read_window_block_2));
69b34cc542SAndrew Jeffery assert(rc == 1);
70b34cc542SAndrew Jeffery assert(((uint8_t *)ctx->mem)[(2 + i) & 1] == data[2]);
71b34cc542SAndrew Jeffery }
72b34cc542SAndrew Jeffery
73b34cc542SAndrew Jeffery return !(rc == 1);
74*68a24c9eSPatrick Williams }
75