blob: 53f3cfef29e07ae34afcdc2e3705d024a29bb70d [file] [log] [blame]
Andrew Jefferyad341a22018-02-22 17:13:15 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
Andrew Jeffery261f61a2019-03-14 09:57:28 +10304extern "C" {
5#include "common.h"
6#include "flash.h"
7#include "mboxd.h"
8}
9
10#include "vpnor/test/tmpd.hpp"
11
Andrew Jefferyad341a22018-02-22 17:13:15 +103012#include <fcntl.h>
13#include <sys/mman.h>
14#include <sys/stat.h>
15#include <sys/types.h>
16#include <unistd.h>
17
Andrew Jeffery261f61a2019-03-14 09:57:28 +103018#include <cassert>
Andrew Jefferyad341a22018-02-22 17:13:15 +103019
20static constexpr auto BLOCK_SIZE = 0x1000;
21
22const std::string toc[] = {
23 "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED",
24};
25
26namespace test = openpower::virtual_pnor::test;
27
28int 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 IIId5f1d402018-10-11 13:55:04 -070034 void* map;
Andrew Jefferyad341a22018-02-22 17:13:15 +103035 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 Jeffery742a1f62018-03-02 09:26:03 +103045 init_vpnor_from_paths(ctx);
Andrew Jefferyad341a22018-02-22 17:13:15 +103046
47 /* Test */
48 memset(src, 0xaa, sizeof(src));
Andrew Jeffery0293f2f2018-08-08 16:59:45 +093049 rc = flash_write(ctx, 0x1000, src, sizeof(src));
Andrew Jefferyad341a22018-02-22 17:13:15 +103050 assert(rc == 0);
51
52 /* Verify */
53 fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY);
54 assert(fd >= 0);
Andrew Jeffery506f2f52018-03-27 12:13:25 +103055 map = mmap(NULL, sizeof(src), PROT_READ, MAP_SHARED, fd, 0);
Andrew Jefferyad341a22018-02-22 17:13:15 +103056 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}