Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <sys/mman.h> |
| 7 | #include <sys/stat.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <unistd.h> |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "mbox.h" |
Andrew Jeffery | 71eaa73 | 2018-08-08 16:44:24 +0930 | [diff] [blame] | 13 | extern "C" { |
Andrew Jeffery | eebc6bd | 2018-08-08 10:38:19 +0930 | [diff] [blame] | 14 | #include "flash.h" |
Andrew Jeffery | 71eaa73 | 2018-08-08 16:44:24 +0930 | [diff] [blame] | 15 | } |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 16 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 17 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 18 | |
| 19 | static constexpr auto BLOCK_SIZE = 0x1000; |
| 20 | |
| 21 | const std::string toc[] = { |
| 22 | "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED", |
| 23 | }; |
| 24 | |
| 25 | namespace test = openpower::virtual_pnor::test; |
| 26 | |
| 27 | int main(void) |
| 28 | { |
| 29 | namespace fs = std::experimental::filesystem; |
| 30 | |
| 31 | struct mbox_context _ctx, *ctx = &_ctx; |
| 32 | uint8_t src[8]; |
| 33 | void *map; |
| 34 | int fd; |
| 35 | int rc; |
| 36 | |
| 37 | /* Setup */ |
| 38 | memset(ctx, 0, sizeof(mbox_context)); |
| 39 | |
| 40 | mbox_vlog = &mbox_log_console; |
| 41 | verbosity = (verbose)2; |
| 42 | |
| 43 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 44 | init_vpnor_from_paths(ctx); |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 45 | |
| 46 | /* Test */ |
| 47 | memset(src, 0xaa, sizeof(src)); |
Andrew Jeffery | 0293f2f | 2018-08-08 16:59:45 +0930 | [diff] [blame] | 48 | rc = flash_write(ctx, 0x1000, src, sizeof(src)); |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 49 | assert(rc == 0); |
| 50 | |
| 51 | /* Verify */ |
| 52 | fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY); |
| 53 | assert(fd >= 0); |
Andrew Jeffery | 506f2f5 | 2018-03-27 12:13:25 +1030 | [diff] [blame] | 54 | map = mmap(NULL, sizeof(src), PROT_READ, MAP_SHARED, fd, 0); |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 55 | assert(map != MAP_FAILED); |
| 56 | |
| 57 | rc = memcmp(src, map, sizeof(src)); |
| 58 | assert(rc == 0); |
| 59 | munmap(map, sizeof(src)); |
| 60 | close(fd); |
| 61 | |
| 62 | /* Cleanup */ |
| 63 | destroy_vpnor(ctx); |
| 64 | |
| 65 | return 0; |
| 66 | } |