diff options
author | Andrew Jeffery <andrew@aj.id.au> | 2018-11-13 15:17:30 +1030 |
---|---|---|
committer | Andrew Jeffery <andrew@aj.id.au> | 2019-01-08 03:11:04 +0000 |
commit | 899857542e729e57049d1dd88406127626b3902d (patch) | |
tree | 0d92fbbbe336ea4d2fe9b29aa42f38d0018edfb1 | |
parent | 4c15bb1768765e06060a4cde3b22e7bc8896574f (diff) | |
download | phosphor-mboxbridge-899857542e729e57049d1dd88406127626b3902d.tar.gz phosphor-mboxbridge-899857542e729e57049d1dd88406127626b3902d.zip |
vpnor: Add write-to-writable-ToC test
Tests if mutations survive re-opening the window. They don't, so add the
test to XFAIL_TESTS.
Change-Id: Ic2f844c30a7da35033bf03012ea452718d2843e4
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r-- | vpnor/test/Makefile.am.include | 13 | ||||
-rw-r--r-- | vpnor/test/write_toc.cpp | 101 |
2 files changed, 113 insertions, 1 deletions
diff --git a/vpnor/test/Makefile.am.include b/vpnor/test/Makefile.am.include index b029b37..63c6240 100644 --- a/vpnor/test/Makefile.am.include +++ b/vpnor/test/Makefile.am.include @@ -219,6 +219,13 @@ vpnor_test_create_write_window_unmapped_SOURCES = \ vpnor_test_create_write_window_unmapped_LDFLAGS = $(OESDK_TESTCASE_FLAGS) vpnor_test_create_write_window_unmapped_LDADD = $(VPNOR_LDADD) +vpnor_test_write_toc_SOURCES = \ + $(TEST_MOCK_SRCS) \ + $(TEST_MBOX_VPNOR_INTEG_SRCS) \ + %reldir%/write_toc.cpp +vpnor_test_write_toc_LDFLAGS = $(OESDK_TESTCASE_FLAGS) +vpnor_test_write_toc_LDADD = $(VPNOR_LDADD) + if VIRTUAL_PNOR_ENABLED check_PROGRAMS += \ %reldir%/create_pnor_partition_table \ @@ -248,5 +255,9 @@ check_PROGRAMS += \ %reldir%/create_read_window_remap \ %reldir%/create_write_window_ro_partition \ %reldir%/create_write_window_rw_partition \ - %reldir%/create_write_window_unmapped + %reldir%/create_write_window_unmapped \ + %reldir%/write_toc + +XFAIL_TESTS += \ + %reldir%/write_toc endif diff --git a/vpnor/test/write_toc.cpp b/vpnor/test/write_toc.cpp new file mode 100644 index 0000000..dcf5aae --- /dev/null +++ b/vpnor/test/write_toc.cpp @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2018 IBM Corp. +#include "config.h" + +#include "vpnor/pnor_partition_table.hpp" + +#include <assert.h> +#include <string.h> +#include <sys/mman.h> + +extern "C" { +#include "test/mbox.h" +#include "test/system.h" +} + +#include "vpnor/test/tmpd.hpp" + +static constexpr auto BLOCK_SIZE = 4 * 1024; +static constexpr auto PNOR_SIZE = 2 * BLOCK_SIZE; +static constexpr auto MEM_SIZE = BLOCK_SIZE; +static constexpr auto ERASE_SIZE = BLOCK_SIZE; +static constexpr auto N_WINDOWS = 1; +static constexpr auto WINDOW_SIZE = BLOCK_SIZE; +static constexpr auto TOC_PART_SIZE = BLOCK_SIZE; + +const std::string toc[] = { + "partition00=part,00000000,00001000,80,READWRITE", + "partition01=ONE,00001000,00002000,80,READWRITE", +}; + +static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +static const uint8_t write_toc[] = {0x06, 0x01, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +static const uint8_t erase_toc[] = {0x0a, 0x02, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +static const uint8_t read_one[] = {0x04, 0x03, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +static const uint8_t read_toc[] = {0x04, 0x04, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + +int main() +{ + namespace test = openpower::virtual_pnor::test; + namespace vpnor = openpower::virtual_pnor; + + struct mbox_context* ctx; + int rc; + + void* erased; + + erased = malloc(BLOCK_SIZE); + assert(erased); + + memset(erased, 0xff, BLOCK_SIZE); + + 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); + vpnor::partition::Table table(ctx); + + assert(table.capacity() == TOC_PART_SIZE); + + init_vpnor_from_paths(ctx); + + rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); + assert(rc == MBOX_R_SUCCESS); + + rc = mbox_command_dispatch(ctx, write_toc, sizeof(write_toc)); + assert(rc == MBOX_R_SUCCESS); + + rc = mbox_command_dispatch(ctx, erase_toc, sizeof(erase_toc)); + assert(rc == MBOX_R_SUCCESS); + + rc = memcmp(ctx->mem, erased, BLOCK_SIZE); + assert(rc == 0); + + rc = mbox_command_dispatch(ctx, read_one, sizeof(read_one)); + assert(rc == MBOX_R_SUCCESS); + + rc = mbox_command_dispatch(ctx, read_toc, sizeof(read_toc)); + assert(rc == MBOX_R_SUCCESS); + + rc = memcmp(ctx->mem, erased, BLOCK_SIZE); + assert(rc == 0); + + free(erased); + + return 0; +} |