1 | /* |
---|
2 | * SPDX-License-Identifier: BSD-2-Clause |
---|
3 | * |
---|
4 | * Copyright (C) 2018, 2019 embedded brains GmbH |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | #ifdef HAVE_CONFIG_H |
---|
29 | #include "config.h" |
---|
30 | #endif |
---|
31 | |
---|
32 | #include <rtems/record.h> |
---|
33 | #include <rtems/recordserver.h> |
---|
34 | #include <rtems.h> |
---|
35 | |
---|
36 | #include <sys/endian.h> |
---|
37 | #include <sys/socket.h> |
---|
38 | |
---|
39 | #include <string.h> |
---|
40 | #include <unistd.h> |
---|
41 | |
---|
42 | #include <netinet/in.h> |
---|
43 | |
---|
44 | #ifdef RTEMS_NETWORKING |
---|
45 | #include <rtems/rtems_bsdnet.h> |
---|
46 | #endif |
---|
47 | |
---|
48 | #include <tmacros.h> |
---|
49 | |
---|
50 | const char rtems_test_name[] = "RECORD 1"; |
---|
51 | |
---|
52 | #define ITEM_COUNT 4 |
---|
53 | |
---|
54 | #define ITEM_SIZE (ITEM_COUNT * sizeof(rtems_record_item)) |
---|
55 | |
---|
56 | typedef struct { |
---|
57 | Record_Control control; |
---|
58 | rtems_record_item items[ITEM_COUNT]; |
---|
59 | } test_context; |
---|
60 | |
---|
61 | static test_context test_instance; |
---|
62 | |
---|
63 | const Record_Configuration _Record_Configuration = { |
---|
64 | .item_count = ITEM_COUNT |
---|
65 | }; |
---|
66 | |
---|
67 | #define UE(user) RTEMS_RECORD_USER(user) |
---|
68 | |
---|
69 | #define TE(t, e) RTEMS_RECORD_TIME_EVENT(t, e) |
---|
70 | |
---|
71 | static const rtems_record_item expected_items_0[ITEM_COUNT] = { |
---|
72 | { .event = TE(2, UE(1)), .data = 3 } |
---|
73 | }; |
---|
74 | |
---|
75 | static const rtems_record_item expected_items_1[ITEM_COUNT] = { |
---|
76 | { .event = TE(2, UE(1)), .data = 3 }, |
---|
77 | { .event = TE(6, UE(5)), .data = 7 } |
---|
78 | }; |
---|
79 | |
---|
80 | static const rtems_record_item expected_items_2[ITEM_COUNT] = { |
---|
81 | { .event = TE(2, UE(1)), .data = 3 }, |
---|
82 | { .event = TE(6, UE(5)), .data = 7 }, |
---|
83 | { .event = TE(10, UE(9)), .data = 11 } |
---|
84 | }; |
---|
85 | |
---|
86 | static const rtems_record_item expected_items_3[ITEM_COUNT] = { |
---|
87 | { .event = TE(2, UE(1)), .data = 3 }, |
---|
88 | { .event = TE(6, UE(5)), .data = 7 }, |
---|
89 | { .event = TE(10, UE(9)), .data = 11 }, |
---|
90 | { .event = TE(14, UE(13)), .data = 15 } |
---|
91 | }; |
---|
92 | |
---|
93 | static const rtems_record_item expected_items_4[ITEM_COUNT] = { |
---|
94 | { .event = TE(18, UE(17)), .data = 19 }, |
---|
95 | { .event = TE(6, UE(5)), .data = 7 }, |
---|
96 | { .event = TE(10, UE(9)), .data = 11 }, |
---|
97 | { .event = TE(14, UE(13)), .data = 15 } |
---|
98 | }; |
---|
99 | |
---|
100 | static const rtems_record_item expected_items_5[ITEM_COUNT] = { |
---|
101 | { .event = TE(2, UE(1)), .data = 3 } |
---|
102 | }; |
---|
103 | |
---|
104 | static const rtems_record_item expected_items_6[ITEM_COUNT] = { |
---|
105 | { .event = TE(2, UE(1)), .data = 3 }, |
---|
106 | { .event = TE(6, UE(5)), .data = 7 } |
---|
107 | }; |
---|
108 | |
---|
109 | static const rtems_record_item expected_items_7[ITEM_COUNT] = { |
---|
110 | { .event = TE(2, UE(1)), .data = 3 }, |
---|
111 | { .event = TE(6, UE(5)), .data = 7 }, |
---|
112 | { .event = TE(10, UE(9)), .data = 11 } |
---|
113 | }; |
---|
114 | |
---|
115 | static const rtems_record_item expected_items_8[] = { |
---|
116 | { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 }, |
---|
117 | { .event = TE(0, RTEMS_RECORD_PER_CPU_TAIL), .data = 0 }, |
---|
118 | { .event = TE(0, RTEMS_RECORD_PER_CPU_HEAD), .data = 3 }, |
---|
119 | { .event = TE(2, UE(1)), .data = 3 }, |
---|
120 | { .event = TE(5, UE(4)), .data = 6 }, |
---|
121 | { .event = TE(8, UE(7)), .data = 9 } |
---|
122 | }; |
---|
123 | |
---|
124 | static const rtems_record_item expected_items_9[] = { |
---|
125 | { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 }, |
---|
126 | { .event = TE(0, RTEMS_RECORD_PER_CPU_TAIL), .data = 3 }, |
---|
127 | { .event = TE(0, RTEMS_RECORD_PER_CPU_HEAD), .data = 5 }, |
---|
128 | { .event = TE(11, UE(10)), .data = 12 }, |
---|
129 | { .event = TE(14, UE(13)), .data = 15 } |
---|
130 | }; |
---|
131 | |
---|
132 | static const rtems_record_item expected_items_10[] = { |
---|
133 | { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 }, |
---|
134 | { .event = TE(0, RTEMS_RECORD_PER_CPU_TAIL), .data = 5 }, |
---|
135 | { .event = TE(0, RTEMS_RECORD_PER_CPU_HEAD), .data = 8 }, |
---|
136 | { .event = TE(17, UE(16)), .data = 18 }, |
---|
137 | { .event = TE(20, UE(19)), .data = 21 }, |
---|
138 | { .event = TE(23, UE(22)), .data = 24 } |
---|
139 | }; |
---|
140 | |
---|
141 | static const rtems_record_item expected_items_11[] = { |
---|
142 | { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 }, |
---|
143 | { .event = TE(0, RTEMS_RECORD_PER_CPU_TAIL), .data = 8 }, |
---|
144 | { .event = TE(0, RTEMS_RECORD_PER_CPU_HEAD), .data = 9 }, |
---|
145 | { .event = TE(26, UE(25)), .data = 27 } |
---|
146 | }; |
---|
147 | |
---|
148 | static const rtems_record_item expected_items_12[] = { |
---|
149 | { .event = TE(0, RTEMS_RECORD_PROCESSOR), .data = 0 }, |
---|
150 | { .event = TE(0, RTEMS_RECORD_PER_CPU_TAIL), .data = 9 }, |
---|
151 | { .event = TE(0, RTEMS_RECORD_PER_CPU_HEAD), .data = 15 }, |
---|
152 | { .event = TE(38, UE(37)), .data = 39 }, |
---|
153 | { .event = TE(41, UE(40)), .data = 42 }, |
---|
154 | { .event = TE(44, UE(43)), .data = 45 } |
---|
155 | }; |
---|
156 | |
---|
157 | #ifdef RTEMS_NETWORKING |
---|
158 | static const rtems_record_item expected_items_13[] = { |
---|
159 | { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0x9010001 }, |
---|
160 | { |
---|
161 | .event = TE(0, RTEMS_RECORD_THREAD_NAME), |
---|
162 | .data = rtems_build_name('E', 'L', 'D', 'I') |
---|
163 | }, |
---|
164 | { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0xa010001 }, |
---|
165 | { |
---|
166 | .event = TE(0, RTEMS_RECORD_THREAD_NAME), |
---|
167 | .data = rtems_build_name(' ', '1', 'I', 'U') |
---|
168 | }, |
---|
169 | { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0xa010002 }, |
---|
170 | { |
---|
171 | .event = TE(0, RTEMS_RECORD_THREAD_NAME), |
---|
172 | .data = rtems_build_name('k', 'w', 't', 'n') |
---|
173 | }, |
---|
174 | { .event = TE(0, RTEMS_RECORD_THREAD_ID), .data = 0xa010003 }, |
---|
175 | { |
---|
176 | .event = TE(0, RTEMS_RECORD_THREAD_NAME), |
---|
177 | .data = rtems_build_name('D', 'R', 'C', 'R') |
---|
178 | } |
---|
179 | }; |
---|
180 | #endif |
---|
181 | |
---|
182 | static void init_context(test_context *ctx) |
---|
183 | { |
---|
184 | memset(ctx, 0, sizeof(*ctx)); |
---|
185 | ctx->control.mask = ITEM_COUNT - 1; |
---|
186 | } |
---|
187 | |
---|
188 | static void test_capacity(const Record_Control *control) |
---|
189 | { |
---|
190 | unsigned int capacity; |
---|
191 | |
---|
192 | capacity = _Record_Capacity(control, 0, 0); |
---|
193 | rtems_test_assert(capacity == 3); |
---|
194 | |
---|
195 | capacity = _Record_Capacity(control, 0, 1); |
---|
196 | rtems_test_assert(capacity == 2); |
---|
197 | |
---|
198 | capacity = _Record_Capacity(control, 0, 2); |
---|
199 | rtems_test_assert(capacity == 1); |
---|
200 | |
---|
201 | capacity = _Record_Capacity(control, 0, 3); |
---|
202 | rtems_test_assert(capacity == 0); |
---|
203 | |
---|
204 | capacity = _Record_Capacity(control, 3, 3); |
---|
205 | rtems_test_assert(capacity == 3); |
---|
206 | |
---|
207 | capacity = _Record_Capacity(control, 3, 0); |
---|
208 | rtems_test_assert(capacity == 2); |
---|
209 | |
---|
210 | capacity = _Record_Capacity(control, 3, 1); |
---|
211 | rtems_test_assert(capacity == 1); |
---|
212 | |
---|
213 | capacity = _Record_Capacity(control, 3, 2); |
---|
214 | rtems_test_assert(capacity == 0); |
---|
215 | } |
---|
216 | |
---|
217 | static void test_index(const Record_Control *control) |
---|
218 | { |
---|
219 | unsigned int index; |
---|
220 | |
---|
221 | index = _Record_Index(control, 0); |
---|
222 | rtems_test_assert(index == 0); |
---|
223 | |
---|
224 | index = _Record_Index(control, 1); |
---|
225 | rtems_test_assert(index == 1); |
---|
226 | |
---|
227 | index = _Record_Index(control, 2); |
---|
228 | rtems_test_assert(index == 2); |
---|
229 | |
---|
230 | index = _Record_Index(control, 3); |
---|
231 | rtems_test_assert(index == 3); |
---|
232 | |
---|
233 | index = _Record_Index(control, 4); |
---|
234 | rtems_test_assert(index == 0); |
---|
235 | } |
---|
236 | |
---|
237 | static void test_add_2_items(test_context *ctx, Record_Control *control) |
---|
238 | { |
---|
239 | rtems_record_context rc; |
---|
240 | |
---|
241 | init_context(ctx); |
---|
242 | |
---|
243 | rtems_record_prepare(&rc); |
---|
244 | rtems_test_assert(rc.control == control); |
---|
245 | rtems_test_assert(rc.head == 0); |
---|
246 | rtems_test_assert(_Record_Head(control) == 0); |
---|
247 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
248 | |
---|
249 | rc.now = RTEMS_RECORD_TIME_EVENT(2, 0); |
---|
250 | rtems_record_add(&rc, UE(1), 3); |
---|
251 | rtems_test_assert(rc.head == 1); |
---|
252 | rtems_test_assert(memcmp(control->Items, expected_items_0, ITEM_SIZE) == 0); |
---|
253 | rtems_test_assert(_Record_Head(control) == 0); |
---|
254 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
255 | |
---|
256 | rc.now = RTEMS_RECORD_TIME_EVENT(6, 0); |
---|
257 | rtems_record_add(&rc, UE(5), 7); |
---|
258 | rtems_record_commit(&rc); |
---|
259 | rtems_test_assert(rc.head == 2); |
---|
260 | rtems_test_assert(memcmp(control->Items, expected_items_1, ITEM_SIZE) == 0); |
---|
261 | rtems_test_assert(_Record_Head(control) == 2); |
---|
262 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
263 | } |
---|
264 | |
---|
265 | static void test_add_3_items(test_context *ctx, Record_Control *control) |
---|
266 | { |
---|
267 | rtems_record_context rc; |
---|
268 | rtems_interrupt_level level; |
---|
269 | |
---|
270 | init_context(ctx); |
---|
271 | |
---|
272 | rtems_interrupt_local_disable(level); |
---|
273 | rtems_record_prepare_critical(&rc, _Per_CPU_Get()); |
---|
274 | rtems_test_assert(rc.control == control); |
---|
275 | rtems_test_assert(rc.head == 0); |
---|
276 | rtems_test_assert(_Record_Head(control) == 0); |
---|
277 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
278 | |
---|
279 | rc.now = RTEMS_RECORD_TIME_EVENT(2, 0); |
---|
280 | rtems_record_add(&rc, UE(1), 3); |
---|
281 | rtems_test_assert(rc.head == 1); |
---|
282 | rtems_test_assert(memcmp(control->Items, expected_items_5, ITEM_SIZE) == 0); |
---|
283 | rtems_test_assert(_Record_Head(control) == 0); |
---|
284 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
285 | |
---|
286 | rc.now = RTEMS_RECORD_TIME_EVENT(6, 0); |
---|
287 | rtems_record_add(&rc, UE(5), 7); |
---|
288 | rtems_test_assert(rc.head == 2); |
---|
289 | rtems_test_assert(memcmp(control->Items, expected_items_6, ITEM_SIZE) == 0); |
---|
290 | rtems_test_assert(_Record_Head(control) == 0); |
---|
291 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
292 | |
---|
293 | rc.now = RTEMS_RECORD_TIME_EVENT(10, 0); |
---|
294 | rtems_record_add(&rc, UE(9), 11); |
---|
295 | rtems_record_commit_critical(&rc); |
---|
296 | rtems_interrupt_local_enable(level); |
---|
297 | rtems_test_assert(rc.head == 3); |
---|
298 | rtems_test_assert(memcmp(control->Items, expected_items_7, ITEM_SIZE) == 0); |
---|
299 | rtems_test_assert(_Record_Head(control) == 3); |
---|
300 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
301 | } |
---|
302 | |
---|
303 | static void set_time(rtems_record_item *item, uint32_t time) |
---|
304 | { |
---|
305 | uint32_t event; |
---|
306 | |
---|
307 | event = item->event; |
---|
308 | event &= 0x3ff; |
---|
309 | event |= time << 10; |
---|
310 | item->event = event; |
---|
311 | } |
---|
312 | |
---|
313 | static void test_produce(test_context *ctx, Record_Control *control) |
---|
314 | { |
---|
315 | init_context(ctx); |
---|
316 | |
---|
317 | rtems_record_produce(UE(1), 3); |
---|
318 | set_time(&control->Items[0], 2); |
---|
319 | rtems_test_assert(memcmp(control->Items, expected_items_0, ITEM_SIZE) == 0); |
---|
320 | rtems_test_assert(_Record_Head(control) == 1); |
---|
321 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
322 | |
---|
323 | rtems_record_produce(UE(5), 7); |
---|
324 | set_time(&control->Items[1], 6); |
---|
325 | rtems_test_assert(memcmp(control->Items, expected_items_1, ITEM_SIZE) == 0); |
---|
326 | rtems_test_assert(_Record_Head(control) == 2); |
---|
327 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
328 | |
---|
329 | rtems_record_produce(UE(9), 11); |
---|
330 | set_time(&control->Items[2], 10); |
---|
331 | rtems_test_assert(memcmp(control->Items, expected_items_2, ITEM_SIZE) == 0); |
---|
332 | rtems_test_assert(_Record_Head(control) == 3); |
---|
333 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
334 | |
---|
335 | rtems_record_produce(UE(13), 15); |
---|
336 | set_time(&control->Items[3], 14); |
---|
337 | rtems_test_assert(memcmp(control->Items, expected_items_3, ITEM_SIZE) == 0); |
---|
338 | rtems_test_assert(_Record_Head(control) == 4); |
---|
339 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
340 | |
---|
341 | rtems_record_produce(UE(17), 19); |
---|
342 | set_time(&control->Items[0], 18); |
---|
343 | rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0); |
---|
344 | rtems_test_assert(_Record_Head(control) == 5); |
---|
345 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
346 | } |
---|
347 | |
---|
348 | static void test_produce_2(test_context *ctx, Record_Control *control) |
---|
349 | { |
---|
350 | init_context(ctx); |
---|
351 | |
---|
352 | rtems_record_produce_2(UE(1), 3, UE(5), 7); |
---|
353 | set_time(&control->Items[0], 2); |
---|
354 | set_time(&control->Items[1], 6); |
---|
355 | rtems_test_assert(memcmp(control->Items, expected_items_1, ITEM_SIZE) == 0); |
---|
356 | rtems_test_assert(_Record_Head(control) == 2); |
---|
357 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
358 | |
---|
359 | rtems_record_produce(UE(9), 11); |
---|
360 | set_time(&control->Items[2], 10); |
---|
361 | rtems_test_assert(memcmp(control->Items, expected_items_2, ITEM_SIZE) == 0); |
---|
362 | rtems_test_assert(_Record_Head(control) == 3); |
---|
363 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
364 | |
---|
365 | rtems_record_produce_2(UE(13), 15, UE(17), 19); |
---|
366 | set_time(&control->Items[3], 14); |
---|
367 | set_time(&control->Items[0], 18); |
---|
368 | rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0); |
---|
369 | rtems_test_assert(_Record_Head(control) == 5); |
---|
370 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
371 | } |
---|
372 | |
---|
373 | static void test_produce_n(test_context *ctx, Record_Control *control) |
---|
374 | { |
---|
375 | rtems_record_item items[5]; |
---|
376 | |
---|
377 | init_context(ctx); |
---|
378 | |
---|
379 | items[0].event = UE(1); |
---|
380 | items[0].data = 3; |
---|
381 | items[1].event = UE(5); |
---|
382 | items[1].data = 7; |
---|
383 | items[2].event = UE(9); |
---|
384 | items[2].data = 11; |
---|
385 | items[3].event = UE(13); |
---|
386 | items[3].data = 15; |
---|
387 | items[4].event = UE(17); |
---|
388 | items[4].data = 19; |
---|
389 | rtems_record_produce_n(items, RTEMS_ARRAY_SIZE(items)); |
---|
390 | set_time(&control->Items[1], 6); |
---|
391 | set_time(&control->Items[2], 10); |
---|
392 | set_time(&control->Items[3], 14); |
---|
393 | set_time(&control->Items[0], 18); |
---|
394 | rtems_test_assert(memcmp(control->Items, expected_items_4, ITEM_SIZE) == 0); |
---|
395 | rtems_test_assert(_Record_Head(control) == 5); |
---|
396 | rtems_test_assert(_Record_Tail(control) == 0); |
---|
397 | } |
---|
398 | |
---|
399 | typedef struct { |
---|
400 | size_t todo; |
---|
401 | const rtems_record_item *items; |
---|
402 | } visitor_context; |
---|
403 | |
---|
404 | static void visitor(const rtems_record_item *items, size_t count, void *arg) |
---|
405 | { |
---|
406 | visitor_context *vctx; |
---|
407 | |
---|
408 | vctx = arg; |
---|
409 | rtems_test_assert(vctx->todo >= count); |
---|
410 | |
---|
411 | while (count > 0) { |
---|
412 | rtems_test_assert(memcmp(items, vctx->items, sizeof(*items)) == 0); |
---|
413 | ++items; |
---|
414 | ++vctx->items; |
---|
415 | --count; |
---|
416 | --vctx->todo; |
---|
417 | } |
---|
418 | } |
---|
419 | |
---|
420 | static void test_drain(test_context *ctx, Record_Control *control) |
---|
421 | { |
---|
422 | visitor_context vctx; |
---|
423 | |
---|
424 | init_context(ctx); |
---|
425 | |
---|
426 | vctx.todo = 0; |
---|
427 | vctx.items = NULL; |
---|
428 | rtems_record_drain(visitor, &vctx); |
---|
429 | rtems_test_assert(vctx.todo == 0); |
---|
430 | |
---|
431 | rtems_record_produce(UE(1), 3); |
---|
432 | set_time(&control->Items[0], 2); |
---|
433 | rtems_record_produce(UE(4), 6); |
---|
434 | set_time(&control->Items[1], 5); |
---|
435 | rtems_record_produce(UE(7), 9); |
---|
436 | set_time(&control->Items[2], 8); |
---|
437 | |
---|
438 | vctx.todo = RTEMS_ARRAY_SIZE(expected_items_8); |
---|
439 | vctx.items = expected_items_8; |
---|
440 | rtems_record_drain(visitor, &vctx); |
---|
441 | rtems_test_assert(vctx.todo == 0); |
---|
442 | |
---|
443 | vctx.todo = 0; |
---|
444 | vctx.items = NULL; |
---|
445 | rtems_record_drain(visitor, &vctx); |
---|
446 | rtems_test_assert(vctx.todo == 0); |
---|
447 | |
---|
448 | rtems_record_produce(UE(10), 12); |
---|
449 | set_time(&control->Items[3], 11); |
---|
450 | rtems_record_produce(UE(13), 15); |
---|
451 | set_time(&control->Items[0], 14); |
---|
452 | |
---|
453 | vctx.todo = RTEMS_ARRAY_SIZE(expected_items_9); |
---|
454 | vctx.items = expected_items_9; |
---|
455 | rtems_record_drain(visitor, &vctx); |
---|
456 | rtems_test_assert(vctx.todo == 0); |
---|
457 | |
---|
458 | vctx.todo = 0; |
---|
459 | vctx.items = NULL; |
---|
460 | rtems_record_drain(visitor, &vctx); |
---|
461 | rtems_test_assert(vctx.todo == 0); |
---|
462 | |
---|
463 | rtems_record_produce(UE(16), 18); |
---|
464 | set_time(&control->Items[1], 17); |
---|
465 | rtems_record_produce(UE(19), 21); |
---|
466 | set_time(&control->Items[2], 20); |
---|
467 | rtems_record_produce(UE(22), 24); |
---|
468 | set_time(&control->Items[3], 23); |
---|
469 | |
---|
470 | vctx.todo = RTEMS_ARRAY_SIZE(expected_items_10); |
---|
471 | vctx.items = expected_items_10; |
---|
472 | rtems_record_drain(visitor, &vctx); |
---|
473 | rtems_test_assert(vctx.todo == 0); |
---|
474 | |
---|
475 | vctx.todo = 0; |
---|
476 | vctx.items = NULL; |
---|
477 | rtems_record_drain(visitor, &vctx); |
---|
478 | rtems_test_assert(vctx.todo == 0); |
---|
479 | |
---|
480 | rtems_record_produce(UE(25), 27); |
---|
481 | set_time(&control->Items[0], 26); |
---|
482 | |
---|
483 | vctx.todo = RTEMS_ARRAY_SIZE(expected_items_11); |
---|
484 | vctx.items = expected_items_11; |
---|
485 | rtems_record_drain(visitor, &vctx); |
---|
486 | rtems_test_assert(vctx.todo == 0); |
---|
487 | |
---|
488 | vctx.todo = 0; |
---|
489 | vctx.items = NULL; |
---|
490 | rtems_record_drain(visitor, &vctx); |
---|
491 | rtems_test_assert(vctx.todo == 0); |
---|
492 | |
---|
493 | rtems_record_produce(UE(28), 30); |
---|
494 | set_time(&control->Items[1], 29); |
---|
495 | rtems_record_produce(UE(31), 33); |
---|
496 | set_time(&control->Items[2], 32); |
---|
497 | rtems_record_produce(UE(34), 36); |
---|
498 | set_time(&control->Items[3], 35); |
---|
499 | rtems_record_produce(UE(37), 39); |
---|
500 | set_time(&control->Items[0], 38); |
---|
501 | rtems_record_produce(UE(40), 42); |
---|
502 | set_time(&control->Items[1], 41); |
---|
503 | rtems_record_produce(UE(43), 45); |
---|
504 | set_time(&control->Items[2], 44); |
---|
505 | |
---|
506 | vctx.todo = RTEMS_ARRAY_SIZE(expected_items_12); |
---|
507 | vctx.items = expected_items_12; |
---|
508 | rtems_record_drain(visitor, &vctx); |
---|
509 | rtems_test_assert(vctx.todo == 0); |
---|
510 | |
---|
511 | vctx.todo = 0; |
---|
512 | vctx.items = NULL; |
---|
513 | rtems_record_drain(visitor, &vctx); |
---|
514 | rtems_test_assert(vctx.todo == 0); |
---|
515 | } |
---|
516 | |
---|
517 | #ifdef RTEMS_NETWORKING |
---|
518 | #define PORT 1234 |
---|
519 | |
---|
520 | typedef enum { |
---|
521 | HEADER_ARCH, |
---|
522 | HEADER_MULTILIB, |
---|
523 | HEADER_BSP, |
---|
524 | HEADER_VERSION_CONTROL_KEY, |
---|
525 | HEADER_TOOLS, |
---|
526 | HEADER_LAST |
---|
527 | } header_state; |
---|
528 | |
---|
529 | static uint32_t get_format(void) |
---|
530 | { |
---|
531 | uint32_t format; |
---|
532 | |
---|
533 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
534 | #if __INTPTR_WIDTH__ == 32 |
---|
535 | format = RTEMS_RECORD_FORMAT_LE_32; |
---|
536 | #elif __INTPTR_WIDTH__ == 64 |
---|
537 | format = RTEMS_RECORD_FORMAT_LE_64; |
---|
538 | #else |
---|
539 | #error "unexpected __INTPTR_WIDTH__" |
---|
540 | #endif |
---|
541 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
542 | #if __INTPTR_WIDTH__ == 32 |
---|
543 | format = RTEMS_RECORD_FORMAT_BE_32; |
---|
544 | #elif __INTPTR_WIDTH__ == 64 |
---|
545 | format = RTEMS_RECORD_FORMAT_BE_64; |
---|
546 | #else |
---|
547 | #error "unexpected __INTPTR_WIDTH__" |
---|
548 | #endif |
---|
549 | #else |
---|
550 | #error "unexpected BYTE_ORDER" |
---|
551 | #endif |
---|
552 | |
---|
553 | return format; |
---|
554 | } |
---|
555 | |
---|
556 | static rtems_record_event hs_to_ev(header_state hs) |
---|
557 | { |
---|
558 | switch (hs) { |
---|
559 | case HEADER_ARCH: |
---|
560 | return RTEMS_RECORD_ARCH; |
---|
561 | case HEADER_MULTILIB: |
---|
562 | return RTEMS_RECORD_MULTILIB; |
---|
563 | case HEADER_BSP: |
---|
564 | return RTEMS_RECORD_BSP; |
---|
565 | case HEADER_VERSION_CONTROL_KEY: |
---|
566 | return RTEMS_RECORD_VERSION_CONTROL_KEY; |
---|
567 | case HEADER_TOOLS: |
---|
568 | return RTEMS_RECORD_TOOLS; |
---|
569 | default: |
---|
570 | rtems_test_assert(0); |
---|
571 | return RTEMS_RECORD_EMPTY; |
---|
572 | } |
---|
573 | } |
---|
574 | |
---|
575 | static int connect_client(void) |
---|
576 | { |
---|
577 | struct sockaddr_in addr; |
---|
578 | int fd; |
---|
579 | int rv; |
---|
580 | ssize_t n; |
---|
581 | uint32_t v; |
---|
582 | rtems_record_item item; |
---|
583 | rtems_record_item items[8]; |
---|
584 | header_state hs; |
---|
585 | |
---|
586 | fd = socket(PF_INET, SOCK_STREAM, 0); |
---|
587 | rtems_test_assert(fd >= 0); |
---|
588 | |
---|
589 | memset(&addr, 0, sizeof(addr)); |
---|
590 | addr.sin_family = AF_INET; |
---|
591 | addr.sin_port = htons(PORT); |
---|
592 | addr.sin_addr.s_addr = htonl(INADDR_ANY); |
---|
593 | rv = connect(fd, (struct sockaddr *) &addr, sizeof(addr)); |
---|
594 | rtems_test_assert(rv == 0); |
---|
595 | |
---|
596 | n = read(fd, &v, sizeof(v)); |
---|
597 | rtems_test_assert(n == 4); |
---|
598 | rtems_test_assert(v == get_format()); |
---|
599 | |
---|
600 | n = read(fd, &v, sizeof(v)); |
---|
601 | rtems_test_assert(n == 4); |
---|
602 | rtems_test_assert(v == RTEMS_RECORD_MAGIC); |
---|
603 | |
---|
604 | n = read(fd, &item, sizeof(item)); |
---|
605 | rtems_test_assert(n == (ssize_t) sizeof(item)); |
---|
606 | rtems_test_assert(item.event == TE(0, RTEMS_RECORD_VERSION)); |
---|
607 | rtems_test_assert(item.data == RTEMS_RECORD_THE_VERSION); |
---|
608 | |
---|
609 | n = read(fd, &item, sizeof(item)); |
---|
610 | rtems_test_assert(n == (ssize_t) sizeof(item)); |
---|
611 | rtems_test_assert(item.event == TE(0, RTEMS_RECORD_PROCESSOR_MAXIMUM)); |
---|
612 | rtems_test_assert(item.data == 0); |
---|
613 | |
---|
614 | n = read(fd, &item, sizeof(item)); |
---|
615 | rtems_test_assert(n == (ssize_t) sizeof(item)); |
---|
616 | rtems_test_assert(item.event == TE(0, RTEMS_RECORD_PER_CPU_COUNT)); |
---|
617 | rtems_test_assert(item.data == ITEM_COUNT); |
---|
618 | |
---|
619 | n = read(fd, &item, sizeof(item)); |
---|
620 | rtems_test_assert(n == (ssize_t) sizeof(item)); |
---|
621 | rtems_test_assert(item.event == TE(0, RTEMS_RECORD_FREQUENCY)); |
---|
622 | rtems_test_assert(item.data == rtems_counter_frequency()); |
---|
623 | |
---|
624 | hs = HEADER_ARCH; |
---|
625 | while (hs != HEADER_LAST) { |
---|
626 | n = read(fd, items, sizeof(items[0])); |
---|
627 | rtems_test_assert(n == (ssize_t) sizeof(items[0])); |
---|
628 | |
---|
629 | if (items[0].event != hs_to_ev(hs)) { |
---|
630 | ++hs; |
---|
631 | } |
---|
632 | |
---|
633 | rtems_test_assert(hs == HEADER_LAST || items[0].event == hs_to_ev(hs)); |
---|
634 | } |
---|
635 | |
---|
636 | n = read(fd, &items[1], sizeof(expected_items_13) - sizeof(items[0])); |
---|
637 | rtems_test_assert( |
---|
638 | n == (ssize_t) (sizeof(expected_items_13) - sizeof(items[0])) |
---|
639 | ); |
---|
640 | rtems_test_assert( |
---|
641 | memcmp(items, expected_items_13, sizeof(expected_items_13)) == 0 |
---|
642 | ); |
---|
643 | |
---|
644 | return fd; |
---|
645 | } |
---|
646 | |
---|
647 | static void produce_and_read(int fd, Record_Control *control) |
---|
648 | { |
---|
649 | rtems_record_item items[6]; |
---|
650 | ssize_t n; |
---|
651 | |
---|
652 | rtems_record_produce(UE(1), 3); |
---|
653 | set_time(&control->Items[0], 2); |
---|
654 | rtems_record_produce(UE(4), 6); |
---|
655 | set_time(&control->Items[1], 5); |
---|
656 | rtems_record_produce(UE(7), 9); |
---|
657 | set_time(&control->Items[2], 8); |
---|
658 | |
---|
659 | n = read(fd, items, sizeof(expected_items_8)); |
---|
660 | rtems_test_assert(n == (ssize_t) sizeof(expected_items_8)); |
---|
661 | rtems_test_assert( |
---|
662 | memcmp(items, expected_items_8, sizeof(expected_items_8)) == 0 |
---|
663 | ); |
---|
664 | |
---|
665 | rtems_record_produce(UE(10), 12); |
---|
666 | set_time(&control->Items[3], 11); |
---|
667 | rtems_record_produce(UE(13), 15); |
---|
668 | set_time(&control->Items[0], 14); |
---|
669 | |
---|
670 | n = read(fd, items, sizeof(expected_items_9)); |
---|
671 | rtems_test_assert(n == (ssize_t) sizeof(expected_items_9)); |
---|
672 | rtems_test_assert( |
---|
673 | memcmp(items, expected_items_9, sizeof(expected_items_9)) == 0 |
---|
674 | ); |
---|
675 | |
---|
676 | rtems_record_produce(UE(16), 18); |
---|
677 | set_time(&control->Items[1], 17); |
---|
678 | rtems_record_produce(UE(19), 21); |
---|
679 | set_time(&control->Items[2], 20); |
---|
680 | rtems_record_produce(UE(22), 24); |
---|
681 | set_time(&control->Items[3], 23); |
---|
682 | |
---|
683 | n = read(fd, items, sizeof(expected_items_10)); |
---|
684 | rtems_test_assert(n == (ssize_t) sizeof(expected_items_10)); |
---|
685 | rtems_test_assert( |
---|
686 | memcmp(items, expected_items_10, sizeof(expected_items_10)) == 0 |
---|
687 | ); |
---|
688 | |
---|
689 | rtems_record_produce(UE(25), 27); |
---|
690 | set_time(&control->Items[0], 26); |
---|
691 | |
---|
692 | n = read(fd, items, sizeof(expected_items_11)); |
---|
693 | rtems_test_assert(n == (ssize_t) sizeof(expected_items_11)); |
---|
694 | rtems_test_assert( |
---|
695 | memcmp(items, expected_items_11, sizeof(expected_items_11)) == 0 |
---|
696 | ); |
---|
697 | |
---|
698 | rtems_record_produce(UE(28), 30); |
---|
699 | set_time(&control->Items[1], 29); |
---|
700 | rtems_record_produce(UE(31), 33); |
---|
701 | set_time(&control->Items[2], 32); |
---|
702 | rtems_record_produce(UE(34), 36); |
---|
703 | set_time(&control->Items[3], 35); |
---|
704 | rtems_record_produce(UE(37), 39); |
---|
705 | set_time(&control->Items[0], 38); |
---|
706 | rtems_record_produce(UE(40), 42); |
---|
707 | set_time(&control->Items[1], 41); |
---|
708 | rtems_record_produce(UE(43), 45); |
---|
709 | set_time(&control->Items[2], 44); |
---|
710 | |
---|
711 | n = read(fd, items, sizeof(expected_items_12)); |
---|
712 | rtems_test_assert(n == (ssize_t) sizeof(expected_items_12)); |
---|
713 | rtems_test_assert( |
---|
714 | memcmp(items, expected_items_12, sizeof(expected_items_12)) == 0 |
---|
715 | ); |
---|
716 | } |
---|
717 | |
---|
718 | static void test_server(test_context *ctx, Record_Control *control) |
---|
719 | { |
---|
720 | rtems_status_code sc; |
---|
721 | int rv; |
---|
722 | int fd; |
---|
723 | |
---|
724 | init_context(ctx); |
---|
725 | |
---|
726 | rv = rtems_bsdnet_initialize_network(); |
---|
727 | rtems_test_assert(rv == 0); |
---|
728 | |
---|
729 | sc = rtems_record_start_server(1, PORT, 1); |
---|
730 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
731 | |
---|
732 | fd = connect_client(); |
---|
733 | produce_and_read(fd, control); |
---|
734 | |
---|
735 | rv = close(fd); |
---|
736 | rtems_test_assert(rv == 0); |
---|
737 | } |
---|
738 | #endif |
---|
739 | |
---|
740 | static void Init(rtems_task_argument arg) |
---|
741 | { |
---|
742 | test_context *ctx; |
---|
743 | Per_CPU_Control *cpu_self; |
---|
744 | |
---|
745 | TEST_BEGIN(); |
---|
746 | |
---|
747 | ctx = &test_instance; |
---|
748 | |
---|
749 | cpu_self = _Per_CPU_Get_snapshot(); |
---|
750 | cpu_self->record = &ctx->control; |
---|
751 | |
---|
752 | init_context(ctx); |
---|
753 | test_capacity(&ctx->control); |
---|
754 | test_index(&ctx->control); |
---|
755 | test_add_2_items(ctx, &ctx->control); |
---|
756 | test_add_3_items(ctx, &ctx->control); |
---|
757 | test_produce(ctx, &ctx->control); |
---|
758 | test_produce_2(ctx, &ctx->control); |
---|
759 | test_produce_n(ctx, &ctx->control); |
---|
760 | test_drain(ctx, &ctx->control); |
---|
761 | #ifdef RTEMS_NETWORKING |
---|
762 | test_server(ctx, &ctx->control); |
---|
763 | #endif |
---|
764 | |
---|
765 | TEST_END(); |
---|
766 | rtems_test_exit(0); |
---|
767 | } |
---|
768 | |
---|
769 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
770 | |
---|
771 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
772 | |
---|
773 | #ifdef RTEMS_NETWORKING |
---|
774 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 7 |
---|
775 | |
---|
776 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
777 | |
---|
778 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
779 | |
---|
780 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
781 | #else |
---|
782 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
783 | #endif |
---|
784 | |
---|
785 | #define CONFIGURE_INIT_TASK_PRIORITY 2 |
---|
786 | |
---|
787 | #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES |
---|
788 | |
---|
789 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
790 | |
---|
791 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
792 | |
---|
793 | #define CONFIGURE_INIT |
---|
794 | |
---|
795 | #include <rtems/confdefs.h> |
---|