Andrew Jeffery | 2b73f17 | 2018-03-01 13:06:29 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
| 4 | #include "config.h" |
| 5 | |
Andrew Jeffery | 2b73f17 | 2018-03-01 13:06:29 +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 | 2b73f17 | 2018-03-01 13:06:29 +1030 | [diff] [blame] | 12 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 13 | #include <cassert> |
| 14 | #include <cstring> |
| 15 | |
| 16 | #include "vpnor/mboxd_pnor_partition_table.h" |
| 17 | |
Andrew Jeffery | 2b73f17 | 2018-03-01 13:06:29 +1030 | [diff] [blame] | 18 | const std::string toc[] = { |
| 19 | "partition01=ONE,00001000,00002000,80,ECC,READONLY", |
| 20 | "partition02=TWO,00002000,00003000,80,ECC,READONLY", |
| 21 | }; |
| 22 | |
| 23 | uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab}; |
| 24 | |
| 25 | static constexpr auto BLOCK_SIZE = 0x1000; |
| 26 | static constexpr auto MEM_SIZE = BLOCK_SIZE * 2; |
| 27 | static constexpr auto ERASE_SIZE = BLOCK_SIZE; |
| 28 | static constexpr auto N_WINDOWS = 1; |
| 29 | static constexpr auto WINDOW_SIZE = MEM_SIZE; |
| 30 | static constexpr auto PNOR_SIZE = MEM_SIZE * 2; |
| 31 | |
| 32 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 34 | 0x00, 0x00, 0x00, 0x00}; |
| 35 | |
| 36 | static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x02, 0x00, |
| 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 38 | 0x00, 0x00, 0x00, 0x00}; |
| 39 | |
| 40 | static const uint8_t response[] = { |
| 41 | 0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01, |
| 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 43 | }; |
| 44 | |
| 45 | int main() |
| 46 | { |
| 47 | namespace test = openpower::virtual_pnor::test; |
| 48 | namespace fs = std::experimental::filesystem; |
| 49 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 50 | struct mbox_context* ctx; |
Andrew Jeffery | 2b73f17 | 2018-03-01 13:06:29 +1030 | [diff] [blame] | 51 | |
| 52 | system_set_reserved_size(MEM_SIZE); |
| 53 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
| 54 | |
| 55 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 56 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 57 | init_vpnor_from_paths(ctx); |
Andrew Jeffery | 2b73f17 | 2018-03-01 13:06:29 +1030 | [diff] [blame] | 58 | |
| 59 | int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 60 | assert(rc == 1); |
| 61 | |
| 62 | // Request a read window that would cover both partitions. With the current |
| 63 | // behaviour, we expect to receive a reply describing a window that covers |
| 64 | // the first partition but is limited in size to exclude the second |
| 65 | // partition. |
| 66 | rc = mbox_command_dispatch(ctx, create_read_window, |
| 67 | sizeof(create_read_window)); |
| 68 | assert(rc == 1); |
| 69 | |
| 70 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 71 | assert(rc == 0); |
| 72 | |
| 73 | return 0; |
| 74 | } |