blob: 95cff4b1b54dc9387551f88bf5cb888cca2cd588 [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"
Evan Lojewskif1e547c2019-03-14 14:34:33 +10308#include "mtd/backend.h"
Andrew Jeffery457a6e52018-08-08 11:21:08 +09309#include "transport_mbox.h"
Andrew Jefferyc5da1482017-04-12 14:49:07 +093010
11#include "test/mbox.h"
12#include "test/system.h"
13
14static const uint8_t get_info[] = {
15 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
16 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
17};
18
19static const uint8_t create_write_window[] = {
20 0x06, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
21 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
22};
23
24static const uint8_t mark_write_erased[] = {
25 0x0a, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
27};
28
29static const uint8_t response[] = {
30 0x0a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
32};
33
34static const uint8_t write_flush[] = {
35 0x08, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
37};
38
39const uint8_t start_data[] = { 0xaa, 0x55, 0xaa };
40const uint8_t finish_data[] = { 0xaa, 0xff, 0xaa };
41
42#define MEM_SIZE sizeof(start_data)
43#define ERASE_SIZE 1
44#define N_WINDOWS 1
45#define WINDOW_SIZE sizeof(start_data)
46
47int main(void)
48{
49 struct mbox_context *ctx;
50 uint8_t *map;
51 int rc;
52
53 system_set_reserved_size(MEM_SIZE);
54 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
55
56 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
57 rc = mbox_set_mtd_data(ctx, start_data, sizeof(start_data));
58 assert(rc == 0);
59
60 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
61 assert(rc == 1);
62
63 rc = mbox_command_dispatch(ctx, create_write_window,
64 sizeof(create_write_window));
65 assert(rc == 1);
66
67 rc = mbox_command_dispatch(ctx, mark_write_erased,
68 sizeof(mark_write_erased));
69 assert(rc == 1);
70
71 rc = mbox_cmp(ctx, response, sizeof(response));
72 assert(rc == 0);
73
74 rc = memcmp(ctx->mem, finish_data, sizeof(finish_data));
75 assert(rc == 0);
76
77 map = mmap(NULL, MEM_SIZE, PROT_READ, MAP_PRIVATE,
Evan Lojewskif1e547c2019-03-14 14:34:33 +103078 ((struct mtd_data *)ctx->backend.priv)->fd, 0);
Andrew Jefferyc5da1482017-04-12 14:49:07 +093079 assert(map != MAP_FAILED);
80
81 rc = memcmp(start_data, map, sizeof(start_data));
82 assert(rc == 0);
83
84 rc = mbox_command_dispatch(ctx, write_flush, sizeof(write_flush));
85 assert(rc == 1);
86
87 rc = memcmp(finish_data, map, sizeof(finish_data));
88 assert(rc == 0);
89
90 return rc;
91};