1 // 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"
8 #include "vpnor/mboxd_pnor_partition_table.h"
9
10 extern "C" {
11 #include "test/mbox.h"
12 #include "test/system.h"
13 }
14
15 #include "vpnor/test/tmpd.hpp"
16 static const auto BLOCK_SIZE = 4096;
17 static const auto ERASE_SIZE = BLOCK_SIZE;
18 static const auto WINDOW_SIZE = 2 * BLOCK_SIZE;
19 static const auto MEM_SIZE = WINDOW_SIZE;
20 static const auto N_WINDOWS = 1;
21 static const auto PNOR_SIZE = 4 * BLOCK_SIZE;
22
23 const std::string toc[] = {
24 "partition01=ONE,00001000,00002000,80,ECC,READONLY",
25 "partition02=TWO,00002000,00004000,80,ECC,READONLY",
26 };
27
28 static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00};
31
32 static const uint8_t request_one[] = {0x04, 0x01, 0x01, 0x00, 0x02, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00};
35
36 static const uint8_t response_one[] = {0x04, 0x01, 0xfe, 0xff, 0x01,
37 0x00, 0x01, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x01};
39
40 static const uint8_t request_two[] = {0x04, 0x02, 0x02, 0x00, 0x02, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00};
43
44 static const uint8_t response_two[] = {0x04, 0x02, 0xfe, 0xff, 0x02,
45 0x00, 0x02, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x01};
47
48 namespace test = openpower::virtual_pnor::test;
49
main()50 int 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 }
78