diff options
author | Andrew Jeffery <andrew@aj.id.au> | 2018-02-22 17:13:15 +1030 |
---|---|---|
committer | Andrew Jeffery <andrew@aj.id.au> | 2018-03-24 13:59:32 +1030 |
commit | ad341a2e1c8d81ae99ecbe2e93fd8c98c35e772d (patch) | |
tree | b2d24a74e7f4b9627699a20a23fec736d54761f2 /test | |
parent | a6582531dca0b30506eb258ca711d9f80fa0dca2 (diff) | |
download | phosphor-mboxd-ad341a2e1c8d81ae99ecbe2e93fd8c98c35e772d.tar.gz phosphor-mboxd-ad341a2e1c8d81ae99ecbe2e93fd8c98c35e772d.zip |
test: vpnor: Extract write_prsv from write_flash_vpnor
Change-Id: I71641b2c67eebf0b2babd677a46dbc45e0848795
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'test')
-rw-r--r-- | test/vpnor/Makefile.am.include | 13 | ||||
-rw-r--r-- | test/vpnor/write_flash_vpnor.cpp | 22 | ||||
-rw-r--r-- | test/vpnor/write_prsv.cpp | 64 |
3 files changed, 78 insertions, 21 deletions
diff --git a/test/vpnor/Makefile.am.include b/test/vpnor/Makefile.am.include index 13d76ea..5b6cc3d 100644 --- a/test/vpnor/Makefile.am.include +++ b/test/vpnor/Makefile.am.include @@ -35,9 +35,20 @@ test_vpnor_write_flash_vpnor_SOURCES = \ test_vpnor_write_flash_vpnor_LDFLAGS = $(OESDK_TESTCASE_FLAGS) test_vpnor_write_flash_vpnor_LDADD = $(VPNOR_LDADD) +test_vpnor_write_prsv_SOURCES = \ + $(TEST_MBOX_VPNOR_SRCS) \ + mboxd_pnor_partition_table.cpp \ + mboxd_flash_virtual.cpp \ + mtd.c \ + pnor_partition.cpp \ + %reldir%/write_prsv.cpp +test_vpnor_write_prsv_LDFLAGS = $(OESDK_TESTCASE_FLAGS) +test_vpnor_write_prsv_LDADD = $(VPNOR_LDADD) + if VIRTUAL_PNOR_ENABLED check_PROGRAMS += \ %reldir%/create_pnor_partition_table \ %reldir%/create_read_window_vpnor \ - %reldir%/write_flash_vpnor + %reldir%/write_flash_vpnor \ + %reldir%/write_prsv endif diff --git a/test/vpnor/write_flash_vpnor.cpp b/test/vpnor/write_flash_vpnor.cpp index 7c8f506..23d065d 100644 --- a/test/vpnor/write_flash_vpnor.cpp +++ b/test/vpnor/write_flash_vpnor.cpp @@ -86,6 +86,8 @@ int main(void) namespace fs = std::experimental::filesystem; int rc{}; + int fd; + void* map; char src[DATA_SIZE]{0}; struct mbox_context context; struct mbox_context* ctx = &context; @@ -99,26 +101,6 @@ int main(void) // create the partition table vpnor_create_partition_table_from_path(ctx, root.ro().c_str()); - // Write to psrv partition - - // As file doesn't exist there, so it copies - // the file from RO to PRSV and write the file in PRSV partition. - - memset(src, 0xaa, sizeof(src)); - - rc = write_flash(ctx, (OFFSET * 3), src, sizeof(src)); - assert(rc == 0); - - auto fd = open((root.prsv() / "TEST3").c_str(), O_RDONLY); - auto map = mmap(NULL, MEM_SIZE, PROT_READ, MAP_PRIVATE, fd, 0); - assert(map != MAP_FAILED); - - // verify it is written - rc = memcmp(src, map, sizeof(src)); - assert(rc == 0); - munmap(map, MEM_SIZE); - close(fd); - // Write to the RO partition memset(src, 0x55, sizeof(src)); fd = open((root.ro() / "TEST1").c_str(), O_RDONLY); diff --git a/test/vpnor/write_prsv.cpp b/test/vpnor/write_prsv.cpp new file mode 100644 index 0000000..03624e4 --- /dev/null +++ b/test/vpnor/write_prsv.cpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2018 IBM Corp. + +#include <assert.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#include "common.h" +#include "mbox.h" +#include "mboxd_flash.h" + +#include "test/vpnor/tmpd.hpp" + +static constexpr auto BLOCK_SIZE = 0x1000; + +const std::string toc[] = { + "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED", +}; + +namespace test = openpower::virtual_pnor::test; + +int main(void) +{ + namespace fs = std::experimental::filesystem; + + struct mbox_context _ctx, *ctx = &_ctx; + uint8_t src[8]; + void *map; + int fd; + int rc; + + /* Setup */ + memset(ctx, 0, sizeof(mbox_context)); + + mbox_vlog = &mbox_log_console; + verbosity = (verbose)2; + + test::VpnorRoot root(ctx, toc, BLOCK_SIZE); + vpnor_create_partition_table_from_path(ctx, root.ro().c_str()); + + /* Test */ + memset(src, 0xaa, sizeof(src)); + rc = write_flash(ctx, 0x1000, src, sizeof(src)); + assert(rc == 0); + + /* Verify */ + fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY); + assert(fd >= 0); + map = mmap(NULL, sizeof(src), PROT_READ, MAP_PRIVATE, fd, 0); + assert(map != MAP_FAILED); + + rc = memcmp(src, map, sizeof(src)); + assert(rc == 0); + munmap(map, sizeof(src)); + close(fd); + + /* Cleanup */ + destroy_vpnor(ctx); + + return 0; +} |