blob: 134a98e016392c2860d5952168b5a5a7475bf177 [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" {
Evan Lojewskif1e547c2019-03-14 14:34:33 +10305#include "backend.h"
Andrew Jeffery261f61a2019-03-14 09:57:28 +10306#include "common.h"
Andrew Jeffery261f61a2019-03-14 09:57:28 +10307#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
Evan Lojewskif1e547c2019-03-14 14:34:33 +103044 ctx->backend.flash_size = 0x2000;
45 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
Andrew Jefferyad341a22018-02-22 17:13:15 +103046
47 /* Test */
48 memset(src, 0xaa, sizeof(src));
Andrew Jeffery0297e5b2019-03-14 16:36:27 +103049 rc = backend_write(&ctx->backend, 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
Andrew Jefferyad341a22018-02-22 17:13:15 +103063 return 0;
64}