1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 #include "config.h" 5 6 extern "C" { 7 #include "test/mbox.h" 8 #include "test/system.h" 9 } 10 11 #include "vpnor/test/tmpd.hpp" 12 13 #include <cassert> 14 #include <experimental/filesystem> 15 16 #include "vpnor/mboxd_pnor_partition_table.h" 17 18 static const auto BLOCK_SIZE = 4096; 19 static const auto ERASE_SIZE = BLOCK_SIZE; 20 static const auto WINDOW_SIZE = 2 * BLOCK_SIZE; 21 static const auto MEM_SIZE = WINDOW_SIZE; 22 static const auto N_WINDOWS = 1; 23 static const auto PNOR_SIZE = 4 * BLOCK_SIZE; 24 25 const std::string toc[] = { 26 "partition01=ONE,00001000,00002000,80,ECC,READONLY", 27 "partition02=TWO,00002000,00004000,80,ECC,READONLY", 28 }; 29 30 static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 0x00, 0x00, 0x00, 0x00}; 33 34 static const uint8_t request_one[] = {0x04, 0x01, 0x01, 0x00, 0x02, 0x00, 35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 0x00, 0x00, 0x00, 0x00}; 37 38 static const uint8_t response_one[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 39 0x00, 0x01, 0x00, 0x00, 0x00, 40 0x00, 0x00, 0x00, 0x01}; 41 42 static const uint8_t request_two[] = {0x04, 0x02, 0x02, 0x00, 0x02, 0x00, 43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 0x00, 0x00, 0x00, 0x00}; 45 46 static const uint8_t response_two[] = {0x04, 0x02, 0xfe, 0xff, 0x02, 47 0x00, 0x02, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x01}; 49 50 namespace test = openpower::virtual_pnor::test; 51 52 int main() 53 { 54 struct mbox_context* ctx; 55 56 system_set_reserved_size(MEM_SIZE); 57 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); 58 59 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); 60 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); 61 62 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); 63 assert(rc == 1); 64 65 rc = mbox_command_dispatch(ctx, request_one, sizeof(request_one)); 66 assert(rc == 1); 67 68 rc = mbox_cmp(ctx, response_one, sizeof(response_one)); 69 assert(rc == 0); 70 71 rc = mbox_command_dispatch(ctx, request_two, sizeof(request_two)); 72 assert(rc == 1); 73 74 rc = mbox_cmp(ctx, response_two, sizeof(response_two)); 75 assert(rc == 0); 76 77 return rc; 78 } 79