From e9493adc142eaafabe30c8a0dd22b60a0c08f4f0 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Wed, 28 Mar 2018 14:04:34 +1030 Subject: test: vpnor: Add write_patch_resize Ensures writes can resize the backing files up to the limit of the partition size. Change-Id: Ie399d556dd485a235b7f6731d35536b2a6c703be Signed-off-by: Andrew Jeffery --- test/vpnor/Makefile.am.include | 14 +++++++- test/vpnor/write_patch_resize.cpp | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 test/vpnor/write_patch_resize.cpp diff --git a/test/vpnor/Makefile.am.include b/test/vpnor/Makefile.am.include index ca3f055..22bcd41 100644 --- a/test/vpnor/Makefile.am.include +++ b/test/vpnor/Makefile.am.include @@ -232,6 +232,16 @@ test_vpnor_read_patch_SOURCES = \ test_vpnor_read_patch_LDFLAGS = $(OESDK_TESTCASE_FLAGS) test_vpnor_read_patch_LDADD = $(VPNOR_LDADD) +test_vpnor_write_patch_resize_SOURCES = \ + $(TEST_MBOX_VPNOR_SRCS) \ + mboxd_pnor_partition_table.cpp \ + mboxd_flash_virtual.cpp \ + mtd.c \ + pnor_partition.cpp \ + %reldir%/write_patch_resize.cpp +test_vpnor_write_patch_resize_LDFLAGS = $(OESDK_TESTCASE_FLAGS) +test_vpnor_write_patch_resize_LDADD = $(VPNOR_LDADD) + if VIRTUAL_PNOR_ENABLED check_PROGRAMS += \ %reldir%/create_pnor_partition_table \ @@ -254,7 +264,9 @@ check_PROGRAMS += \ %reldir%/create_read_window_toc \ %reldir%/create_read_window_straddle_partitions \ %reldir%/create_read_window_partition_invalid \ - %reldir%/read_patch + %reldir%/read_patch \ + %reldir%/write_patch_resize XFAIL_TESTS += %reldir%/read_patch +XFAIL_TESTS += %reldir%/write_patch_resize endif diff --git a/test/vpnor/write_patch_resize.cpp b/test/vpnor/write_patch_resize.cpp new file mode 100644 index 0000000..24c71b0 --- /dev/null +++ b/test/vpnor/write_patch_resize.cpp @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2018 IBM Corp. + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "common.h" +#include "mbox.h" +#include "mboxd_flash.h" + +#include "test/vpnor/tmpd.hpp" + +static constexpr auto BLOCK_SIZE = 0x1000; +static constexpr auto PART_SIZE = BLOCK_SIZE; +static constexpr auto PATCH_SIZE = BLOCK_SIZE / 2; +static constexpr auto UPDATE_SIZE = BLOCK_SIZE; + +const std::string toc[] = { + "partition01=TEST1,00001000,00002000,80,ECC,READWRITE", +}; + +int main(void) +{ + namespace fs = std::experimental::filesystem; + namespace test = openpower::virtual_pnor::test; + + struct mbox_context _ctx, *ctx = &_ctx; + void *map; + int rc; + int fd; + + /* Setup */ + memset(ctx, 0, sizeof(mbox_context)); + + mbox_vlog = &mbox_log_console; + verbosity = (verbose)2; + + test::VpnorRoot root(ctx, toc, BLOCK_SIZE); + std::vector roContent(PART_SIZE, 0xff); + root.write("TEST1", roContent.data(), roContent.size()); + /* write_flash doesn't copy the file for us */ + std::vector patchContent(PATCH_SIZE, 0xaa); + root.patch("TEST1", patchContent.data(), patchContent.size()); + + vpnor_create_partition_table_from_path(ctx, root.ro().c_str()); + + /* Test */ + std::vector update(UPDATE_SIZE, 0x55); + rc = write_flash(ctx, 0x1000, update.data(), update.size()); + assert(rc == 0); + + /* Check that PATCH is modified with the new data */ + fs::path patch = root.patch() / "TEST1"; + assert(UPDATE_SIZE == fs::file_size(patch)); + fd = open(patch.c_str(), O_RDONLY); + map = mmap(NULL, UPDATE_SIZE, PROT_READ, MAP_SHARED, fd, 0); + assert(map != MAP_FAILED); + rc = memcmp(update.data(), map, update.size()); + assert(rc == 0); + munmap(map, update.size()); + close(fd); + + destroy_vpnor(ctx); + free(ctx->flash_bmap); + + return rc; +} -- cgit v1.2.1