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