blob: 9c0f172671a4a2c7144e8d388096b1a1010db546 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jefferyc5da1482017-04-12 14:49:07 +09303
4#include <assert.h>
5#include <sys/mman.h>
6
Andrew Jeffery26558db2018-08-10 00:22:38 +09307#include "mboxd.h"
Andrew Jeffery457a6e52018-08-08 11:21:08 +09308#include "transport_mbox.h"
Andrew Jefferyc5da1482017-04-12 14:49:07 +09309
10#include "test/mbox.h"
11#include "test/system.h"
12
13static const uint8_t get_info[] = {
14 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
15 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
16};
17
18static const uint8_t create_write_window[] = {
19 0x06, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
21};
22
23static const uint8_t mark_write_erased[] = {
24 0x0a, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
25 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
26};
27
28static const uint8_t response[] = {
29 0x0a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
31};
32
33static const uint8_t write_flush[] = {
34 0x08, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
36};
37
38const uint8_t start_data[] = { 0xaa, 0x55, 0xaa };
39const uint8_t finish_data[] = { 0xaa, 0xff, 0xaa };
40
41#define MEM_SIZE sizeof(start_data)
42#define ERASE_SIZE 1
43#define N_WINDOWS 1
44#define WINDOW_SIZE sizeof(start_data)
45
46int main(void)
47{
48 struct mbox_context *ctx;
49 uint8_t *map;
50 int rc;
51
52 system_set_reserved_size(MEM_SIZE);
53 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
54
55 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
56 rc = mbox_set_mtd_data(ctx, start_data, sizeof(start_data));
57 assert(rc == 0);
58
59 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
60 assert(rc == 1);
61
62 rc = mbox_command_dispatch(ctx, create_write_window,
63 sizeof(create_write_window));
64 assert(rc == 1);
65
66 rc = mbox_command_dispatch(ctx, mark_write_erased,
67 sizeof(mark_write_erased));
68 assert(rc == 1);
69
70 rc = mbox_cmp(ctx, response, sizeof(response));
71 assert(rc == 0);
72
73 rc = memcmp(ctx->mem, finish_data, sizeof(finish_data));
74 assert(rc == 0);
75
76 map = mmap(NULL, MEM_SIZE, PROT_READ, MAP_PRIVATE,
77 ctx->fds[MTD_FD].fd, 0);
78 assert(map != MAP_FAILED);
79
80 rc = memcmp(start_data, map, sizeof(start_data));
81 assert(rc == 0);
82
83 rc = mbox_command_dispatch(ctx, write_flush, sizeof(write_flush));
84 assert(rc == 1);
85
86 rc = memcmp(finish_data, map, sizeof(finish_data));
87 assert(rc == 0);
88
89 return rc;
90};