blob: 2caab8b72e60aee94c0aaf589a56a699ea043fe3 [file] [log] [blame]
Ninad Palsule2be45632024-11-20 17:28:49 -06001// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2024 IBM Corp.
3#include "config.h"
4
5extern "C" {
6#include "backend.h"
7#include "test/mbox.h"
8#include "test/system.h"
9}
10
11#include "vpnor/table.hpp"
12#include "vpnor/test/tmpd.hpp"
13
14#include <cassert>
15#include <cstring>
16
17static constexpr auto BLOCK_SIZE = 0x1000;
18static constexpr auto ERASE_SIZE = BLOCK_SIZE;
19static constexpr auto PNOR_SIZE = 64 * 1024 * 1024;
20static constexpr auto MEM_SIZE = 32 * 1024 * 1024;
21static constexpr auto N_WINDOWS = 1;
22static constexpr auto WINDOW_SIZE = BLOCK_SIZE * 2;
23
24static const uint8_t reset_state[] = {0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
25 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00};
27static const uint8_t reset_state1[] = {0x01, 0x02, 0x00, 0x00, 0x00, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00};
30
31const std::string toc[] = {
32 "partition01=ONE,00001000,00002000,80,",
33 "partition02=TWO,00002000,00003000,80,",
34};
35
36int main()
37{
38 namespace test = openpower::virtual_pnor::test;
39 namespace fs = std::filesystem;
40 namespace vpnor = openpower::virtual_pnor;
41
42 int rc;
43 struct mbox_context* ctx;
44
45 system_set_reserved_size(MEM_SIZE);
46 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
47
48 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
49
50 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
51
52 fs::remove(root.ro() / "TWO");
53
54 /*
55 * First reset should fail due to missing file but it should keep objects
56 * in sane state.
57 */
58 rc = mbox_command_dispatch(ctx, reset_state, sizeof(reset_state));
59 assert(rc == 2);
60
61 /*
62 * Run one more reset to make sure that reset can free objects created
63 * by previous reset.
64 */
65 rc = mbox_command_dispatch(ctx, reset_state1, sizeof(reset_state1));
66 assert(rc == 2);
67}