1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright (C) 2018 IBM Corp.
3 
4 #include "config.h"
5 
6 #include <assert.h>
7 #include <string.h>
8 
9 #include <experimental/filesystem>
10 #include <fstream>
11 #include <vector>
12 
13 #include "vpnor/mboxd_pnor_partition_table.h"
14 
15 extern "C" {
16 #include "test/mbox.h"
17 #include "test/system.h"
18 }
19 
20 #include "vpnor/test/tmpd.hpp"
21 
22 static const auto BLOCK_SIZE = 4096;
23 static const auto ERASE_SIZE = BLOCK_SIZE;
24 static const auto WINDOW_SIZE = 16 * BLOCK_SIZE;
25 static const auto N_WINDOWS = 2;
26 static const auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE;
27 
28 const std::string toc[] = {
29     "partition01=ONE,00001000,00011000,80,ECC,READONLY",
30 };
31 
32 static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
33                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34                                    0x00, 0x00, 0x00, 0x00};
35 
36 namespace test = openpower::virtual_pnor::test;
37 
38 int main()
39 {
40     uint8_t request[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
41                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
42 
43     uint8_t response[] = {0x04, 0x01, 0xe0, 0xff, 0x10, 0x00, 0x01,
44                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
45 
46     struct mbox_context* ctx;
47 
48     system_set_reserved_size(MEM_SIZE);
49     system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
50 
51     ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
52     test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
53     init_vpnor_from_paths(ctx);
54 
55     int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
56     assert(rc == 1);
57 
58     for (int i = 1; i < (0x10000 / BLOCK_SIZE); i++)
59     {
60         /* Update the requested offset */
61         put_u16(&request[2], i);
62 
63         /*
64          * Reuse the offset as a sequence number, because it's unique. Request
65          * and response have the same sequence number
66          */
67         request[1] = i;
68         response[1] = i;
69 
70         rc = mbox_command_dispatch(ctx, request, sizeof(request));
71         assert(rc == 1);
72 
73         /* Check that it maps to the same window each time */
74         rc = mbox_cmp(ctx, response, sizeof(response));
75         assert(rc == 0);
76     }
77 
78     return 0;
79 }
80