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