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