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" { |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 5 | #include "backend.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 6 | #include "common.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 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 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 44 | ctx->backend.flash_size = 0x2000; |
| 45 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 46 | |
| 47 | /* Test */ |
| 48 | memset(src, 0xaa, sizeof(src)); |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 49 | rc = backend_write(&ctx->backend, 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 | |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 63 | return 0; |
| 64 | } |