130bcf84cSAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
230bcf84cSAndrew Jeffery // Copyright (C) 2018 IBM Corp.
330bcf84cSAndrew Jeffery 
4d5f1d40fSWilliam A. Kennington III #include "config.h"
5d5f1d40fSWilliam A. Kennington III 
630bcf84cSAndrew Jeffery extern "C" {
730bcf84cSAndrew Jeffery #include "test/mbox.h"
830bcf84cSAndrew Jeffery #include "test/system.h"
930bcf84cSAndrew Jeffery }
1030bcf84cSAndrew Jeffery 
1130bcf84cSAndrew Jeffery #include "vpnor/test/tmpd.hpp"
12261f61a1SAndrew Jeffery 
13261f61a1SAndrew Jeffery #include <cassert>
14*150be912SPatrick Williams #include <filesystem>
15261f61a1SAndrew Jeffery 
16f4bc335bSAndrew Jeffery #include "vpnor/backend.h"
17261f61a1SAndrew Jeffery 
1830bcf84cSAndrew Jeffery static const auto BLOCK_SIZE = 4096;
1930bcf84cSAndrew Jeffery static const auto ERASE_SIZE = BLOCK_SIZE;
2030bcf84cSAndrew Jeffery static const auto WINDOW_SIZE = 2 * BLOCK_SIZE;
2130bcf84cSAndrew Jeffery static const auto MEM_SIZE = WINDOW_SIZE;
2230bcf84cSAndrew Jeffery static const auto N_WINDOWS = 1;
2330bcf84cSAndrew Jeffery static const auto PNOR_SIZE = 4 * BLOCK_SIZE;
2430bcf84cSAndrew Jeffery 
2530bcf84cSAndrew Jeffery const std::string toc[] = {
2630bcf84cSAndrew Jeffery     "partition01=ONE,00001000,00002000,80,ECC,READONLY",
2730bcf84cSAndrew Jeffery     "partition02=TWO,00002000,00004000,80,ECC,READONLY",
2830bcf84cSAndrew Jeffery };
2930bcf84cSAndrew Jeffery 
3030bcf84cSAndrew Jeffery static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
3130bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3230bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00};
3330bcf84cSAndrew Jeffery 
3430bcf84cSAndrew Jeffery static const uint8_t request_one[] = {0x04, 0x01, 0x01, 0x00, 0x02, 0x00,
3530bcf84cSAndrew Jeffery                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3630bcf84cSAndrew Jeffery                                       0x00, 0x00, 0x00, 0x00};
3730bcf84cSAndrew Jeffery 
3830bcf84cSAndrew Jeffery static const uint8_t response_one[] = {0x04, 0x01, 0xfe, 0xff, 0x01,
3930bcf84cSAndrew Jeffery                                        0x00, 0x01, 0x00, 0x00, 0x00,
4030bcf84cSAndrew Jeffery                                        0x00, 0x00, 0x00, 0x01};
4130bcf84cSAndrew Jeffery 
4230bcf84cSAndrew Jeffery static const uint8_t request_two[] = {0x04, 0x02, 0x02, 0x00, 0x02, 0x00,
4330bcf84cSAndrew Jeffery                                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4430bcf84cSAndrew Jeffery                                       0x00, 0x00, 0x00, 0x00};
4530bcf84cSAndrew Jeffery 
4630bcf84cSAndrew Jeffery static const uint8_t response_two[] = {0x04, 0x02, 0xfe, 0xff, 0x02,
4730bcf84cSAndrew Jeffery                                        0x00, 0x02, 0x00, 0x00, 0x00,
4830bcf84cSAndrew Jeffery                                        0x00, 0x00, 0x00, 0x01};
4930bcf84cSAndrew Jeffery 
5030bcf84cSAndrew Jeffery namespace test = openpower::virtual_pnor::test;
5130bcf84cSAndrew Jeffery 
main()5230bcf84cSAndrew Jeffery int main()
5330bcf84cSAndrew Jeffery {
5430bcf84cSAndrew Jeffery     struct mbox_context* ctx;
5530bcf84cSAndrew Jeffery 
5630bcf84cSAndrew Jeffery     system_set_reserved_size(MEM_SIZE);
5730bcf84cSAndrew Jeffery     system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
5830bcf84cSAndrew Jeffery 
59f1e547c7SEvan Lojewski     ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
60f1e547c7SEvan Lojewski     test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
6130bcf84cSAndrew Jeffery 
6230bcf84cSAndrew Jeffery     int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
6330bcf84cSAndrew Jeffery     assert(rc == 1);
6430bcf84cSAndrew Jeffery 
6530bcf84cSAndrew Jeffery     rc = mbox_command_dispatch(ctx, request_one, sizeof(request_one));
6630bcf84cSAndrew Jeffery     assert(rc == 1);
6730bcf84cSAndrew Jeffery 
6830bcf84cSAndrew Jeffery     rc = mbox_cmp(ctx, response_one, sizeof(response_one));
6930bcf84cSAndrew Jeffery     assert(rc == 0);
7030bcf84cSAndrew Jeffery 
7130bcf84cSAndrew Jeffery     rc = mbox_command_dispatch(ctx, request_two, sizeof(request_two));
7230bcf84cSAndrew Jeffery     assert(rc == 1);
7330bcf84cSAndrew Jeffery 
7430bcf84cSAndrew Jeffery     rc = mbox_cmp(ctx, response_two, sizeof(response_two));
7530bcf84cSAndrew Jeffery     assert(rc == 0);
7630bcf84cSAndrew Jeffery 
7730bcf84cSAndrew Jeffery     return rc;
7830bcf84cSAndrew Jeffery }
79