xref: /openbmc/hiomapd/test/sequence_numbers.c (revision 26558dbb00e439fb6ea18566361c0671ea6133f5)
14fe996c2SAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
24fe996c2SAndrew Jeffery // Copyright (C) 2018 IBM Corp.
3cbbc13c3SAndrew Jeffery 
4cbbc13c3SAndrew Jeffery #include <assert.h>
5cbbc13c3SAndrew Jeffery 
6*26558dbbSAndrew Jeffery #include "mboxd.h"
7457a6e5fSAndrew Jeffery #include "transport_mbox.h"
8cbbc13c3SAndrew Jeffery 
9cbbc13c3SAndrew Jeffery #include "test/mbox.h"
10cbbc13c3SAndrew Jeffery #include "test/system.h"
11cbbc13c3SAndrew Jeffery 
12cbbc13c3SAndrew Jeffery static const uint8_t get_mbox_info[] = {
13cbbc13c3SAndrew Jeffery 	0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
14cbbc13c3SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
15cbbc13c3SAndrew Jeffery };
16cbbc13c3SAndrew Jeffery 
17cbbc13c3SAndrew Jeffery static const uint8_t get_mbox_info_response[] = {
18cbbc13c3SAndrew Jeffery 	0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
19cbbc13c3SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
20cbbc13c3SAndrew Jeffery };
21cbbc13c3SAndrew Jeffery 
22cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info0[] = {
23cbbc13c3SAndrew Jeffery 	0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24cbbc13c3SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
25cbbc13c3SAndrew Jeffery };
26cbbc13c3SAndrew Jeffery 
27cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info_response0[] = {
28cbbc13c3SAndrew Jeffery 	0x03, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00,
29cbbc13c3SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x01
30cbbc13c3SAndrew Jeffery };
31cbbc13c3SAndrew Jeffery 
32cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info1[] = {
33cbbc13c3SAndrew Jeffery 	0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34cbbc13c3SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
35cbbc13c3SAndrew Jeffery };
36cbbc13c3SAndrew Jeffery 
37cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info_response1[] = {
38cbbc13c3SAndrew Jeffery 	0x03, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00,
39cbbc13c3SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x01
40cbbc13c3SAndrew Jeffery };
41cbbc13c3SAndrew Jeffery 
42cbbc13c3SAndrew Jeffery #define MEM_SIZE	3
43cbbc13c3SAndrew Jeffery #define ERASE_SIZE	1
44cbbc13c3SAndrew Jeffery #define N_WINDOWS	1
45cbbc13c3SAndrew Jeffery #define WINDOW_SIZE	1
46cbbc13c3SAndrew Jeffery 
main(void)47cbbc13c3SAndrew Jeffery int main(void)
48cbbc13c3SAndrew Jeffery {
49cbbc13c3SAndrew Jeffery 	struct mbox_context *ctx;
50cbbc13c3SAndrew Jeffery 	int rc;
51cbbc13c3SAndrew Jeffery 
52cbbc13c3SAndrew Jeffery 	system_set_reserved_size(MEM_SIZE);
53cbbc13c3SAndrew Jeffery 	system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
54cbbc13c3SAndrew Jeffery 
55cbbc13c3SAndrew Jeffery 	ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
56cbbc13c3SAndrew Jeffery 
57cbbc13c3SAndrew Jeffery 	/* Consecutive GET_MBOX_INFOs can use "invalid" sequence numbers */
58cbbc13c3SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info));
59cbbc13c3SAndrew Jeffery 	assert(rc == 1);
60cbbc13c3SAndrew Jeffery 
61cbbc13c3SAndrew Jeffery 	rc = mbox_cmp(ctx, get_mbox_info_response,
62cbbc13c3SAndrew Jeffery 			sizeof(get_mbox_info_response));
63cbbc13c3SAndrew Jeffery 	assert(rc == 0);
64cbbc13c3SAndrew Jeffery 
65cbbc13c3SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info));
66cbbc13c3SAndrew Jeffery 	assert(rc == 1);
67cbbc13c3SAndrew Jeffery 
68cbbc13c3SAndrew Jeffery 	/* Other commands must use valid sequence numbers */
69cbbc13c3SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_flash_info0,
70cbbc13c3SAndrew Jeffery 			sizeof(get_flash_info0));
71cbbc13c3SAndrew Jeffery 	assert(rc == 1);
72cbbc13c3SAndrew Jeffery 
73cbbc13c3SAndrew Jeffery 	rc = mbox_cmp(ctx, get_flash_info_response0,
74cbbc13c3SAndrew Jeffery 			sizeof(get_flash_info_response0));
75cbbc13c3SAndrew Jeffery 	assert(rc == 0);
76cbbc13c3SAndrew Jeffery 
77cbbc13c3SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_flash_info0,
78cbbc13c3SAndrew Jeffery 			sizeof(get_flash_info0));
79cbbc13c3SAndrew Jeffery 	assert(rc == 8);
80cbbc13c3SAndrew Jeffery 
81cbbc13c3SAndrew Jeffery 	/* Retry with a "valid" sequence number */
82cbbc13c3SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_flash_info1,
83cbbc13c3SAndrew Jeffery 			sizeof(get_flash_info1));
84cbbc13c3SAndrew Jeffery 	assert(rc == 1);
85cbbc13c3SAndrew Jeffery 
86cbbc13c3SAndrew Jeffery 	rc = mbox_cmp(ctx, get_flash_info_response1,
87cbbc13c3SAndrew Jeffery 			sizeof(get_flash_info_response1));
88cbbc13c3SAndrew Jeffery 	assert(rc == 0);
89cbbc13c3SAndrew Jeffery 
90cbbc13c3SAndrew Jeffery 	return rc;
91cbbc13c3SAndrew Jeffery }
92