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