blob: b0e246e1c2a30b77901339dea17a87ed78ca0f04 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jefferyccaec502017-04-12 14:42:36 +09303
4#include <assert.h>
Andrew Jeffery26558db2018-08-10 00:22:38 +09305#include <string.h>
Andrew Jefferyccaec502017-04-12 14:42:36 +09306
Andrew Jeffery26558db2018-08-10 00:22:38 +09307#include "mboxd.h"
Andrew Jeffery457a6e52018-08-08 11:21:08 +09308#include "transport_mbox.h"
Andrew Jefferyccaec502017-04-12 14:42:36 +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 response[] = {
24 0x06, 0x01, 0xfd, 0xff, 0x03, 0x00, 0x00, 0x00,
25 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
26};
27
28uint8_t data[3] = { 0xaa, 0x55, 0xaa };
29
30#define MEM_SIZE sizeof(data)
31#define ERASE_SIZE 1
32#define N_WINDOWS 1
33#define WINDOW_SIZE sizeof(data)
34
35int main(void)
36{
37 struct mbox_context *ctx;
38 int rc;
39
40 system_set_reserved_size(MEM_SIZE);
41 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
42
43 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
44 rc = mbox_set_mtd_data(ctx, data, sizeof(data));
45 assert(rc == 0);
46
47 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
48 assert(rc == 1);
49
50 rc = mbox_command_dispatch(ctx, create_write_window,
51 sizeof(create_write_window));
52 assert(rc == 1);
53
54 rc = mbox_cmp(ctx, response, sizeof(response));
55 assert(rc == 0);
56
57 rc = memcmp(ctx->mem, data, sizeof(data));
58 assert(rc == 0);
59
60 return rc;
61};