blob: 6085f96c35a09e7ca203efd3f6e1973112ffebbb [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jeffery3e3cf282017-04-12 14:40:31 +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 response[] = {
23 0x04, 0x01, 0xfd, 0xff, 0x03, 0x00, 0x00, 0x00,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
25};
26
27uint8_t data[3] = { 0xaa, 0x55, 0xaa };
28
29#define MEM_SIZE sizeof(data)
30#define ERASE_SIZE 1
31#define N_WINDOWS 1
32#define WINDOW_SIZE sizeof(data)
33
34int main(void)
35{
36 struct mbox_context *ctx;
37 int rc;
38
39 system_set_reserved_size(MEM_SIZE);
40 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
41
42 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
43 rc = mbox_set_mtd_data(ctx, data, sizeof(data));
44 assert(rc == 0);
45
46 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
47 assert(rc == 1);
48
49 rc = mbox_command_dispatch(ctx, create_read_window,
50 sizeof(create_read_window));
51 assert(rc == 1);
52
53 rc = mbox_cmp(ctx, response, sizeof(response));
54 assert(rc == 0);
55
Andrew Jefferyccaec502017-04-12 14:42:36 +093056 /* Compare the reserved memory to the flash */
Andrew Jeffery3e3cf282017-04-12 14:40:31 +093057 rc = memcmp(ctx->mem, data, sizeof(data));
58 assert(rc == 0);
59
60 return rc;
61};