blob: 498ac621d3540b923c7ea6c781dcda43fba42e2a [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jefferyaed3a5f2017-04-13 14:44:26 +09303
4#include <assert.h>
5
Andrew Jeffery26558db2018-08-10 00:22:38 +09306#include "mboxd.h"
Andrew Jeffery457a6e52018-08-08 11:21:08 +09307#include "transport_mbox.h"
Andrew Jefferyaed3a5f2017-04-13 14:44:26 +09308
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 mark_write_erased[] = {
23 0x0a, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
25};
26
27static const uint8_t response[] = {
28 0x0a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x07
30};
31
32uint8_t data[3] = { 0xaa, 0x55, 0xaa };
33
34#define MEM_SIZE sizeof(data)
35#define ERASE_SIZE 1
36#define N_WINDOWS 1
37#define WINDOW_SIZE sizeof(data)
38
39int main(void)
40{
41 struct mbox_context *ctx;
42 int rc;
43
44 system_set_reserved_size(MEM_SIZE);
45 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
46
47 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
48 rc = mbox_set_mtd_data(ctx, data, sizeof(data));
49 assert(rc == 0);
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 rc = mbox_command_dispatch(ctx, mark_write_erased,
59 sizeof(mark_write_erased));
60 assert(rc == 7);
61
62 rc = mbox_cmp(ctx, response, sizeof(response));
63 assert(rc == 0);
64
65 return rc;
66};