blob: 49cdfb899c9a1344b7c0ce34a70784bb22d2e0fb [file] [log] [blame]
Suraj Jitindar Singh29b3e8a2017-05-01 16:00:39 +10001/*
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
22#include "mbox.h"
23#include "mboxd_msg.h"
24
25#include "test/mbox.h"
26#include "test/system.h"
27
28static const uint8_t command[] = {
29 0x02, 0xaa, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
31};
32
33static const uint8_t response[] = {
34 0x02, 0xaa, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
35 /* Window size == 1MB -> suggested timeout == 8 (seconds) */
36 0x08, 0x00, 0x00, 0x00, 0x00, 0x01,
37};
38
39/*
40 * Suggested timeout is based on a milliseconds-per-MB constant. Thus to
41 * get a non-zero value we need a window of size atleast 1MB.
42 */
43#define MEM_SIZE 1 << 20
44#define ERASE_SIZE 1
45#define N_WINDOWS 1
46#define WINDOW_SIZE 1 << 20
47
48int main(void)
49{
50 struct mbox_context *ctx;
51 int rc;
52
53 system_set_reserved_size(MEM_SIZE);
54 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
55
56 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
57
58 rc = mbox_command_dispatch(ctx, command, sizeof(command));
59 assert(rc == 1);
60
61 rc = mbox_cmp(ctx, response, sizeof(response));
62 assert(rc == 0);
63
64 return rc;
65}