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"
1230bcf84cSAndrew Jeffery 
13261f61a1SAndrew Jeffery #include <cassert>
14261f61a1SAndrew Jeffery 
15*f4bc335bSAndrew Jeffery #include "vpnor/backend.h"
16261f61a1SAndrew Jeffery 
1730bcf84cSAndrew Jeffery const std::string toc[] = {
1830bcf84cSAndrew Jeffery     "partition01=HBB,00001000,00002000,80,ECC,READONLY",
1930bcf84cSAndrew Jeffery };
2030bcf84cSAndrew Jeffery 
2130bcf84cSAndrew Jeffery static const auto BLOCK_SIZE = 4096;
2230bcf84cSAndrew Jeffery static const auto MEM_SIZE = BLOCK_SIZE * 2;
2330bcf84cSAndrew Jeffery static const auto ERASE_SIZE = BLOCK_SIZE;
2430bcf84cSAndrew Jeffery static const auto N_WINDOWS = 1;
2530bcf84cSAndrew Jeffery static const auto WINDOW_SIZE = BLOCK_SIZE;
2630bcf84cSAndrew Jeffery 
2730bcf84cSAndrew Jeffery static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
2830bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2930bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00};
3030bcf84cSAndrew Jeffery 
3130bcf84cSAndrew Jeffery // offset 0x100 and size 6
3230bcf84cSAndrew Jeffery static const uint8_t create_write_window[] = {
3330bcf84cSAndrew Jeffery     0x06, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
3430bcf84cSAndrew Jeffery     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
3530bcf84cSAndrew Jeffery 
3630bcf84cSAndrew Jeffery static const uint8_t response[] = {0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
3730bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07};
3830bcf84cSAndrew Jeffery 
3930bcf84cSAndrew Jeffery namespace test = openpower::virtual_pnor::test;
4030bcf84cSAndrew Jeffery 
main()4130bcf84cSAndrew Jeffery int main()
4230bcf84cSAndrew Jeffery {
4330bcf84cSAndrew Jeffery     struct mbox_context* ctx;
4430bcf84cSAndrew Jeffery 
4530bcf84cSAndrew Jeffery     system_set_reserved_size(MEM_SIZE);
4630bcf84cSAndrew Jeffery     system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
4730bcf84cSAndrew Jeffery 
48f1e547c7SEvan Lojewski     ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
4930bcf84cSAndrew Jeffery 
50f1e547c7SEvan Lojewski     test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
5130bcf84cSAndrew Jeffery 
5230bcf84cSAndrew Jeffery     int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
5330bcf84cSAndrew Jeffery     assert(rc == 1);
5430bcf84cSAndrew Jeffery 
5530bcf84cSAndrew Jeffery     rc = mbox_command_dispatch(ctx, create_write_window,
5630bcf84cSAndrew Jeffery                                sizeof(create_write_window));
5730bcf84cSAndrew Jeffery     assert(rc == 7);
5830bcf84cSAndrew Jeffery 
5930bcf84cSAndrew Jeffery     rc = mbox_cmp(ctx, response, sizeof(response));
6030bcf84cSAndrew Jeffery     assert(rc == 0);
6130bcf84cSAndrew Jeffery 
6230bcf84cSAndrew Jeffery     return rc;
6330bcf84cSAndrew Jeffery }
64