blob: 69b4989453c9e501c5e48350f68ce3584c229c32 [file] [log] [blame]
Andrew Jefferyad341a22018-02-22 17:13:15 +10301// 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"
Andrew Jeffery26558db2018-08-10 00:22:38 +093012#include "mboxd.h"
Andrew Jeffery71eaa732018-08-08 16:44:24 +093013extern "C" {
Andrew Jefferyeebc6bd2018-08-08 10:38:19 +093014#include "flash.h"
Andrew Jeffery71eaa732018-08-08 16:44:24 +093015}
Andrew Jefferyad341a22018-02-22 17:13:15 +103016
Andrew Jeffery30bcf842018-03-26 12:13:20 +103017#include "vpnor/test/tmpd.hpp"
Andrew Jefferyad341a22018-02-22 17:13:15 +103018
19static constexpr auto BLOCK_SIZE = 0x1000;
20
21const std::string toc[] = {
22 "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED",
23};
24
25namespace test = openpower::virtual_pnor::test;
26
27int main(void)
28{
29 namespace fs = std::experimental::filesystem;
30
31 struct mbox_context _ctx, *ctx = &_ctx;
32 uint8_t src[8];
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070033 void* map;
Andrew Jefferyad341a22018-02-22 17:13:15 +103034 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 Jeffery742a1f62018-03-02 09:26:03 +103044 init_vpnor_from_paths(ctx);
Andrew Jefferyad341a22018-02-22 17:13:15 +103045
46 /* Test */
47 memset(src, 0xaa, sizeof(src));
Andrew Jeffery0293f2f2018-08-08 16:59:45 +093048 rc = flash_write(ctx, 0x1000, src, sizeof(src));
Andrew Jefferyad341a22018-02-22 17:13:15 +103049 assert(rc == 0);
50
51 /* Verify */
52 fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY);
53 assert(fd >= 0);
Andrew Jeffery506f2f52018-03-27 12:13:25 +103054 map = mmap(NULL, sizeof(src), PROT_READ, MAP_SHARED, fd, 0);
Andrew Jefferyad341a22018-02-22 17:13:15 +103055 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}