blob: c05ef02a3f27920813c7d2fd1eb6fbb5478ce037 [file] [log] [blame]
Andrew Jeffery912c9bd2018-03-23 13:31:46 +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 Jeffery912c9bd2018-03-23 13:31:46 +10306#include <assert.h>
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07007#include <string.h>
8
Andrew Jeffery912c9bd2018-03-23 13:31:46 +10309#include <experimental/filesystem>
10#include <fstream>
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103011#include <vector>
12
Andrew Jeffery53c21aa2018-03-26 11:56:16 +103013#include "vpnor/mboxd_pnor_partition_table.h"
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103014
15extern "C" {
16#include "test/mbox.h"
17#include "test/system.h"
18}
19
Andrew Jeffery30bcf842018-03-26 12:13:20 +103020#include "vpnor/test/tmpd.hpp"
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103021
22static const auto BLOCK_SIZE = 4096;
23static const auto ERASE_SIZE = BLOCK_SIZE;
24static const auto WINDOW_SIZE = 16 * BLOCK_SIZE;
25static const auto N_WINDOWS = 2;
26static const auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE;
27
28const std::string toc[] = {
29 "partition01=ONE,00001000,00011000,80,ECC,READONLY",
30};
31
32static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00};
35
36namespace test = openpower::virtual_pnor::test;
37
38int 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
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070046 struct mbox_context* ctx;
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103047
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}