Andrew Jeffery | 9b25b59 | 2018-02-26 12:01:24 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
| 4 | #include "config.h" |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 5 | |
| 6 | #include "vpnor/pnor_partition_table.hpp" |
| 7 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 8 | #include <cassert> |
Andrew Jeffery | 9b25b59 | 2018-02-26 12:01:24 +1030 | [diff] [blame] | 9 | |
| 10 | #include "common.h" |
Andrew Jeffery | 53c21aa | 2018-03-26 11:56:16 +1030 | [diff] [blame] | 11 | #include "vpnor/pnor_partition_defs.h" |
Andrew Jeffery | 9b25b59 | 2018-02-26 12:01:24 +1030 | [diff] [blame] | 12 | |
| 13 | static constexpr auto BLOCK_SIZE = 4 * 1024; |
| 14 | static constexpr auto DATA_MASK = ((1 << 24) - 1); |
| 15 | |
| 16 | int 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 | } |