1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 extern "C" { 5 #include "backend.h" 6 #include "common.h" 7 #include "mboxd.h" 8 } 9 10 #include "vpnor/test/tmpd.hpp" 11 12 #include <fcntl.h> 13 #include <sys/mman.h> 14 #include <sys/stat.h> 15 #include <sys/types.h> 16 #include <unistd.h> 17 18 #include <cassert> 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]; 34 void* map; 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 ctx->backend.flash_size = 0x2000; 45 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); 46 47 /* Test */ 48 memset(src, 0xaa, sizeof(src)); 49 rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src)); 50 assert(rc == 0); 51 52 /* Verify */ 53 fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY); 54 assert(fd >= 0); 55 map = mmap(NULL, sizeof(src), PROT_READ, MAP_SHARED, fd, 0); 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 return 0; 64 } 65