blob: 0e3dd55f9d0b54ef87bd7e1857e7c575fff2d900 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jefferyd8f24ef2017-04-12 14:43:57 +09303
4#include <assert.h>
5
6#include "mbox.h"
7#include "mboxd_msg.h"
8
9#include "test/mbox.h"
10#include "test/system.h"
11
12static 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
17static 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
22static 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
27static const uint8_t response_no_flag[] = {
28 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
30};
31
32static 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
37static 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
47int 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
61int 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
77int 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
94int 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};