blob: 17240c96ec8014dce5c349c2c2097b70997aa4e5 [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
Andrew Jefferyf4bc3352019-03-18 12:09:48 +103016#include "vpnor/backend.h"
Andrew Jeffery261f61a2019-03-14 09:57:28 +103017
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
Evan Lojewskif1e547c2019-03-14 14:34:33 +103059 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
60 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
Andrew Jeffery929b4212018-03-23 16:13:29 +103061
62 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
63 assert(rc == 1);
64
65 rc = mbox_command_dispatch(ctx, request_one, sizeof(request_one));
66 assert(rc == 1);
67
68 rc = mbox_cmp(ctx, response_one, sizeof(response_one));
69 assert(rc == 0);
70
71 rc = mbox_command_dispatch(ctx, request_two, sizeof(request_two));
72 assert(rc == 1);
73
74 rc = mbox_cmp(ctx, response_two, sizeof(response_two));
75 assert(rc == 0);
76
77 return rc;
78}