xref: /openbmc/phosphor-mboxd/vpnor/test/toc_lookup_found.cpp (revision 30bcf84c932a579532e5f8417af549494e11b6e9)
1 *30bcf84cSAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
2 *30bcf84cSAndrew Jeffery // Copyright (C) 2018 IBM Corp.
3 *30bcf84cSAndrew Jeffery #include <assert.h>
4 *30bcf84cSAndrew Jeffery #include <string.h>
5 *30bcf84cSAndrew Jeffery 
6 *30bcf84cSAndrew Jeffery #include "config.h"
7 *30bcf84cSAndrew Jeffery #include "vpnor/pnor_partition_table.hpp"
8 *30bcf84cSAndrew Jeffery 
9 *30bcf84cSAndrew Jeffery extern "C" {
10 *30bcf84cSAndrew Jeffery #include "test/mbox.h"
11 *30bcf84cSAndrew Jeffery #include "test/system.h"
12 *30bcf84cSAndrew Jeffery }
13 *30bcf84cSAndrew Jeffery 
14 *30bcf84cSAndrew Jeffery #include "vpnor/test/tmpd.hpp"
15 *30bcf84cSAndrew Jeffery 
16 *30bcf84cSAndrew Jeffery static constexpr auto BLOCK_SIZE = 0x1000;
17 *30bcf84cSAndrew Jeffery static constexpr auto ERASE_SIZE = BLOCK_SIZE;
18 *30bcf84cSAndrew Jeffery static constexpr auto PNOR_SIZE = 64 * 1024 * 1024;
19 *30bcf84cSAndrew Jeffery static constexpr auto MEM_SIZE = 32 * 1024 * 1024;
20 *30bcf84cSAndrew Jeffery static constexpr auto N_WINDOWS = 1;
21 *30bcf84cSAndrew Jeffery static constexpr auto WINDOW_SIZE = BLOCK_SIZE * 2;
22 *30bcf84cSAndrew Jeffery 
23 *30bcf84cSAndrew Jeffery const std::string toc[] = {
24 *30bcf84cSAndrew Jeffery     "partition01=ONE,00001000,00002000,80,",
25 *30bcf84cSAndrew Jeffery     "partition02=TWO,00002000,00004000,80,",
26 *30bcf84cSAndrew Jeffery     "partition03=THREE,00004000,00008000,80,",
27 *30bcf84cSAndrew Jeffery };
28 *30bcf84cSAndrew Jeffery 
main()29 *30bcf84cSAndrew Jeffery int main()
30 *30bcf84cSAndrew Jeffery {
31 *30bcf84cSAndrew Jeffery     namespace test = openpower::virtual_pnor::test;
32 *30bcf84cSAndrew Jeffery     namespace vpnor = openpower::virtual_pnor;
33 *30bcf84cSAndrew Jeffery 
34 *30bcf84cSAndrew Jeffery     struct mbox_context* ctx;
35 *30bcf84cSAndrew Jeffery 
36 *30bcf84cSAndrew Jeffery     system_set_reserved_size(MEM_SIZE);
37 *30bcf84cSAndrew Jeffery     system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
38 *30bcf84cSAndrew Jeffery 
39 *30bcf84cSAndrew Jeffery     ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
40 *30bcf84cSAndrew Jeffery 
41 *30bcf84cSAndrew Jeffery     test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
42 *30bcf84cSAndrew Jeffery     vpnor::partition::Table table(ctx);
43 *30bcf84cSAndrew Jeffery 
44 *30bcf84cSAndrew Jeffery     const struct pnor_partition& part = table.partition("TWO");
45 *30bcf84cSAndrew Jeffery     assert(part.data.id == 2);
46 *30bcf84cSAndrew Jeffery     assert(part.data.base == 2);
47 *30bcf84cSAndrew Jeffery     assert(part.data.size == 2);
48 *30bcf84cSAndrew Jeffery 
49 *30bcf84cSAndrew Jeffery     return 0;
50 *30bcf84cSAndrew Jeffery }
51