Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 4 | #include "config.h" |
| 5 | |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 6 | extern "C" { |
| 7 | #include "test/mbox.h" |
| 8 | #include "test/system.h" |
| 9 | } |
| 10 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 11 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 12 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 13 | #include <cassert> |
| 14 | #include <cstring> |
| 15 | #include <experimental/filesystem> |
| 16 | #include <fstream> |
| 17 | #include <vector> |
| 18 | |
Andrew Jeffery | f4bc335 | 2019-03-18 12:09:48 +1030 | [diff] [blame^] | 19 | #include "vpnor/backend.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 20 | |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 21 | static const auto BLOCK_SIZE = 4096; |
| 22 | static const auto ERASE_SIZE = BLOCK_SIZE; |
| 23 | static const auto WINDOW_SIZE = 16 * BLOCK_SIZE; |
| 24 | static const auto N_WINDOWS = 2; |
| 25 | static const auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE; |
| 26 | |
| 27 | const std::string toc[] = { |
| 28 | "partition01=ONE,00001000,00011000,80,ECC,READONLY", |
| 29 | }; |
| 30 | |
| 31 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 33 | 0x00, 0x00, 0x00, 0x00}; |
| 34 | |
| 35 | namespace test = openpower::virtual_pnor::test; |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | uint8_t request[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 41 | |
| 42 | uint8_t response[] = {0x04, 0x01, 0xe0, 0xff, 0x10, 0x00, 0x01, |
| 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
| 44 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 45 | struct mbox_context* ctx; |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 46 | |
| 47 | system_set_reserved_size(MEM_SIZE); |
| 48 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 49 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 50 | ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); |
| 51 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 52 | |
| 53 | int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 54 | assert(rc == 1); |
| 55 | |
| 56 | for (int i = 1; i < (0x10000 / BLOCK_SIZE); i++) |
| 57 | { |
| 58 | /* Update the requested offset */ |
| 59 | put_u16(&request[2], i); |
| 60 | |
| 61 | /* |
| 62 | * Reuse the offset as a sequence number, because it's unique. Request |
| 63 | * and response have the same sequence number |
| 64 | */ |
| 65 | request[1] = i; |
| 66 | response[1] = i; |
| 67 | |
| 68 | rc = mbox_command_dispatch(ctx, request, sizeof(request)); |
| 69 | assert(rc == 1); |
| 70 | |
| 71 | /* Check that it maps to the same window each time */ |
| 72 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 73 | assert(rc == 0); |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |