diff options
author | Andrew Jeffery <andrew@aj.id.au> | 2018-03-26 12:13:20 +1030 |
---|---|---|
committer | Andrew Jeffery <andrew@aj.id.au> | 2018-04-04 17:27:31 +0930 |
commit | 30bcf84c932a579532e5f8417af549494e11b6e9 (patch) | |
tree | ebbfb4abf9507463a1a714fc4e2bf8973978d5d5 /vpnor/test/create_pnor_partition_table.cpp | |
parent | 53c21aaa803e148c9c79cb3f5e0252d911506b10 (diff) | |
download | phosphor-mboxd-30bcf84c932a579532e5f8417af549494e11b6e9.tar.gz phosphor-mboxd-30bcf84c932a579532e5f8417af549494e11b6e9.zip |
test: Move vpnor tests to vpnor directory
In the spirit of things that are together should be kept together. The
repository layout now better corresponds to upstream with the exception
of the vpnor directory and some modifications to Makefile.am
Change-Id: I16d59a3c9ee846065f6a8c83eb4459715d525f3f
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'vpnor/test/create_pnor_partition_table.cpp')
-rw-r--r-- | vpnor/test/create_pnor_partition_table.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/vpnor/test/create_pnor_partition_table.cpp b/vpnor/test/create_pnor_partition_table.cpp new file mode 100644 index 0000000..3a46e38 --- /dev/null +++ b/vpnor/test/create_pnor_partition_table.cpp @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2018 IBM Corp. +#include <assert.h> +#include <string.h> + +#include "config.h" +#include "vpnor/pnor_partition_table.hpp" + +extern "C" { +#include "test/mbox.h" +#include "test/system.h" +} + +#include "vpnor/test/tmpd.hpp" + +static const auto BLOCK_SIZE = 4 * 1024; +static const auto ERASE_SIZE = BLOCK_SIZE; +static const auto PNOR_SIZE = 64 * 1024 * 1024; +static const auto MEM_SIZE = PNOR_SIZE; +static const auto N_WINDOWS = 1; +static const auto WINDOW_SIZE = BLOCK_SIZE; + +const std::string toc[] = { + "partition01=HBB,00000000,00001000,80,ECC,PRESERVED", +}; +constexpr auto partitionName = "HBB"; + +namespace test = openpower::virtual_pnor::test; + +int main() +{ + struct mbox_context* ctx; + + system_set_reserved_size(MEM_SIZE); + system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); + ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); + test::VpnorRoot root(ctx, toc, BLOCK_SIZE); + const openpower::virtual_pnor::partition::Table table(ctx); + + pnor_partition_table expectedTable{}; + expectedTable.data.magic = PARTITION_HEADER_MAGIC; + expectedTable.data.version = PARTITION_VERSION_1; + expectedTable.data.size = 1; + expectedTable.data.entry_size = sizeof(pnor_partition); + expectedTable.data.entry_count = 1; + expectedTable.data.block_size = BLOCK_SIZE; + expectedTable.data.block_count = + (PNOR_SIZE) / expectedTable.data.block_size; + expectedTable.checksum = + openpower::virtual_pnor::details::checksum(expectedTable.data); + + pnor_partition expectedPartition{}; + strcpy(expectedPartition.data.name, partitionName); + expectedPartition.data.base = 0; + expectedPartition.data.size = 1; + expectedPartition.data.actual = 0x1000; + expectedPartition.data.id = 1; + expectedPartition.data.pid = PARENT_PATITION_ID; + expectedPartition.data.type = PARTITION_TYPE_DATA; + expectedPartition.data.flags = 0; + expectedPartition.data.user.data[0] = PARTITION_ECC_PROTECTED; + expectedPartition.data.user.data[1] |= PARTITION_PRESERVED; + expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512; + expectedPartition.checksum = + openpower::virtual_pnor::details::checksum(expectedPartition.data); + + const pnor_partition_table& result = table.getNativeTable(); + + auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table)); + assert(rc == 0); + + rc = memcmp(&expectedPartition, &result.partitions[0], + sizeof(pnor_partition)); + assert(rc == 0); + + const pnor_partition& first = table.partition(0); + rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition)); + assert(rc == 0); + + return 0; +} |