1 |
49 |
magro732 |
/*******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* RapidIO IP Library Core
|
4 |
|
|
*
|
5 |
|
|
* This file is part of the RapidIO IP library project
|
6 |
|
|
* http://www.opencores.org/cores/rio/
|
7 |
|
|
*
|
8 |
|
|
* Description:
|
9 |
|
|
* This file contains automatic regression tests for riopacket. Compile and
|
10 |
|
|
* run it by using:
|
11 |
|
|
* gcc -o testriopacket test_riopacket.c -fprofile-arcs -ftest-coverage
|
12 |
|
|
* ./testriopacket
|
13 |
|
|
* gcov test_riopacket.c
|
14 |
|
|
*
|
15 |
|
|
* To Do:
|
16 |
|
|
* -
|
17 |
|
|
*
|
18 |
|
|
* Author(s):
|
19 |
|
|
* - Magnus Rosenius, magro732@opencores.org
|
20 |
|
|
*
|
21 |
|
|
*******************************************************************************
|
22 |
|
|
*
|
23 |
|
|
* Copyright (C) 2015 Authors and OPENCORES.ORG
|
24 |
|
|
*
|
25 |
|
|
* This source file may be used and distributed without
|
26 |
|
|
* restriction provided that this copyright statement is not
|
27 |
|
|
* removed from the file and that any derivative work contains
|
28 |
|
|
* the original copyright notice and the associated disclaimer.
|
29 |
|
|
*
|
30 |
|
|
* This source file is free software; you can redistribute it
|
31 |
|
|
* and/or modify it under the terms of the GNU Lesser General
|
32 |
|
|
* Public License as published by the Free Software Foundation;
|
33 |
|
|
* either version 2.1 of the License, or (at your option) any
|
34 |
|
|
* later version.
|
35 |
|
|
*
|
36 |
|
|
* This source is distributed in the hope that it will be
|
37 |
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
38 |
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
39 |
|
|
* PURPOSE. See the GNU Lesser General Public License for more
|
40 |
|
|
* details.
|
41 |
|
|
*
|
42 |
|
|
* You should have received a copy of the GNU Lesser General
|
43 |
|
|
* Public License along with this source; if not, download it
|
44 |
|
|
* from http://www.opencores.org/lgpl.shtml
|
45 |
|
|
*
|
46 |
|
|
*******************************************************************************/
|
47 |
|
|
|
48 |
|
|
#include <stdio.h>
|
49 |
|
|
#include <stdlib.h>
|
50 |
|
|
|
51 |
|
|
#define MODULE_TEST
|
52 |
|
|
#include "riopacket.c"
|
53 |
|
|
|
54 |
|
|
#define PrintS(s) \
|
55 |
|
|
{ \
|
56 |
|
|
FILE *fd; \
|
57 |
|
|
fd=fopen("testspec.txt", "a"); \
|
58 |
|
|
fputs(s "\n", fd); \
|
59 |
|
|
fclose(fd); \
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
#define TESTSTART(s) printf(s)
|
63 |
|
|
#define TESTEND printf(" passed.\n");
|
64 |
|
|
|
65 |
|
|
#define TESTCOND(got) \
|
66 |
|
|
if (!(got)) \
|
67 |
|
|
{ \
|
68 |
|
|
printf("\nERROR at line %u:%s=%u (0x%08x)\n", \
|
69 |
|
|
__LINE__, #got, (got), (got)); \
|
70 |
|
|
exit(1); \
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
#define TESTEXPR(got, expected) \
|
74 |
|
|
if ((got)!=(expected)) \
|
75 |
|
|
{ \
|
76 |
|
|
printf("\nERROR at line %u:%s=%u (0x%08x) expected=%u (0x%08x)\n", \
|
77 |
|
|
__LINE__, #got, (got), (got), (expected), (expected)); \
|
78 |
|
|
exit(1); \
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
#define TESTPACKET(got, expected) testSymbol(__LINE__, #got, (got), (expected))
|
82 |
|
|
|
83 |
|
|
void testPacket(uint32_t line, char *expression, RioPacket_t got, RioPacket_t expected)
|
84 |
|
|
{
|
85 |
|
|
int i;
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
if ((got).size==(expected).size)
|
89 |
|
|
{
|
90 |
|
|
for(i = 0; i < got.size; i++)
|
91 |
|
|
{
|
92 |
|
|
if(got.payload[i] != expected.payload[i])
|
93 |
|
|
{
|
94 |
|
|
printf("\nERROR at line %u:%s:payload[%u]:=%u (0x%08x) expected=%u (0x%08x)\n",
|
95 |
|
|
line, expression, i, (got).payload[i], (got).payload[i], (expected).payload[i], (expected).payload[i]);
|
96 |
|
|
exit(1);
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
else
|
101 |
|
|
{
|
102 |
|
|
printf("\nERROR at line %u:%s:size=%u (0x%08x) expected=%u (0x%08x)\n",
|
103 |
|
|
line, expression, (got).size, (got).size, (expected).size, (expected).size);
|
104 |
|
|
exit(1);
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
void packetClear(RioPacket_t *packet)
|
109 |
|
|
{
|
110 |
|
|
uint32_t i;
|
111 |
|
|
|
112 |
|
|
for(i = 0; i < RIOPACKET_SIZE_MAX; i++)
|
113 |
|
|
{
|
114 |
|
|
packet->payload[i] = 0xdeadbeef;
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
/*******************************************************************************
|
119 |
|
|
* Module test for this file.
|
120 |
|
|
*******************************************************************************/
|
121 |
|
|
int32_t main(void)
|
122 |
|
|
{
|
123 |
|
|
RioPacket_t packet;
|
124 |
|
|
int i, j, k;
|
125 |
|
|
uint16_t length;
|
126 |
|
|
uint16_t dstidExpected, dstid;
|
127 |
|
|
uint16_t srcidExpected, srcid;
|
128 |
|
|
uint8_t tidExpected, tid;
|
129 |
|
|
uint8_t hopExpected, hop;
|
130 |
|
|
uint8_t mailboxExpected, mailbox;
|
131 |
|
|
uint16_t infoExpected, info;
|
132 |
|
|
uint32_t addressExpected, address;
|
133 |
|
|
uint32_t dataExpected, data;
|
134 |
|
|
|
135 |
|
|
uint16_t payloadSizeExpected, payloadSize;
|
136 |
|
|
uint8_t payloadExpected[256], payload[256];
|
137 |
|
|
|
138 |
|
|
uint8_t buffer[512];
|
139 |
|
|
uint16_t bufferSize;
|
140 |
|
|
|
141 |
|
|
srand(0);
|
142 |
|
|
|
143 |
|
|
/******************************************************************************/
|
144 |
|
|
PrintS("----------------------------------------------------------------------");
|
145 |
|
|
PrintS("TG_riopacket-TC1");
|
146 |
|
|
PrintS("Description: Test packet initialization, validation and appending.");
|
147 |
|
|
PrintS("Requirement: XXXXX");
|
148 |
|
|
PrintS("----------------------------------------------------------------------");
|
149 |
|
|
PrintS("Step 1:");
|
150 |
|
|
PrintS("Action: ");
|
151 |
|
|
PrintS("Result: ");
|
152 |
|
|
PrintS("----------------------------------------------------------------------");
|
153 |
|
|
/******************************************************************************/
|
154 |
|
|
TESTSTART("TG_riostack-TC1-Step1");
|
155 |
|
|
/******************************************************************************/
|
156 |
|
|
|
157 |
|
|
RIOPACKET_init(&packet);
|
158 |
|
|
|
159 |
|
|
TESTEXPR(RIOPACKET_size(&packet), 0);
|
160 |
|
|
TESTCOND(!RIOPACKET_valid(&packet));
|
161 |
|
|
|
162 |
|
|
RIOPACKET_append(&packet, 0x001a0001);
|
163 |
|
|
|
164 |
|
|
TESTEXPR(RIOPACKET_size(&packet), 1);
|
165 |
|
|
TESTCOND(!RIOPACKET_valid(&packet));
|
166 |
|
|
|
167 |
|
|
RIOPACKET_append(&packet, 0xffff0000);
|
168 |
|
|
|
169 |
|
|
TESTEXPR(RIOPACKET_size(&packet), 2);
|
170 |
|
|
TESTCOND(!RIOPACKET_valid(&packet));
|
171 |
|
|
|
172 |
|
|
RIOPACKET_append(&packet, 0xdeaf9903);
|
173 |
|
|
|
174 |
|
|
TESTEXPR(RIOPACKET_size(&packet), 3);
|
175 |
|
|
TESTCOND(RIOPACKET_valid(&packet));
|
176 |
|
|
|
177 |
|
|
/* Check that altering the ackid does not affect the validity of the packet. */
|
178 |
|
|
packet.payload[0] |= 0xfc000000;
|
179 |
|
|
TESTCOND(RIOPACKET_valid(&packet));
|
180 |
|
|
|
181 |
|
|
/* Access the packet and check its content. */
|
182 |
|
|
TESTEXPR(RIOPACKET_getFtype(&packet), RIOPACKET_FTYPE_DOORBELL);
|
183 |
|
|
TESTEXPR(RIOPACKET_getDestination(&packet), 0x0001);
|
184 |
|
|
TESTEXPR(RIOPACKET_getSource(&packet), 0xffff);
|
185 |
|
|
TESTEXPR(RIOPACKET_getTid(&packet), 0x00);
|
186 |
|
|
RIOPACKET_getDoorbell(&packet, &dstid, &srcid, &tid, &info);
|
187 |
|
|
TESTEXPR(dstid, 0x0001);
|
188 |
|
|
TESTEXPR(srcid, 0xffff);
|
189 |
|
|
TESTEXPR(tid, 0x00);
|
190 |
|
|
TESTEXPR(info, 0xdeaf);
|
191 |
|
|
|
192 |
|
|
bufferSize = RIOPACKET_serialize(&packet, sizeof(buffer), buffer);
|
193 |
|
|
TESTEXPR(bufferSize, 13);
|
194 |
|
|
TESTEXPR(buffer[0], 0x03);
|
195 |
|
|
TESTEXPR(buffer[1], 0xfc);
|
196 |
|
|
TESTEXPR(buffer[2], 0x1a);
|
197 |
|
|
TESTEXPR(buffer[3], 0x00);
|
198 |
|
|
TESTEXPR(buffer[4], 0x01);
|
199 |
|
|
TESTEXPR(buffer[5], 0xff);
|
200 |
|
|
TESTEXPR(buffer[6], 0xff);
|
201 |
|
|
TESTEXPR(buffer[7], 0x00);
|
202 |
|
|
TESTEXPR(buffer[8], 0x00);
|
203 |
|
|
TESTEXPR(buffer[9], 0xde);
|
204 |
|
|
TESTEXPR(buffer[10], 0xaf);
|
205 |
|
|
TESTEXPR(buffer[11], 0x99);
|
206 |
|
|
TESTEXPR(buffer[12], 0x03);
|
207 |
|
|
|
208 |
|
|
RIOPACKET_init(&packet);
|
209 |
|
|
RIOPACKET_deserialize(&packet, bufferSize, buffer);
|
210 |
|
|
TESTCOND(RIOPACKET_valid(&packet));
|
211 |
|
|
TESTEXPR(RIOPACKET_getFtype(&packet), RIOPACKET_FTYPE_DOORBELL);
|
212 |
|
|
TESTEXPR(RIOPACKET_getDestination(&packet), 0x0001);
|
213 |
|
|
TESTEXPR(RIOPACKET_getSource(&packet), 0xffff);
|
214 |
|
|
TESTEXPR(RIOPACKET_getTid(&packet), 0x00);
|
215 |
|
|
RIOPACKET_getDoorbell(&packet, &dstid, &srcid, &tid, &info);
|
216 |
|
|
TESTEXPR(dstid, 0x0001);
|
217 |
|
|
TESTEXPR(srcid, 0xffff);
|
218 |
|
|
TESTEXPR(tid, 0x00);
|
219 |
|
|
TESTEXPR(info, 0xdeaf);
|
220 |
|
|
|
221 |
|
|
/******************************************************************************/
|
222 |
|
|
TESTEND;
|
223 |
|
|
/******************************************************************************/
|
224 |
|
|
/******************************************************************************/
|
225 |
|
|
PrintS("----------------------------------------------------------------------");
|
226 |
|
|
PrintS("TG_riopacket-TC2");
|
227 |
|
|
PrintS("Description: Test maintenance packets.");
|
228 |
|
|
PrintS("Requirement: XXXXX");
|
229 |
|
|
PrintS("----------------------------------------------------------------------");
|
230 |
|
|
PrintS("Step 1:");
|
231 |
|
|
PrintS("Action: ");
|
232 |
|
|
PrintS("Result: ");
|
233 |
|
|
PrintS("----------------------------------------------------------------------");
|
234 |
|
|
/******************************************************************************/
|
235 |
|
|
TESTSTART("TG_riostack-TC2-Step1");
|
236 |
|
|
/******************************************************************************/
|
237 |
|
|
|
238 |
|
|
RIOPACKET_init(&packet);
|
239 |
|
|
RIOPACKET_setMaintReadRequest(&packet, 0xc0de, 0xbabe, 0x13, 0x41, 0xffffffff);
|
240 |
|
|
RIOPACKET_getMaintReadRequest(&packet, &dstid, &srcid, &hop, &tid, &address);
|
241 |
|
|
|
242 |
|
|
TESTCOND(RIOPACKET_valid(&packet));
|
243 |
|
|
TESTEXPR(dstid, 0xc0de);
|
244 |
|
|
TESTEXPR(srcid, 0xbabe);
|
245 |
|
|
TESTEXPR(hop, 0x13);
|
246 |
|
|
TESTEXPR(tid, 0x41);
|
247 |
|
|
TESTEXPR(address, 0x00fffffc);
|
248 |
|
|
|
249 |
|
|
/******************************************************************************/
|
250 |
|
|
TESTEND;
|
251 |
|
|
/******************************************************************************/
|
252 |
|
|
/******************************************************************************/
|
253 |
|
|
PrintS("----------------------------------------------------------------------");
|
254 |
|
|
PrintS("TG_riopacket-TC3");
|
255 |
|
|
PrintS("Description: Test input/output packets.");
|
256 |
|
|
PrintS("Requirement: XXXXX");
|
257 |
|
|
PrintS("----------------------------------------------------------------------");
|
258 |
|
|
PrintS("Step 1:");
|
259 |
|
|
PrintS("Action: ");
|
260 |
|
|
PrintS("Result: ");
|
261 |
|
|
PrintS("----------------------------------------------------------------------");
|
262 |
|
|
/******************************************************************************/
|
263 |
|
|
TESTSTART("TG_riostack-TC3-Step1");
|
264 |
|
|
/******************************************************************************/
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
/******************************************************************************/
|
268 |
|
|
TESTEND;
|
269 |
|
|
/******************************************************************************/
|
270 |
|
|
/******************************************************************************/
|
271 |
|
|
PrintS("----------------------------------------------------------------------");
|
272 |
|
|
PrintS("TG_riopacket-TC4");
|
273 |
|
|
PrintS("Description: Test message passing packets.");
|
274 |
|
|
PrintS("Requirement: XXXXX");
|
275 |
|
|
PrintS("----------------------------------------------------------------------");
|
276 |
|
|
PrintS("Step 1:");
|
277 |
|
|
PrintS("Action: Send a message with invalid payload length.");
|
278 |
|
|
PrintS("Result: No packet should be generated.");
|
279 |
|
|
PrintS("----------------------------------------------------------------------");
|
280 |
|
|
/******************************************************************************/
|
281 |
|
|
TESTSTART("TG_riostack-TC4-Step1");
|
282 |
|
|
/******************************************************************************/
|
283 |
|
|
|
284 |
|
|
RIOPACKET_setMessage(&packet, 0xdead, 0xbeef, 0xc0, 0, &payloadExpected[0]);
|
285 |
|
|
|
286 |
|
|
TESTEXPR(packet.size, 0);
|
287 |
|
|
TESTCOND(!RIOPACKET_valid(&packet));
|
288 |
|
|
|
289 |
|
|
RIOPACKET_setMessage(&packet, 0xdead, 0xbeef, 0xc0, 257, &payloadExpected[0]);
|
290 |
|
|
|
291 |
|
|
TESTEXPR(packet.size, 0);
|
292 |
|
|
TESTCOND(!RIOPACKET_valid(&packet));
|
293 |
|
|
|
294 |
|
|
/******************************************************************************/
|
295 |
|
|
TESTEND;
|
296 |
|
|
/******************************************************************************/
|
297 |
|
|
PrintS("----------------------------------------------------------------------");
|
298 |
|
|
PrintS("Step 2:");
|
299 |
|
|
PrintS("Action: Test sending all possible payload sizes on random deviceIds ");
|
300 |
|
|
PrintS(" and mailboxes.");
|
301 |
|
|
PrintS("Result: The content of the packet should be equal to what was entered.");
|
302 |
|
|
PrintS("----------------------------------------------------------------------");
|
303 |
|
|
/******************************************************************************/
|
304 |
|
|
TESTSTART("TG_riostack-TC4-Step2");
|
305 |
|
|
/******************************************************************************/
|
306 |
|
|
|
307 |
|
|
for(i = 1; i <= 256; i++)
|
308 |
|
|
{
|
309 |
|
|
dstidExpected = rand();
|
310 |
|
|
srcidExpected = rand();
|
311 |
|
|
mailboxExpected = rand();
|
312 |
|
|
|
313 |
|
|
if((i%8) == 0)
|
314 |
|
|
{
|
315 |
|
|
payloadSizeExpected = 8*(i/8);
|
316 |
|
|
}
|
317 |
|
|
else
|
318 |
|
|
{
|
319 |
|
|
payloadSizeExpected = 8*(i/8+1);
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
for(j = 0; j < i; j++)
|
323 |
|
|
{
|
324 |
|
|
payloadExpected[j] = rand();
|
325 |
|
|
}
|
326 |
|
|
|
327 |
|
|
RIOPACKET_setMessage(&packet, dstidExpected, srcidExpected, mailboxExpected,
|
328 |
|
|
i, &payloadExpected[0]);
|
329 |
|
|
TESTCOND(RIOPACKET_valid(&packet));
|
330 |
|
|
|
331 |
|
|
RIOPACKET_getMessage(&packet, &dstid, &srcid, &mailbox, &payloadSize, &(payload[0]));
|
332 |
|
|
TESTEXPR(dstid, dstidExpected);
|
333 |
|
|
TESTEXPR(srcid, srcidExpected);
|
334 |
|
|
TESTEXPR(mailbox, mailboxExpected);
|
335 |
|
|
TESTEXPR(payloadSize, payloadSizeExpected);
|
336 |
|
|
for(j = 0; j < i; j++)
|
337 |
|
|
{
|
338 |
|
|
TESTEXPR(payload[j], payloadExpected[j]);
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
/******************************************************************************/
|
343 |
|
|
TESTEND;
|
344 |
|
|
/******************************************************************************/
|
345 |
|
|
|
346 |
|
|
return 0;
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
/*************************** end of file **************************************/
|