summaryrefslogtreecommitdiffstats
path: root/test/windows_equally_evictable.c
blob: e54343b53e7e761d2e07d44378f3833d91fdf2d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.

#include <assert.h>
#include <string.h>

#include "config.h"
#include "transport_mbox.h"
#include "windows.h"

#include "test/mbox.h"
#include "test/system.h"

struct test_context
{
    uint8_t seq;
    struct mbox_context *ctx;
};

// Configure the system and the paritions such that we eventually request a
// window that covers the last section of flash, but the remaining flash is
// smaller than the window size
#define BLOCK_SIZE	4096
#define ERASE_SIZE	BLOCK_SIZE
#define N_WINDOWS	3
#define WINDOW_SIZE	BLOCK_SIZE
#define MEM_SIZE	(N_WINDOWS * WINDOW_SIZE)
#define PNOR_SIZE	((N_WINDOWS + 1) * WINDOW_SIZE)

static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00};

#define MBOX_CREATE_READ_WINDOW 4

static int mbox_create_read_window(struct test_context *tctx, size_t offset,
                                   size_t len)
{
    union mbox_regs regs;

    memset(&regs, 0, sizeof(regs));
    regs.msg.command = MBOX_CREATE_READ_WINDOW;
    regs.msg.seq = ++tctx->seq;
    put_u16(&regs.msg.args[0], offset);
    put_u16(&regs.msg.args[2], len);

    return mbox_command_dispatch(tctx->ctx, regs.raw, sizeof(regs.raw));
}

int main()
{
    struct test_context _tctx = {0}, *tctx = &_tctx;
    size_t len;
    size_t pos;
    int rc;

    system_set_reserved_size(MEM_SIZE);
    system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);

    tctx->ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);

    rc = mbox_command_dispatch(tctx->ctx, get_info, sizeof(get_info));
    assert(rc == 1);

    pos = 0;
    while (pos < ((PNOR_SIZE - BLOCK_SIZE) / BLOCK_SIZE))
    {
        struct mbox_msg _msg, *msg = &_msg;

        rc = mbox_create_read_window(tctx, pos, (WINDOW_SIZE / BLOCK_SIZE));
        assert(rc == 1);

        mbox_rspcpy(tctx->ctx, msg);

        len = get_u16(&msg->args[2]);
        pos = get_u16(&msg->args[4]) + len;
    }

    windows_reset_all(tctx->ctx);

    rc = mbox_create_read_window(tctx, pos, (WINDOW_SIZE / BLOCK_SIZE));
    assert(rc == 1);

    return 0;
}
OpenPOWER on IntegriCloud