blob: 13bd0162fc92726b0856c9fe8f38440376ef2b89 [file] [log] [blame]
Andrew Jeffery9b25b592018-02-26 12:01:24 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
4#include "config.h"
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07005
6#include "vpnor/pnor_partition_table.hpp"
7
Andrew Jeffery261f61a2019-03-14 09:57:28 +10308#include <cassert>
Andrew Jeffery9b25b592018-02-26 12:01:24 +10309
10#include "common.h"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +103011#include "vpnor/pnor_partition_defs.h"
Andrew Jeffery9b25b592018-02-26 12:01:24 +103012
13static constexpr auto BLOCK_SIZE = 4 * 1024;
14static constexpr auto DATA_MASK = ((1 << 24) - 1);
15
16int main()
17{
18 namespace vpnor = openpower::virtual_pnor;
19
20 struct pnor_partition part;
21 std::string line;
22
23 mbox_vlog = mbox_log_console;
24 verbosity = MBOX_LOG_DEBUG;
25
26 line = "partition01=FOO,00001000,00002000,80,ECC";
27 vpnor::parseTocLine(line, BLOCK_SIZE, part);
28 assert((part.data.user.data[0]) == PARTITION_ECC_PROTECTED);
29 assert(!(part.data.user.data[1] & DATA_MASK));
30
31 line = "partition01=FOO,00001000,00002000,80,PRESERVED";
32 vpnor::parseTocLine(line, BLOCK_SIZE, part);
33 assert(!(part.data.user.data[0]));
34 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_PRESERVED);
35
36 line = "partition01=FOO,00001000,00002000,80,READONLY";
37 vpnor::parseTocLine(line, BLOCK_SIZE, part);
38 assert(!(part.data.user.data[0]));
39 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_READONLY);
40
41 /* BACKUP is unimplemented */
42 line = "partition01=FOO,00001000,00002000,80,BACKUP";
43 vpnor::parseTocLine(line, BLOCK_SIZE, part);
44 assert(!(part.data.user.data[0]));
45 assert(!(part.data.user.data[1] & DATA_MASK));
46
47 line = "partition01=FOO,00001000,00002000,80,REPROVISION";
48 vpnor::parseTocLine(line, BLOCK_SIZE, part);
49 assert(!(part.data.user.data[0]));
50 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_REPROVISION);
51
52 line = "partition01=FOO,00001000,00002000,80,VOLATILE";
53 vpnor::parseTocLine(line, BLOCK_SIZE, part);
54 assert(!(part.data.user.data[0]));
55 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_VOLATILE);
56
57 line = "partition01=FOO,00001000,00002000,80,CLEARECC";
58 vpnor::parseTocLine(line, BLOCK_SIZE, part);
59 assert(!(part.data.user.data[0]));
60 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_CLEARECC);
61
62 line = "partition01=FOO,00001000,00002000,80,READWRITE";
63 vpnor::parseTocLine(line, BLOCK_SIZE, part);
64 assert(!(part.data.user.data[0]));
65 assert(((part.data.user.data[1] & DATA_MASK) ^ PARTITION_READONLY) ==
66 PARTITION_READONLY);
67
68 line = "partition01=FOO,00001000,00002000,80,";
69 vpnor::parseTocLine(line, BLOCK_SIZE, part);
70 assert(!(part.data.user.data[0]));
71 assert(!(part.data.user.data[1] & DATA_MASK));
72
73 line = "partition01=FOO,00001000,00002000,80,junk";
74 vpnor::parseTocLine(line, BLOCK_SIZE, part);
75 assert(!(part.data.user.data[0]));
76 assert(!(part.data.user.data[1] & DATA_MASK));
77
78 return 0;
79}