blob: 3d4cffd3ee0b72a85f49cac164481bb03ab4a12f [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
10#include "mbox.h"
11#include "mboxd_msg.h"
12
13#include "test/mbox.h"
14#include "test/system.h"
15
16#define FLAGS 0xc3
17
18static const uint8_t command[] = {
19 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00,
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS
21};
22
23#define MEM_SIZE 3
24#define ERASE_SIZE 1
25#define N_WINDOWS 1
26#define WINDOW_SIZE 1
27
28int main(void)
29{
30 struct mbox_context *ctx;
31 struct stat details;
32 uint8_t *map;
33 int rc;
34
35 system_set_reserved_size(MEM_SIZE);
36 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
37
38 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
39
40 set_bmc_events(ctx, FLAGS, SET_BMC_EVENT);
41
42 rc = mbox_command_dispatch(ctx, command, sizeof(command));
43 assert(rc == 1);
44
45 rc = fstat(ctx->fds[MBOX_FD].fd, &details);
46 assert(rc == 0);
47
48 assert(details.st_size == 16);
49
50 map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE,
51 ctx->fds[MBOX_FD].fd, 0);
52 assert(map != MAP_FAILED);
53
54 if (map[15] != 0xc0)
55 return -1;
56
57 return rc;
58}