blob: 6e134e51bcadf857ec3fcbe18e29357ea2ad7ffe [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"
5#include <assert.h>
6
7#include "common.h"
8#include "pnor_partition_defs.h"
9#include "pnor_partition_table.hpp"
10
11static constexpr auto BLOCK_SIZE = 4 * 1024;
12static constexpr auto DATA_MASK = ((1 << 24) - 1);
13
14int main()
15{
16 namespace vpnor = openpower::virtual_pnor;
17
18 struct pnor_partition part;
19 std::string line;
20
21 mbox_vlog = mbox_log_console;
22 verbosity = MBOX_LOG_DEBUG;
23
24 line = "partition01=FOO,00001000,00002000,80,ECC";
25 vpnor::parseTocLine(line, BLOCK_SIZE, part);
26 assert((part.data.user.data[0]) == PARTITION_ECC_PROTECTED);
27 assert(!(part.data.user.data[1] & DATA_MASK));
28
29 line = "partition01=FOO,00001000,00002000,80,PRESERVED";
30 vpnor::parseTocLine(line, BLOCK_SIZE, part);
31 assert(!(part.data.user.data[0]));
32 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_PRESERVED);
33
34 line = "partition01=FOO,00001000,00002000,80,READONLY";
35 vpnor::parseTocLine(line, BLOCK_SIZE, part);
36 assert(!(part.data.user.data[0]));
37 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_READONLY);
38
39 /* BACKUP is unimplemented */
40 line = "partition01=FOO,00001000,00002000,80,BACKUP";
41 vpnor::parseTocLine(line, BLOCK_SIZE, part);
42 assert(!(part.data.user.data[0]));
43 assert(!(part.data.user.data[1] & DATA_MASK));
44
45 line = "partition01=FOO,00001000,00002000,80,REPROVISION";
46 vpnor::parseTocLine(line, BLOCK_SIZE, part);
47 assert(!(part.data.user.data[0]));
48 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_REPROVISION);
49
50 line = "partition01=FOO,00001000,00002000,80,VOLATILE";
51 vpnor::parseTocLine(line, BLOCK_SIZE, part);
52 assert(!(part.data.user.data[0]));
53 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_VOLATILE);
54
55 line = "partition01=FOO,00001000,00002000,80,CLEARECC";
56 vpnor::parseTocLine(line, BLOCK_SIZE, part);
57 assert(!(part.data.user.data[0]));
58 assert((part.data.user.data[1] & DATA_MASK) == PARTITION_CLEARECC);
59
60 line = "partition01=FOO,00001000,00002000,80,READWRITE";
61 vpnor::parseTocLine(line, BLOCK_SIZE, part);
62 assert(!(part.data.user.data[0]));
63 assert(((part.data.user.data[1] & DATA_MASK) ^ PARTITION_READONLY) ==
64 PARTITION_READONLY);
65
66 line = "partition01=FOO,00001000,00002000,80,";
67 vpnor::parseTocLine(line, BLOCK_SIZE, part);
68 assert(!(part.data.user.data[0]));
69 assert(!(part.data.user.data[1] & DATA_MASK));
70
71 line = "partition01=FOO,00001000,00002000,80,junk";
72 vpnor::parseTocLine(line, BLOCK_SIZE, part);
73 assert(!(part.data.user.data[0]));
74 assert(!(part.data.user.data[1] & DATA_MASK));
75
76 return 0;
77}