blob: 1837546f01c896e5982e39f2e79152865227fe7d [file] [log] [blame]
Andrew Jeffery929b4212018-03-23 16:13:29 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
4#include <assert.h>
5#include <experimental/filesystem>
6
7#include "config.h"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +10308#include "vpnor/mboxd_pnor_partition_table.h"
Andrew Jeffery929b4212018-03-23 16:13:29 +10309
10extern "C" {
11#include "test/mbox.h"
12#include "test/system.h"
13}
14
Andrew Jeffery30bcf842018-03-26 12:13:20 +103015#include "vpnor/test/tmpd.hpp"
Andrew Jeffery929b4212018-03-23 16:13:29 +103016static const auto BLOCK_SIZE = 4096;
17static const auto ERASE_SIZE = BLOCK_SIZE;
18static const auto WINDOW_SIZE = 2 * BLOCK_SIZE;
19static const auto MEM_SIZE = WINDOW_SIZE;
20static const auto N_WINDOWS = 1;
21static const auto PNOR_SIZE = 4 * BLOCK_SIZE;
22
23const std::string toc[] = {
24 "partition01=ONE,00001000,00002000,80,ECC,READONLY",
25 "partition02=TWO,00002000,00004000,80,ECC,READONLY",
26};
27
28static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00};
31
32static const uint8_t request_one[] = {0x04, 0x01, 0x01, 0x00, 0x02, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00};
35
36static const uint8_t response_one[] = {0x04, 0x01, 0xfe, 0xff, 0x01,
37 0x00, 0x01, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x01};
39
40static const uint8_t request_two[] = {0x04, 0x02, 0x02, 0x00, 0x02, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00};
43
44static const uint8_t response_two[] = {0x04, 0x02, 0xfe, 0xff, 0x02,
45 0x00, 0x02, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x01};
47
48namespace test = openpower::virtual_pnor::test;
49
50int main()
51{
52 struct mbox_context *ctx;
53
54 system_set_reserved_size(MEM_SIZE);
55 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
56
57 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
58 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
59 init_vpnor_from_paths(ctx);
60
61 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
62 assert(rc == 1);
63
64 rc = mbox_command_dispatch(ctx, request_one, sizeof(request_one));
65 assert(rc == 1);
66
67 rc = mbox_cmp(ctx, response_one, sizeof(response_one));
68 assert(rc == 0);
69
70 rc = mbox_command_dispatch(ctx, request_two, sizeof(request_two));
71 assert(rc == 1);
72
73 rc = mbox_cmp(ctx, response_two, sizeof(response_two));
74 assert(rc == 0);
75
76 return rc;
77}