1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright (C) 2018 IBM Corp.
3 
4 #include <assert.h>
5 #include <string.h>
6 
7 #include "mboxd.h"
8 #include "transport_mbox.h"
9 
10 #include "test/mbox.h"
11 #include "test/system.h"
12 
13 static 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 
18 static const uint8_t create_read_window[] = {
19 	0x04, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
20 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
21 };
22 
23 static const uint8_t response[] = {
24 	0x04, 0x01, 0xfd, 0xff, 0x03, 0x00, 0x00, 0x00,
25 	0x00, 0x00, 0x00, 0x00, 0x00, 0x01
26 };
27 
28 uint8_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 
main(void)35 int 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_read_window,
51 			sizeof(create_read_window));
52 	assert(rc == 1);
53 
54 	rc = mbox_cmp(ctx, response, sizeof(response));
55 	assert(rc == 0);
56 
57 	/* Compare the reserved memory to the flash */
58 	rc = memcmp(ctx->mem, data, sizeof(data));
59 	assert(rc == 0);
60 
61 	return rc;
62 }
63