blob: 719c27b787f5222369a0737d3dddd4d01f0f3d85 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jeffery1770ce82017-04-12 14:50:32 +09303
4#include <assert.h>
5#include <sys/mman.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <unistd.h>
9
Andrew Jeffery26558db2018-08-10 00:22:38 +093010#include "mboxd.h"
11#include "protocol.h"
Andrew Jeffery457a6e52018-08-08 11:21:08 +093012#include "transport_mbox.h"
Andrew Jeffery1770ce82017-04-12 14:50:32 +093013
14#include "test/mbox.h"
15#include "test/system.h"
16
17#define FLAGS 0xc3
18
Andrew Jefferyb5685b32018-08-07 14:10:54 +093019static const uint8_t get_info[] = {
20 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
22};
23
Andrew Jeffery1770ce82017-04-12 14:50:32 +093024static const uint8_t command[] = {
25 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS
27};
28
Andrew Jefferyb5685b32018-08-07 14:10:54 +093029uint8_t data[3] = { 0xaa, 0x55, 0xaa };
30
Andrew Jeffery1770ce82017-04-12 14:50:32 +093031#define MEM_SIZE 3
32#define ERASE_SIZE 1
33#define N_WINDOWS 1
34#define WINDOW_SIZE 1
35
36int main(void)
37{
38 struct mbox_context *ctx;
39 struct stat details;
40 uint8_t *map;
41 int rc;
42
43 system_set_reserved_size(MEM_SIZE);
44 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
45
46 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
Andrew Jefferyb5685b32018-08-07 14:10:54 +093047 rc = mbox_set_mtd_data(ctx, data, sizeof(data));
48 assert(rc == 0);
49
50 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
51 assert(rc == 1);
Andrew Jeffery1770ce82017-04-12 14:50:32 +093052
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093053 protocol_events_set(ctx, FLAGS);
Andrew Jeffery1770ce82017-04-12 14:50:32 +093054
55 rc = mbox_command_dispatch(ctx, command, sizeof(command));
56 assert(rc == 1);
57
58 rc = fstat(ctx->fds[MBOX_FD].fd, &details);
59 assert(rc == 0);
60
Andrew Jeffery1770ce82017-04-12 14:50:32 +093061 map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE,
62 ctx->fds[MBOX_FD].fd, 0);
63 assert(map != MAP_FAILED);
64
Andrew Jefferyb5685b32018-08-07 14:10:54 +093065 assert(details.st_size >= 16);
66 assert(map[15] == 0xc0);
Andrew Jeffery1770ce82017-04-12 14:50:32 +093067
Andrew Jefferyb5685b32018-08-07 14:10:54 +093068 return 0;
Andrew Jeffery1770ce82017-04-12 14:50:32 +093069}