blob: 910e7c50d246b409032abaaa07116559581ab08f [file] [log] [blame]
Alvin Wang8cef63e2019-10-15 23:23:38 +08001// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
4#include "config.h"
5
6extern "C" {
7#include "test/mbox.h"
8#include "test/system.h"
9}
10
11#include "vpnor/test/tmpd.hpp"
12
13#include <cassert>
14#include <cstring>
15#include <experimental/filesystem>
16#include <fstream>
17#include <vector>
18
19#include "vpnor/backend.h"
20
21// A read window assumes that the toc is located at offset 0,
22// so create dummy partition at arbitrary offset 0x1000.
23const std::string toc[] = {
24 "partition01=HBB,00001000,00002000,80,ECC,READONLY",
25 "partition05=DJVPD,0x000e5000,0x0022d000,00,ECC,PRESERVED",
26};
27
28static const auto BLOCK_SIZE = 4096;
29static const auto ERASE_SIZE = BLOCK_SIZE;
30static const auto N_WINDOWS = 1;
31static const auto WINDOW_SIZE = 1024 * 1024;
32static const auto MEM_SIZE = WINDOW_SIZE * 3;
33
34static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00};
37
38// Used to check the alignment
39static const uint8_t create_read_window1[] = {
40 0x04, 0x01, 0xe7, 0x00, 0x01, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
42
43static const uint8_t response1[] = {0x04, 0x01, 0x00, 0xfd, 0x00, 0x01, 0xe5,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
45
46static const uint8_t create_read_window2[] = {
47 0x04, 0x02, 0xe5, 0x01, 0x01, 0x00, 0x00, 0x00,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
49
50static const uint8_t response2[] = {0x04, 0x02, 0x00, 0xfd, 0x48, 0x00, 0xe5,
51 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
52
53namespace test = openpower::virtual_pnor::test;
54
55int main()
56{
57 struct mbox_context* ctx;
58
59 system_set_reserved_size(MEM_SIZE);
60 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
61
62 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
63
64 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
65
66 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
67 assert(rc == 1);
68
69 // send the request for partition5
70 rc = mbox_command_dispatch(ctx, create_read_window1,
71 sizeof(create_read_window1));
72 assert(rc == 1);
73 rc = mbox_cmp(ctx, response1, sizeof(response1));
74 assert(rc == 0);
75
76 // send the request for partition5
77 rc = mbox_command_dispatch(ctx, create_read_window2,
78 sizeof(create_read_window2));
79 assert(rc == 1);
80 rc = mbox_cmp(ctx, response2, sizeof(response2));
81 assert(rc == 0);
82
83 return rc;
84}