blob: 7bfae6d0775d11d084495177d27cd45dee0a1e4b [file] [log] [blame]
Andrew Jeffery1770ce82017-04-12 14:50:32 +09301/*
2 * MBox Daemon Test File
3 *
4 * Copyright 2017 IBM
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#include <assert.h>
21#include <sys/mman.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <unistd.h>
25
26#include "mbox.h"
27#include "mboxd_msg.h"
28
29#include "test/mbox.h"
30#include "test/system.h"
31
32#define FLAGS 0xc3
33
34static const uint8_t command[] = {
35 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS
37};
38
39#define MEM_SIZE 3
40#define ERASE_SIZE 1
41#define N_WINDOWS 1
42#define WINDOW_SIZE 1
43
44int main(void)
45{
46 struct mbox_context *ctx;
47 struct stat details;
48 uint8_t *map;
49 int rc;
50
51 system_set_reserved_size(MEM_SIZE);
52 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
53
54 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
55
56 set_bmc_events(ctx, FLAGS, SET_BMC_EVENT);
57
58 rc = mbox_command_dispatch(ctx, command, sizeof(command));
59 assert(rc == 1);
60
61 rc = fstat(ctx->fds[MBOX_FD].fd, &details);
62 assert(rc == 0);
63
64 assert(details.st_size == 16);
65
66 map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE,
67 ctx->fds[MBOX_FD].fd, 0);
68 assert(map != MAP_FAILED);
69
70 if (map[15] != 0xc0)
71 return -1;
72
73 return rc;
74}