1 | # SPDX-License-Identifier: BSD-2-Clause |
---|
2 | """ Unit tests for the rtemsspec.validation module. """ |
---|
3 | |
---|
4 | # Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
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 | import os |
---|
28 | import pytest |
---|
29 | |
---|
30 | from rtemsspec.validation import generate |
---|
31 | from rtemsspec.items import EmptyItemCache, ItemCache |
---|
32 | from rtemsspec.tests.util import create_item_cache_config_and_copy_spec |
---|
33 | |
---|
34 | |
---|
35 | def test_validation(tmpdir): |
---|
36 | validation_config = {} |
---|
37 | base_directory = os.path.join(tmpdir, "base") |
---|
38 | validation_config["base-directory"] = base_directory |
---|
39 | |
---|
40 | generate(validation_config, EmptyItemCache()) |
---|
41 | |
---|
42 | item_cache_config = create_item_cache_config_and_copy_spec( |
---|
43 | tmpdir, "spec-validation", with_spec_types=True) |
---|
44 | generate(validation_config, ItemCache(item_cache_config)) |
---|
45 | |
---|
46 | with open(os.path.join(base_directory, "ts.c"), "r") as src: |
---|
47 | content = """/* SPDX-License-Identifier: BSD-2-Clause */ |
---|
48 | |
---|
49 | /** |
---|
50 | * @file |
---|
51 | * |
---|
52 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
53 | */ |
---|
54 | |
---|
55 | /* |
---|
56 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
57 | * |
---|
58 | * Redistribution and use in source and binary forms, with or without |
---|
59 | * modification, are permitted provided that the following conditions |
---|
60 | * are met: |
---|
61 | * 1. Redistributions of source code must retain the above copyright |
---|
62 | * notice, this list of conditions and the following disclaimer. |
---|
63 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
64 | * notice, this list of conditions and the following disclaimer in the |
---|
65 | * documentation and/or other materials provided with the distribution. |
---|
66 | * |
---|
67 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
68 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
69 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
70 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
71 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
72 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
73 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
74 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
75 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
76 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
77 | * POSSIBILITY OF SUCH DAMAGE. |
---|
78 | */ |
---|
79 | |
---|
80 | #ifdef HAVE_CONFIG_H |
---|
81 | #include "config.h" |
---|
82 | #endif |
---|
83 | |
---|
84 | #include <blue.h> |
---|
85 | |
---|
86 | #include "green.h" |
---|
87 | |
---|
88 | #include <rtems/test.h> |
---|
89 | |
---|
90 | /** |
---|
91 | * @defgroup RTEMSTestSuiteBlueGreen Blue Green |
---|
92 | * |
---|
93 | * @ingroup RTEMSTestSuites |
---|
94 | * |
---|
95 | * @brief Test Suite |
---|
96 | * |
---|
97 | * The Blue Green description. |
---|
98 | * |
---|
99 | * @{ |
---|
100 | */ |
---|
101 | |
---|
102 | /* Blue green code */ |
---|
103 | |
---|
104 | /** @} */ |
---|
105 | """ |
---|
106 | assert content == src.read() |
---|
107 | |
---|
108 | with open(os.path.join(base_directory, "tc12.c"), "r") as src: |
---|
109 | content = """/* SPDX-License-Identifier: BSD-2-Clause */ |
---|
110 | |
---|
111 | /** |
---|
112 | * @file |
---|
113 | * |
---|
114 | * @ingroup RTEMSTestCaseClassicTaskIdentification |
---|
115 | * @ingroup RTEMSTestCaseTestCase |
---|
116 | * @ingroup RTEMSTestCaseTestCase2 |
---|
117 | */ |
---|
118 | |
---|
119 | /* |
---|
120 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
121 | * |
---|
122 | * Redistribution and use in source and binary forms, with or without |
---|
123 | * modification, are permitted provided that the following conditions |
---|
124 | * are met: |
---|
125 | * 1. Redistributions of source code must retain the above copyright |
---|
126 | * notice, this list of conditions and the following disclaimer. |
---|
127 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
128 | * notice, this list of conditions and the following disclaimer in the |
---|
129 | * documentation and/or other materials provided with the distribution. |
---|
130 | * |
---|
131 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
132 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
133 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
134 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
135 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
136 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
137 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
138 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
139 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
140 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
141 | * POSSIBILITY OF SUCH DAMAGE. |
---|
142 | */ |
---|
143 | |
---|
144 | #ifdef HAVE_CONFIG_H |
---|
145 | #include "config.h" |
---|
146 | #endif |
---|
147 | |
---|
148 | #include <a.h> |
---|
149 | #include <b.h> |
---|
150 | #include <rtems.h> |
---|
151 | |
---|
152 | #include "x.h" |
---|
153 | #include "y.h" |
---|
154 | |
---|
155 | #include <rtems/test.h> |
---|
156 | |
---|
157 | /** |
---|
158 | * @defgroup RTEMSTestCaseClassicTaskIdentification Classic Task Identification |
---|
159 | * |
---|
160 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
161 | * |
---|
162 | * @brief Test Case |
---|
163 | * |
---|
164 | * @{ |
---|
165 | */ |
---|
166 | |
---|
167 | typedef enum { |
---|
168 | ClassicTaskIdentification_Pre_Name_Invalid, |
---|
169 | ClassicTaskIdentification_Pre_Name_Self, |
---|
170 | ClassicTaskIdentification_Pre_Name_Valid, |
---|
171 | ClassicTaskIdentification_Pre_Name_NA |
---|
172 | } ClassicTaskIdentification_Pre_Name; |
---|
173 | |
---|
174 | typedef enum { |
---|
175 | ClassicTaskIdentification_Pre_Node_Local, |
---|
176 | ClassicTaskIdentification_Pre_Node_Remote, |
---|
177 | ClassicTaskIdentification_Pre_Node_Invalid, |
---|
178 | ClassicTaskIdentification_Pre_Node_SearchAll, |
---|
179 | ClassicTaskIdentification_Pre_Node_SearchOther, |
---|
180 | ClassicTaskIdentification_Pre_Node_SearchLocal, |
---|
181 | ClassicTaskIdentification_Pre_Node_NA |
---|
182 | } ClassicTaskIdentification_Pre_Node; |
---|
183 | |
---|
184 | typedef enum { |
---|
185 | ClassicTaskIdentification_Pre_Id_NullPtr, |
---|
186 | ClassicTaskIdentification_Pre_Id_Valid, |
---|
187 | ClassicTaskIdentification_Pre_Id_NA |
---|
188 | } ClassicTaskIdentification_Pre_Id; |
---|
189 | |
---|
190 | typedef enum { |
---|
191 | ClassicTaskIdentification_Post_Status_Ok, |
---|
192 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
193 | ClassicTaskIdentification_Post_Status_InvName, |
---|
194 | ClassicTaskIdentification_Post_Status_InvNode, |
---|
195 | ClassicTaskIdentification_Post_Status_InvId, |
---|
196 | ClassicTaskIdentification_Post_Status_NA |
---|
197 | } ClassicTaskIdentification_Post_Status; |
---|
198 | |
---|
199 | typedef enum { |
---|
200 | ClassicTaskIdentification_Post_Id_Nop, |
---|
201 | ClassicTaskIdentification_Post_Id_NullPtr, |
---|
202 | ClassicTaskIdentification_Post_Id_Self, |
---|
203 | ClassicTaskIdentification_Post_Id_LocalTask, |
---|
204 | ClassicTaskIdentification_Post_Id_RemoteTask, |
---|
205 | ClassicTaskIdentification_Post_Id_NA |
---|
206 | } ClassicTaskIdentification_Post_Id; |
---|
207 | |
---|
208 | /** |
---|
209 | * @brief Test context for Classic Task Identification test case. |
---|
210 | */ |
---|
211 | typedef struct { |
---|
212 | /** |
---|
213 | * @brief Brief context member description. |
---|
214 | * |
---|
215 | * Context member description. |
---|
216 | */ |
---|
217 | rtems_status_code status; |
---|
218 | |
---|
219 | rtems_name name; |
---|
220 | |
---|
221 | uint32_t node; |
---|
222 | |
---|
223 | rtems_id *id; |
---|
224 | |
---|
225 | rtems_id id_value; |
---|
226 | |
---|
227 | rtems_id id_local_task; |
---|
228 | |
---|
229 | rtems_id id_remote_task; |
---|
230 | |
---|
231 | /** |
---|
232 | * @brief This member defines the pre-condition states for the next action. |
---|
233 | */ |
---|
234 | size_t pcs[ 3 ]; |
---|
235 | |
---|
236 | /** |
---|
237 | * @brief This member indicates if the test action loop is currently |
---|
238 | * executed. |
---|
239 | */ |
---|
240 | bool in_action_loop; |
---|
241 | } ClassicTaskIdentification_Context; |
---|
242 | |
---|
243 | static ClassicTaskIdentification_Context |
---|
244 | ClassicTaskIdentification_Instance; |
---|
245 | |
---|
246 | static const char * const ClassicTaskIdentification_PreDesc_Name[] = { |
---|
247 | "Invalid", |
---|
248 | "Self", |
---|
249 | "Valid" |
---|
250 | }; |
---|
251 | |
---|
252 | static const char * const ClassicTaskIdentification_PreDesc_Node[] = { |
---|
253 | "Local", |
---|
254 | "Remote", |
---|
255 | "Invalid", |
---|
256 | "SearchAll", |
---|
257 | "SearchOther", |
---|
258 | "SearchLocal" |
---|
259 | }; |
---|
260 | |
---|
261 | static const char * const ClassicTaskIdentification_PreDesc_Id[] = { |
---|
262 | "NullPtr", |
---|
263 | "Valid" |
---|
264 | }; |
---|
265 | |
---|
266 | static const char * const * const ClassicTaskIdentification_PreDesc[] = { |
---|
267 | ClassicTaskIdentification_PreDesc_Name, |
---|
268 | ClassicTaskIdentification_PreDesc_Node, |
---|
269 | ClassicTaskIdentification_PreDesc_Id, |
---|
270 | NULL |
---|
271 | }; |
---|
272 | |
---|
273 | /* Test rtems_task_ident() support */ |
---|
274 | |
---|
275 | static void ClassicTaskIdentification_Pre_Name_Prepare( |
---|
276 | ClassicTaskIdentification_Context *ctx, |
---|
277 | ClassicTaskIdentification_Pre_Name state |
---|
278 | ) |
---|
279 | { |
---|
280 | /* Prologue */ |
---|
281 | |
---|
282 | switch ( state ) { |
---|
283 | case ClassicTaskIdentification_Pre_Name_Invalid: { |
---|
284 | ctx->name = 1; |
---|
285 | break; |
---|
286 | } |
---|
287 | |
---|
288 | case ClassicTaskIdentification_Pre_Name_Self: { |
---|
289 | ctx->name = RTEMS_SELF; |
---|
290 | break; |
---|
291 | } |
---|
292 | |
---|
293 | case ClassicTaskIdentification_Pre_Name_Valid: { |
---|
294 | ctx->name = rtems_build_name( 'T', 'A', 'S', 'K' ); |
---|
295 | break; |
---|
296 | } |
---|
297 | |
---|
298 | case ClassicTaskIdentification_Pre_Name_NA: |
---|
299 | break; |
---|
300 | } |
---|
301 | |
---|
302 | /* Epilogue */ |
---|
303 | } |
---|
304 | |
---|
305 | static void ClassicTaskIdentification_Pre_Node_Prepare( |
---|
306 | ClassicTaskIdentification_Context *ctx, |
---|
307 | ClassicTaskIdentification_Pre_Node state |
---|
308 | ) |
---|
309 | { |
---|
310 | switch ( state ) { |
---|
311 | case ClassicTaskIdentification_Pre_Node_Local: { |
---|
312 | ctx->node = 1; |
---|
313 | break; |
---|
314 | } |
---|
315 | |
---|
316 | case ClassicTaskIdentification_Pre_Node_Remote: { |
---|
317 | ctx->node = 2; |
---|
318 | break; |
---|
319 | } |
---|
320 | |
---|
321 | case ClassicTaskIdentification_Pre_Node_Invalid: { |
---|
322 | ctx->node = 256; |
---|
323 | break; |
---|
324 | } |
---|
325 | |
---|
326 | case ClassicTaskIdentification_Pre_Node_SearchAll: { |
---|
327 | ctx->node = RTEMS_SEARCH_ALL_NODES; |
---|
328 | break; |
---|
329 | } |
---|
330 | |
---|
331 | case ClassicTaskIdentification_Pre_Node_SearchOther: { |
---|
332 | ctx->node = RTEMS_SEARCH_OTHER_NODES; |
---|
333 | break; |
---|
334 | } |
---|
335 | |
---|
336 | case ClassicTaskIdentification_Pre_Node_SearchLocal: { |
---|
337 | ctx->node = RTEMS_SEARCH_LOCAL_NODE; |
---|
338 | break; |
---|
339 | } |
---|
340 | |
---|
341 | case ClassicTaskIdentification_Pre_Node_NA: |
---|
342 | break; |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | static void ClassicTaskIdentification_Pre_Id_Prepare( |
---|
347 | ClassicTaskIdentification_Context *ctx, |
---|
348 | ClassicTaskIdentification_Pre_Id state |
---|
349 | ) |
---|
350 | { |
---|
351 | switch ( state ) { |
---|
352 | case ClassicTaskIdentification_Pre_Id_NullPtr: { |
---|
353 | ctx->id = NULL; |
---|
354 | break; |
---|
355 | } |
---|
356 | |
---|
357 | case ClassicTaskIdentification_Pre_Id_Valid: { |
---|
358 | ctx->id_value = 0xffffffff; |
---|
359 | ctx->id = &ctx->id_value; |
---|
360 | break; |
---|
361 | } |
---|
362 | |
---|
363 | case ClassicTaskIdentification_Pre_Id_NA: |
---|
364 | break; |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | static void ClassicTaskIdentification_Post_Status_Check( |
---|
369 | ClassicTaskIdentification_Context *ctx, |
---|
370 | ClassicTaskIdentification_Post_Status state |
---|
371 | ) |
---|
372 | { |
---|
373 | switch ( state ) { |
---|
374 | case ClassicTaskIdentification_Post_Status_Ok: { |
---|
375 | T_rsc(ctx->status, RTEMS_SUCCESSFUL); |
---|
376 | break; |
---|
377 | } |
---|
378 | |
---|
379 | case ClassicTaskIdentification_Post_Status_InvAddr: { |
---|
380 | T_rsc(ctx->status, RTEMS_INVALID_ADDRESS); |
---|
381 | break; |
---|
382 | } |
---|
383 | |
---|
384 | case ClassicTaskIdentification_Post_Status_InvName: { |
---|
385 | T_rsc(ctx->status, RTEMS_INVALID_NAME); |
---|
386 | break; |
---|
387 | } |
---|
388 | |
---|
389 | case ClassicTaskIdentification_Post_Status_InvNode: { |
---|
390 | T_rsc(ctx->status, RTEMS_INVALID_NODE); |
---|
391 | break; |
---|
392 | } |
---|
393 | |
---|
394 | case ClassicTaskIdentification_Post_Status_InvId: { |
---|
395 | T_rsc(ctx->status, RTEMS_INVALID_ID); |
---|
396 | break; |
---|
397 | } |
---|
398 | |
---|
399 | case ClassicTaskIdentification_Post_Status_NA: |
---|
400 | break; |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | static void ClassicTaskIdentification_Post_Id_Check( |
---|
405 | ClassicTaskIdentification_Context *ctx, |
---|
406 | ClassicTaskIdentification_Post_Id state |
---|
407 | ) |
---|
408 | { |
---|
409 | switch ( state ) { |
---|
410 | case ClassicTaskIdentification_Post_Id_Nop: { |
---|
411 | T_eq_ptr(ctx->id, &ctx->id_value); |
---|
412 | T_eq_u32(ctx->id_value, 0xffffffff); |
---|
413 | break; |
---|
414 | } |
---|
415 | |
---|
416 | case ClassicTaskIdentification_Post_Id_NullPtr: { |
---|
417 | T_null(ctx->id) |
---|
418 | break; |
---|
419 | } |
---|
420 | |
---|
421 | case ClassicTaskIdentification_Post_Id_Self: { |
---|
422 | T_eq_ptr(ctx->id, &ctx->id_value); |
---|
423 | T_eq_u32(ctx->id_value, rtems_task_self()); |
---|
424 | break; |
---|
425 | } |
---|
426 | |
---|
427 | case ClassicTaskIdentification_Post_Id_LocalTask: { |
---|
428 | T_eq_ptr(ctx->id, &ctx->id_value); |
---|
429 | T_eq_u32(ctx->id_value, ctx->id_local_task); |
---|
430 | break; |
---|
431 | } |
---|
432 | |
---|
433 | case ClassicTaskIdentification_Post_Id_RemoteTask: { |
---|
434 | T_eq_ptr(ctx->id, &ctx->id_value); |
---|
435 | T_eq_u32(ctx->id_value, ctx->id_remote_task); |
---|
436 | break; |
---|
437 | } |
---|
438 | |
---|
439 | case ClassicTaskIdentification_Post_Id_NA: |
---|
440 | break; |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | /** |
---|
445 | * @brief Setup brief description. |
---|
446 | * |
---|
447 | * Setup description. |
---|
448 | */ |
---|
449 | static void ClassicTaskIdentification_Setup( |
---|
450 | ClassicTaskIdentification_Context *ctx |
---|
451 | ) |
---|
452 | { |
---|
453 | rtems_status_code sc; |
---|
454 | |
---|
455 | sc = rtems_task_create( |
---|
456 | rtems_build_name( 'T', 'A', 'S', 'K' ), |
---|
457 | 1, |
---|
458 | RTEMS_MINIMUM_STACK_SIZE, |
---|
459 | RTEMS_DEFAULT_MODES, |
---|
460 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
461 | &ctx->id_local_task |
---|
462 | ); |
---|
463 | T_assert_rsc_success( sc ); |
---|
464 | } |
---|
465 | |
---|
466 | static void ClassicTaskIdentification_Setup_Wrap( void *arg ) |
---|
467 | { |
---|
468 | ClassicTaskIdentification_Context *ctx; |
---|
469 | |
---|
470 | ctx = arg; |
---|
471 | ctx->in_action_loop = false; |
---|
472 | ClassicTaskIdentification_Setup( ctx ); |
---|
473 | } |
---|
474 | |
---|
475 | static void ClassicTaskIdentification_Teardown( |
---|
476 | ClassicTaskIdentification_Context *ctx |
---|
477 | ) |
---|
478 | { |
---|
479 | rtems_status_code sc; |
---|
480 | |
---|
481 | if ( ctx->id_local_task != 0 ) { |
---|
482 | sc = rtems_task_delete( ctx->id_local_task ); |
---|
483 | T_rsc_success( sc ); |
---|
484 | } |
---|
485 | } |
---|
486 | |
---|
487 | static void ClassicTaskIdentification_Teardown_Wrap( void *arg ) |
---|
488 | { |
---|
489 | ClassicTaskIdentification_Context *ctx; |
---|
490 | |
---|
491 | ctx = arg; |
---|
492 | ctx->in_action_loop = false; |
---|
493 | ClassicTaskIdentification_Teardown( ctx ); |
---|
494 | } |
---|
495 | |
---|
496 | static void ClassicTaskIdentification_Scope( void *arg, char *buf, size_t n ) |
---|
497 | { |
---|
498 | ClassicTaskIdentification_Context *ctx; |
---|
499 | |
---|
500 | ctx = arg; |
---|
501 | |
---|
502 | if ( ctx->in_action_loop ) { |
---|
503 | T_get_scope( ClassicTaskIdentification_PreDesc, buf, n, ctx->pcs ); |
---|
504 | } |
---|
505 | } |
---|
506 | |
---|
507 | static T_fixture ClassicTaskIdentification_Fixture = { |
---|
508 | .setup = ClassicTaskIdentification_Setup_Wrap, |
---|
509 | .stop = NULL, |
---|
510 | .teardown = ClassicTaskIdentification_Teardown_Wrap, |
---|
511 | .scope = ClassicTaskIdentification_Scope, |
---|
512 | .initial_context = &ClassicTaskIdentification_Instance |
---|
513 | }; |
---|
514 | |
---|
515 | static const uint8_t ClassicTaskIdentification_TransitionMap[][ 2 ] = { |
---|
516 | { |
---|
517 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
518 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
519 | }, { |
---|
520 | ClassicTaskIdentification_Post_Status_InvName, |
---|
521 | ClassicTaskIdentification_Post_Id_Nop |
---|
522 | }, { |
---|
523 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
524 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
525 | }, { |
---|
526 | ClassicTaskIdentification_Post_Status_InvName, |
---|
527 | ClassicTaskIdentification_Post_Id_Nop |
---|
528 | }, { |
---|
529 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
530 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
531 | }, { |
---|
532 | ClassicTaskIdentification_Post_Status_InvName, |
---|
533 | ClassicTaskIdentification_Post_Id_Nop |
---|
534 | }, { |
---|
535 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
536 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
537 | }, { |
---|
538 | ClassicTaskIdentification_Post_Status_InvName, |
---|
539 | ClassicTaskIdentification_Post_Id_Nop |
---|
540 | }, { |
---|
541 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
542 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
543 | }, { |
---|
544 | ClassicTaskIdentification_Post_Status_InvName, |
---|
545 | ClassicTaskIdentification_Post_Id_Nop |
---|
546 | }, { |
---|
547 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
548 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
549 | }, { |
---|
550 | ClassicTaskIdentification_Post_Status_InvName, |
---|
551 | ClassicTaskIdentification_Post_Id_Nop |
---|
552 | }, { |
---|
553 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
554 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
555 | }, { |
---|
556 | ClassicTaskIdentification_Post_Status_Ok, |
---|
557 | ClassicTaskIdentification_Post_Id_Self |
---|
558 | }, { |
---|
559 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
560 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
561 | }, { |
---|
562 | ClassicTaskIdentification_Post_Status_Ok, |
---|
563 | ClassicTaskIdentification_Post_Id_Self |
---|
564 | }, { |
---|
565 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
566 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
567 | }, { |
---|
568 | ClassicTaskIdentification_Post_Status_Ok, |
---|
569 | ClassicTaskIdentification_Post_Id_Self |
---|
570 | }, { |
---|
571 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
572 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
573 | }, { |
---|
574 | ClassicTaskIdentification_Post_Status_Ok, |
---|
575 | ClassicTaskIdentification_Post_Id_Self |
---|
576 | }, { |
---|
577 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
578 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
579 | }, { |
---|
580 | ClassicTaskIdentification_Post_Status_Ok, |
---|
581 | ClassicTaskIdentification_Post_Id_Self |
---|
582 | }, { |
---|
583 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
584 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
585 | }, { |
---|
586 | ClassicTaskIdentification_Post_Status_Ok, |
---|
587 | ClassicTaskIdentification_Post_Id_Self |
---|
588 | }, { |
---|
589 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
590 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
591 | }, { |
---|
592 | ClassicTaskIdentification_Post_Status_Ok, |
---|
593 | ClassicTaskIdentification_Post_Id_LocalTask |
---|
594 | }, { |
---|
595 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
596 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
597 | }, { |
---|
598 | #if defined(RTEMS_MULTIPROCESSING) |
---|
599 | ClassicTaskIdentification_Post_Status_Ok, |
---|
600 | ClassicTaskIdentification_Post_Id_RemoteTask |
---|
601 | #else |
---|
602 | ClassicTaskIdentification_Post_Status_InvName, |
---|
603 | ClassicTaskIdentification_Post_Id_Nop |
---|
604 | #endif |
---|
605 | }, { |
---|
606 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
607 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
608 | }, { |
---|
609 | ClassicTaskIdentification_Post_Status_InvName, |
---|
610 | ClassicTaskIdentification_Post_Id_Nop |
---|
611 | }, { |
---|
612 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
613 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
614 | }, { |
---|
615 | ClassicTaskIdentification_Post_Status_Ok, |
---|
616 | ClassicTaskIdentification_Post_Id_LocalTask |
---|
617 | }, { |
---|
618 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
619 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
620 | }, { |
---|
621 | #if defined(RTEMS_MULTIPROCESSING) |
---|
622 | ClassicTaskIdentification_Post_Status_Ok, |
---|
623 | ClassicTaskIdentification_Post_Id_RemoteTask |
---|
624 | #else |
---|
625 | ClassicTaskIdentification_Post_Status_InvName, |
---|
626 | ClassicTaskIdentification_Post_Id_Nop |
---|
627 | #endif |
---|
628 | }, { |
---|
629 | ClassicTaskIdentification_Post_Status_InvAddr, |
---|
630 | ClassicTaskIdentification_Post_Id_NullPtr |
---|
631 | }, { |
---|
632 | ClassicTaskIdentification_Post_Status_Ok, |
---|
633 | ClassicTaskIdentification_Post_Id_LocalTask |
---|
634 | } |
---|
635 | }; |
---|
636 | |
---|
637 | static const struct { |
---|
638 | uint8_t Skip : 1; |
---|
639 | uint8_t Pre_Name_NA : 1; |
---|
640 | uint8_t Pre_Node_NA : 1; |
---|
641 | uint8_t Pre_Id_NA : 1; |
---|
642 | } ClassicTaskIdentification_TransitionInfo[] = { |
---|
643 | { |
---|
644 | 0, 0, 0, 0 |
---|
645 | }, { |
---|
646 | 0, 0, 0, 0 |
---|
647 | }, { |
---|
648 | 0, 0, 0, 0 |
---|
649 | }, { |
---|
650 | 0, 0, 0, 0 |
---|
651 | }, { |
---|
652 | 0, 0, 0, 0 |
---|
653 | }, { |
---|
654 | 0, 0, 0, 0 |
---|
655 | }, { |
---|
656 | 0, 0, 0, 0 |
---|
657 | }, { |
---|
658 | 0, 0, 0, 0 |
---|
659 | }, { |
---|
660 | 0, 0, 0, 0 |
---|
661 | }, { |
---|
662 | 0, 0, 0, 0 |
---|
663 | }, { |
---|
664 | 0, 0, 0, 0 |
---|
665 | }, { |
---|
666 | 0, 0, 0, 0 |
---|
667 | }, { |
---|
668 | 0, 0, 0, 0 |
---|
669 | }, { |
---|
670 | 0, 0, 0, 0 |
---|
671 | }, { |
---|
672 | 0, 0, 0, 0 |
---|
673 | }, { |
---|
674 | 0, 0, 0, 0 |
---|
675 | }, { |
---|
676 | 0, 0, 0, 0 |
---|
677 | }, { |
---|
678 | 0, 0, 0, 0 |
---|
679 | }, { |
---|
680 | 0, 0, 0, 0 |
---|
681 | }, { |
---|
682 | 0, 0, 0, 0 |
---|
683 | }, { |
---|
684 | 0, 0, 0, 0 |
---|
685 | }, { |
---|
686 | 0, 0, 0, 0 |
---|
687 | }, { |
---|
688 | 0, 0, 0, 0 |
---|
689 | }, { |
---|
690 | 0, 0, 0, 0 |
---|
691 | }, { |
---|
692 | 0, 0, 0, 0 |
---|
693 | }, { |
---|
694 | 0, 0, 0, 0 |
---|
695 | }, { |
---|
696 | 0, 0, 0, 0 |
---|
697 | }, { |
---|
698 | #if defined(RTEMS_MULTIPROCESSING) |
---|
699 | 0, 0, 0, 0 |
---|
700 | #else |
---|
701 | 0, 0, 0, 0 |
---|
702 | #endif |
---|
703 | }, { |
---|
704 | 0, 0, 0, 0 |
---|
705 | }, { |
---|
706 | 0, 0, 0, 0 |
---|
707 | }, { |
---|
708 | 0, 0, 0, 0 |
---|
709 | }, { |
---|
710 | 0, 0, 0, 0 |
---|
711 | }, { |
---|
712 | 0, 0, 0, 0 |
---|
713 | }, { |
---|
714 | #if defined(RTEMS_MULTIPROCESSING) |
---|
715 | 0, 0, 0, 0 |
---|
716 | #else |
---|
717 | 0, 0, 0, 0 |
---|
718 | #endif |
---|
719 | }, { |
---|
720 | 0, 0, 0, 0 |
---|
721 | }, { |
---|
722 | 0, 0, 0, 0 |
---|
723 | } |
---|
724 | }; |
---|
725 | |
---|
726 | /** |
---|
727 | * @fn void T_case_body_ClassicTaskIdentification( void ) |
---|
728 | * |
---|
729 | * @brief Test rtems_task_ident() brief description. |
---|
730 | * |
---|
731 | * Test rtems_task_ident() description. |
---|
732 | */ |
---|
733 | T_TEST_CASE_FIXTURE( |
---|
734 | ClassicTaskIdentification, |
---|
735 | &ClassicTaskIdentification_Fixture |
---|
736 | ) |
---|
737 | { |
---|
738 | ClassicTaskIdentification_Context *ctx; |
---|
739 | size_t index; |
---|
740 | |
---|
741 | ctx = T_fixture_context(); |
---|
742 | ctx->in_action_loop = true; |
---|
743 | index = 0; |
---|
744 | |
---|
745 | for ( |
---|
746 | ctx->pcs[ 0 ] = ClassicTaskIdentification_Pre_Name_Invalid; |
---|
747 | ctx->pcs[ 0 ] < ClassicTaskIdentification_Pre_Name_NA; |
---|
748 | ++ctx->pcs[ 0 ] |
---|
749 | ) { |
---|
750 | if ( ClassicTaskIdentification_TransitionInfo[ index ].Pre_Name_NA ) { |
---|
751 | ctx->pcs[ 0 ] = ClassicTaskIdentification_Pre_Name_NA; |
---|
752 | index += ( ClassicTaskIdentification_Pre_Name_NA - 1 ) |
---|
753 | * ClassicTaskIdentification_Pre_Node_NA |
---|
754 | * ClassicTaskIdentification_Pre_Id_NA; |
---|
755 | } |
---|
756 | |
---|
757 | for ( |
---|
758 | ctx->pcs[ 1 ] = ClassicTaskIdentification_Pre_Node_Local; |
---|
759 | ctx->pcs[ 1 ] < ClassicTaskIdentification_Pre_Node_NA; |
---|
760 | ++ctx->pcs[ 1 ] |
---|
761 | ) { |
---|
762 | if ( ClassicTaskIdentification_TransitionInfo[ index ].Pre_Node_NA ) { |
---|
763 | ctx->pcs[ 1 ] = ClassicTaskIdentification_Pre_Node_NA; |
---|
764 | index += ( ClassicTaskIdentification_Pre_Node_NA - 1 ) |
---|
765 | * ClassicTaskIdentification_Pre_Id_NA; |
---|
766 | } |
---|
767 | |
---|
768 | for ( |
---|
769 | ctx->pcs[ 2 ] = ClassicTaskIdentification_Pre_Id_NullPtr; |
---|
770 | ctx->pcs[ 2 ] < ClassicTaskIdentification_Pre_Id_NA; |
---|
771 | ++ctx->pcs[ 2 ] |
---|
772 | ) { |
---|
773 | if ( ClassicTaskIdentification_TransitionInfo[ index ].Pre_Id_NA ) { |
---|
774 | ctx->pcs[ 2 ] = ClassicTaskIdentification_Pre_Id_NA; |
---|
775 | index += ( ClassicTaskIdentification_Pre_Id_NA - 1 ); |
---|
776 | } |
---|
777 | |
---|
778 | if ( ClassicTaskIdentification_TransitionInfo[ index ].Skip ) { |
---|
779 | ++index; |
---|
780 | continue; |
---|
781 | } |
---|
782 | |
---|
783 | ClassicTaskIdentification_Pre_Name_Prepare( ctx, ctx->pcs[ 0 ] ); |
---|
784 | ClassicTaskIdentification_Pre_Node_Prepare( ctx, ctx->pcs[ 1 ] ); |
---|
785 | ClassicTaskIdentification_Pre_Id_Prepare( ctx, ctx->pcs[ 2 ] ); |
---|
786 | ctx->status = rtems_task_ident( ctx->name, ctx->node, ctx->id ); |
---|
787 | ClassicTaskIdentification_Post_Status_Check( |
---|
788 | ctx, |
---|
789 | ClassicTaskIdentification_TransitionMap[ index ][ 0 ] |
---|
790 | ); |
---|
791 | ClassicTaskIdentification_Post_Id_Check( |
---|
792 | ctx, |
---|
793 | ClassicTaskIdentification_TransitionMap[ index ][ 1 ] |
---|
794 | ); |
---|
795 | ++index; |
---|
796 | } |
---|
797 | } |
---|
798 | } |
---|
799 | } |
---|
800 | |
---|
801 | /** @} */ |
---|
802 | |
---|
803 | /** |
---|
804 | * @defgroup RTEMSTestCaseTestCase Test Case |
---|
805 | * |
---|
806 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
807 | * |
---|
808 | * @brief Test Case |
---|
809 | * |
---|
810 | * @{ |
---|
811 | */ |
---|
812 | |
---|
813 | /* Test case support code */ |
---|
814 | |
---|
815 | /** |
---|
816 | * @fn void T_case_body_TestCase( void ) |
---|
817 | * |
---|
818 | * @brief Test case brief description. |
---|
819 | * |
---|
820 | * Test case description. |
---|
821 | * |
---|
822 | * This test case performs the following actions: |
---|
823 | * |
---|
824 | * - Test case action 0 description. |
---|
825 | * |
---|
826 | * - Test case action 0 check 0 description. |
---|
827 | * |
---|
828 | * - Test case action 0 check 1 description. |
---|
829 | * |
---|
830 | * - Test case action 1 description. |
---|
831 | * |
---|
832 | * - Test case action 1 check 0 description. |
---|
833 | * |
---|
834 | * - Test case action 1 check 1 description. |
---|
835 | */ |
---|
836 | T_TEST_CASE( TestCase ) |
---|
837 | { |
---|
838 | /* Test case prologue code */ |
---|
839 | |
---|
840 | T_plan(2); |
---|
841 | |
---|
842 | /* Test case action 0 code */ |
---|
843 | /* Test case action 0 check 0 code */ |
---|
844 | /* Test case action 0 check 1 code; step 0 */ |
---|
845 | |
---|
846 | /* Test case action 1 code */ |
---|
847 | /* Test case action 1 check 0 code; step 1 */ |
---|
848 | /* Test case action 1 check 1 code */ |
---|
849 | |
---|
850 | /* Test case epilogue code */ |
---|
851 | } |
---|
852 | |
---|
853 | /** @} */ |
---|
854 | |
---|
855 | /** |
---|
856 | * @defgroup RTEMSTestCaseTestCase2 Test Case 2 |
---|
857 | * |
---|
858 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
859 | * |
---|
860 | * @brief Test Case |
---|
861 | * |
---|
862 | * @{ |
---|
863 | */ |
---|
864 | |
---|
865 | /** |
---|
866 | * @fn void T_case_body_TestCase2( void ) |
---|
867 | * |
---|
868 | * @brief Test case 2 brief description. |
---|
869 | * |
---|
870 | * Test case 2 description. |
---|
871 | * |
---|
872 | * This test case performs the following actions: |
---|
873 | * |
---|
874 | * - Test case 2 action 0 description. |
---|
875 | * |
---|
876 | * - Test case 2 action 0 check 0 description. |
---|
877 | * |
---|
878 | * - Test case 2 action 0 check 1 description. |
---|
879 | * |
---|
880 | * - Test case 2 action 1 description. |
---|
881 | */ |
---|
882 | T_TEST_CASE_FIXTURE( TestCase2, &test_case_2_fixture ) |
---|
883 | { |
---|
884 | /* Test case 2 action 0 code */ |
---|
885 | /* Test case 2 action 0 check 0 code */ |
---|
886 | /* Test case 2 action 0 check 1 code */ |
---|
887 | |
---|
888 | /* Test case 2 action 1 code */ |
---|
889 | } |
---|
890 | |
---|
891 | /** @} */ |
---|
892 | """ |
---|
893 | assert content == src.read() |
---|
894 | |
---|
895 | with open(os.path.join(base_directory, "tc34.c"), "r") as src: |
---|
896 | content = """/* SPDX-License-Identifier: BSD-2-Clause */ |
---|
897 | |
---|
898 | /** |
---|
899 | * @file |
---|
900 | * |
---|
901 | * @ingroup RTEMSTestCaseTestCase3 |
---|
902 | * @ingroup RTEMSTestCaseTestCase4 |
---|
903 | */ |
---|
904 | |
---|
905 | /* |
---|
906 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
907 | * |
---|
908 | * Redistribution and use in source and binary forms, with or without |
---|
909 | * modification, are permitted provided that the following conditions |
---|
910 | * are met: |
---|
911 | * 1. Redistributions of source code must retain the above copyright |
---|
912 | * notice, this list of conditions and the following disclaimer. |
---|
913 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
914 | * notice, this list of conditions and the following disclaimer in the |
---|
915 | * documentation and/or other materials provided with the distribution. |
---|
916 | * |
---|
917 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
918 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
919 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
920 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
921 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
922 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
923 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
924 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
925 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
926 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
927 | * POSSIBILITY OF SUCH DAMAGE. |
---|
928 | */ |
---|
929 | |
---|
930 | #ifdef HAVE_CONFIG_H |
---|
931 | #include "config.h" |
---|
932 | #endif |
---|
933 | |
---|
934 | #include <c.h> |
---|
935 | |
---|
936 | #include "z.h" |
---|
937 | |
---|
938 | #include <rtems/test.h> |
---|
939 | |
---|
940 | /** |
---|
941 | * @defgroup RTEMSTestCaseTestCase3 Test Case 3 |
---|
942 | * |
---|
943 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
944 | * |
---|
945 | * @brief Test Case |
---|
946 | * |
---|
947 | * @{ |
---|
948 | */ |
---|
949 | |
---|
950 | /** |
---|
951 | * @fn void T_case_body_TestCase3( void ) |
---|
952 | * |
---|
953 | * @brief Test case 3 brief description. |
---|
954 | * |
---|
955 | * Test case 3 description. |
---|
956 | * |
---|
957 | * This test case performs the following actions: |
---|
958 | * |
---|
959 | * - Test case 3 action 0 description. |
---|
960 | * |
---|
961 | * - Test case 3 action 0 check 0 description. |
---|
962 | */ |
---|
963 | T_TEST_CASE( TestCase3 ) |
---|
964 | { |
---|
965 | T_plan(1); |
---|
966 | |
---|
967 | /* Test case 3 action 0 code */ |
---|
968 | /* Test case 3 action 0 check 0 code; step 0 */ |
---|
969 | } |
---|
970 | |
---|
971 | /** @} */ |
---|
972 | |
---|
973 | /** |
---|
974 | * @defgroup RTEMSTestCaseTestCase4 Test Case 4 |
---|
975 | * |
---|
976 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
977 | * |
---|
978 | * @brief Test Case |
---|
979 | * |
---|
980 | * @{ |
---|
981 | */ |
---|
982 | |
---|
983 | /** |
---|
984 | * @fn void T_case_body_TestCase4( void ) |
---|
985 | * |
---|
986 | * @brief Test case 4 brief description. |
---|
987 | * |
---|
988 | * Test case 4 description. |
---|
989 | */ |
---|
990 | T_TEST_CASE( TestCase4 ) |
---|
991 | { |
---|
992 | /* Test case 4 epilogue code */ |
---|
993 | } |
---|
994 | |
---|
995 | /** @} */ |
---|
996 | """ |
---|
997 | assert content == src.read() |
---|
998 | with open(os.path.join(base_directory, "action2.h"), "r") as src: |
---|
999 | content = """/* SPDX-License-Identifier: BSD-2-Clause */ |
---|
1000 | |
---|
1001 | /** |
---|
1002 | * @file |
---|
1003 | * |
---|
1004 | * @ingroup RTEMSTestCaseAction2 |
---|
1005 | */ |
---|
1006 | |
---|
1007 | /* |
---|
1008 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
1009 | * |
---|
1010 | * Redistribution and use in source and binary forms, with or without |
---|
1011 | * modification, are permitted provided that the following conditions |
---|
1012 | * are met: |
---|
1013 | * 1. Redistributions of source code must retain the above copyright |
---|
1014 | * notice, this list of conditions and the following disclaimer. |
---|
1015 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
1016 | * notice, this list of conditions and the following disclaimer in the |
---|
1017 | * documentation and/or other materials provided with the distribution. |
---|
1018 | * |
---|
1019 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
1020 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
1021 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
1022 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
1023 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
1024 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
1025 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
1026 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
1027 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
1028 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
1029 | * POSSIBILITY OF SUCH DAMAGE. |
---|
1030 | */ |
---|
1031 | |
---|
1032 | #ifndef _ACTION2_H |
---|
1033 | #define _ACTION2_H |
---|
1034 | |
---|
1035 | #include <d.h> |
---|
1036 | |
---|
1037 | #include "e.h" |
---|
1038 | |
---|
1039 | #ifdef __cplusplus |
---|
1040 | extern "C" { |
---|
1041 | #endif |
---|
1042 | |
---|
1043 | /** |
---|
1044 | * @addtogroup RTEMSTestCaseAction2 |
---|
1045 | * |
---|
1046 | * @{ |
---|
1047 | */ |
---|
1048 | |
---|
1049 | typedef enum { |
---|
1050 | Action2_Pre_A_X, |
---|
1051 | Action2_Pre_A_Y, |
---|
1052 | Action2_Pre_A_NA |
---|
1053 | } Action2_Pre_A; |
---|
1054 | |
---|
1055 | typedef enum { |
---|
1056 | Action2_Pre_B_X, |
---|
1057 | Action2_Pre_B_Y, |
---|
1058 | Action2_Pre_B_Z, |
---|
1059 | Action2_Pre_B_NA |
---|
1060 | } Action2_Pre_B; |
---|
1061 | |
---|
1062 | typedef enum { |
---|
1063 | Action2_Post_A_X, |
---|
1064 | Action2_Post_A_Y, |
---|
1065 | Action2_Post_A_NA |
---|
1066 | } Action2_Post_A; |
---|
1067 | |
---|
1068 | typedef enum { |
---|
1069 | Action2_Post_B_X, |
---|
1070 | Action2_Post_B_Y, |
---|
1071 | Action2_Post_B_NA |
---|
1072 | } Action2_Post_B; |
---|
1073 | |
---|
1074 | /* Header code for Action 2 with Action2_Run() */ |
---|
1075 | |
---|
1076 | /** |
---|
1077 | * @brief Test brief. |
---|
1078 | * |
---|
1079 | * Test description. |
---|
1080 | * |
---|
1081 | * @param[in] a Parameter A description. |
---|
1082 | * |
---|
1083 | * @param b Parameter B description. |
---|
1084 | * |
---|
1085 | * @param[out] c Parameter C description. |
---|
1086 | */ |
---|
1087 | void Action2_Run( int *a, int b, int *c ); |
---|
1088 | |
---|
1089 | /** @} */ |
---|
1090 | |
---|
1091 | #ifdef __cplusplus |
---|
1092 | } |
---|
1093 | #endif |
---|
1094 | |
---|
1095 | #endif /* _ACTION2_H */ |
---|
1096 | """ |
---|
1097 | assert content == src.read() |
---|
1098 | with open(os.path.join(base_directory, "action2.c"), "r") as src: |
---|
1099 | content = """/* SPDX-License-Identifier: BSD-2-Clause */ |
---|
1100 | |
---|
1101 | /** |
---|
1102 | * @file |
---|
1103 | * |
---|
1104 | * @ingroup RTEMSTestCaseAction2 |
---|
1105 | */ |
---|
1106 | |
---|
1107 | /* |
---|
1108 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
1109 | * |
---|
1110 | * Redistribution and use in source and binary forms, with or without |
---|
1111 | * modification, are permitted provided that the following conditions |
---|
1112 | * are met: |
---|
1113 | * 1. Redistributions of source code must retain the above copyright |
---|
1114 | * notice, this list of conditions and the following disclaimer. |
---|
1115 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
1116 | * notice, this list of conditions and the following disclaimer in the |
---|
1117 | * documentation and/or other materials provided with the distribution. |
---|
1118 | * |
---|
1119 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
1120 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
1121 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
1122 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
1123 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
1124 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
1125 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
1126 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
1127 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
1128 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
1129 | * POSSIBILITY OF SUCH DAMAGE. |
---|
1130 | */ |
---|
1131 | |
---|
1132 | #ifdef HAVE_CONFIG_H |
---|
1133 | #include "config.h" |
---|
1134 | #endif |
---|
1135 | |
---|
1136 | #include <a.h> |
---|
1137 | |
---|
1138 | #include "b.h" |
---|
1139 | |
---|
1140 | #include <rtems/test.h> |
---|
1141 | |
---|
1142 | /** |
---|
1143 | * @defgroup RTEMSTestCaseAction2 Action 2 |
---|
1144 | * |
---|
1145 | * @ingroup RTEMSTestSuiteBlueGreen |
---|
1146 | * |
---|
1147 | * @brief Test Case |
---|
1148 | * |
---|
1149 | * @{ |
---|
1150 | */ |
---|
1151 | |
---|
1152 | /** |
---|
1153 | * @brief Test context for Action 2 test case. |
---|
1154 | */ |
---|
1155 | typedef struct { |
---|
1156 | /** |
---|
1157 | * @brief Context member brief. |
---|
1158 | * |
---|
1159 | * Context member description. |
---|
1160 | */ |
---|
1161 | int member; |
---|
1162 | |
---|
1163 | /** |
---|
1164 | * @brief This member contains a copy of the corresponding Action2_Run() |
---|
1165 | * parameter. |
---|
1166 | */ |
---|
1167 | int *a; |
---|
1168 | |
---|
1169 | /** |
---|
1170 | * @brief This member contains a copy of the corresponding Action2_Run() |
---|
1171 | * parameter. |
---|
1172 | */ |
---|
1173 | int b; |
---|
1174 | |
---|
1175 | /** |
---|
1176 | * @brief This member contains a copy of the corresponding Action2_Run() |
---|
1177 | * parameter. |
---|
1178 | */ |
---|
1179 | int *c; |
---|
1180 | |
---|
1181 | /** |
---|
1182 | * @brief This member defines the pre-condition states for the next action. |
---|
1183 | */ |
---|
1184 | size_t pcs[ 2 ]; |
---|
1185 | |
---|
1186 | /** |
---|
1187 | * @brief This member indicates if the test action loop is currently |
---|
1188 | * executed. |
---|
1189 | */ |
---|
1190 | bool in_action_loop; |
---|
1191 | } Action2_Context; |
---|
1192 | |
---|
1193 | static Action2_Context |
---|
1194 | Action2_Instance; |
---|
1195 | |
---|
1196 | static const char * const Action2_PreDesc_A[] = { |
---|
1197 | "X", |
---|
1198 | "Y" |
---|
1199 | }; |
---|
1200 | |
---|
1201 | static const char * const Action2_PreDesc_B[] = { |
---|
1202 | "X", |
---|
1203 | "Y", |
---|
1204 | "Z" |
---|
1205 | }; |
---|
1206 | |
---|
1207 | static const char * const * const Action2_PreDesc[] = { |
---|
1208 | Action2_PreDesc_A, |
---|
1209 | Action2_PreDesc_B, |
---|
1210 | NULL |
---|
1211 | }; |
---|
1212 | |
---|
1213 | /* Support code */ |
---|
1214 | |
---|
1215 | static void Action2_Pre_A_Prepare( Action2_Context *ctx, Action2_Pre_A state ) |
---|
1216 | { |
---|
1217 | /* Pre A prologue. */ |
---|
1218 | |
---|
1219 | switch ( state ) { |
---|
1220 | case Action2_Pre_A_X: { |
---|
1221 | /* Pre A X */ |
---|
1222 | break; |
---|
1223 | } |
---|
1224 | |
---|
1225 | case Action2_Pre_A_Y: { |
---|
1226 | /* Pre A Y */ |
---|
1227 | break; |
---|
1228 | } |
---|
1229 | |
---|
1230 | case Action2_Pre_A_NA: |
---|
1231 | break; |
---|
1232 | } |
---|
1233 | |
---|
1234 | /* Pre A epilogue. */ |
---|
1235 | } |
---|
1236 | |
---|
1237 | static void Action2_Pre_B_Prepare( Action2_Context *ctx, Action2_Pre_B state ) |
---|
1238 | { |
---|
1239 | /* Pre B prologue. */ |
---|
1240 | |
---|
1241 | switch ( state ) { |
---|
1242 | case Action2_Pre_B_X: { |
---|
1243 | /* Pre B X */ |
---|
1244 | break; |
---|
1245 | } |
---|
1246 | |
---|
1247 | case Action2_Pre_B_Y: { |
---|
1248 | /* Pre B Y */ |
---|
1249 | break; |
---|
1250 | } |
---|
1251 | |
---|
1252 | case Action2_Pre_B_Z: { |
---|
1253 | /* Pre B Z */ |
---|
1254 | break; |
---|
1255 | } |
---|
1256 | |
---|
1257 | case Action2_Pre_B_NA: |
---|
1258 | break; |
---|
1259 | } |
---|
1260 | |
---|
1261 | /* Pre B epilogue. */ |
---|
1262 | } |
---|
1263 | |
---|
1264 | static void Action2_Post_A_Check( Action2_Context *ctx, Action2_Post_A state ) |
---|
1265 | { |
---|
1266 | /* Post A prologue. */ |
---|
1267 | |
---|
1268 | switch ( state ) { |
---|
1269 | case Action2_Post_A_X: { |
---|
1270 | /* Post A X */ |
---|
1271 | break; |
---|
1272 | } |
---|
1273 | |
---|
1274 | case Action2_Post_A_Y: { |
---|
1275 | /* Post A Y */ |
---|
1276 | break; |
---|
1277 | } |
---|
1278 | |
---|
1279 | case Action2_Post_A_NA: |
---|
1280 | break; |
---|
1281 | } |
---|
1282 | |
---|
1283 | /* Post A epilogue. */ |
---|
1284 | } |
---|
1285 | |
---|
1286 | static void Action2_Post_B_Check( Action2_Context *ctx, Action2_Post_B state ) |
---|
1287 | { |
---|
1288 | /* Post B prologue. */ |
---|
1289 | |
---|
1290 | switch ( state ) { |
---|
1291 | case Action2_Post_B_X: { |
---|
1292 | /* Post B X */ |
---|
1293 | break; |
---|
1294 | } |
---|
1295 | |
---|
1296 | case Action2_Post_B_Y: { |
---|
1297 | /* Post B Y */ |
---|
1298 | break; |
---|
1299 | } |
---|
1300 | |
---|
1301 | case Action2_Post_B_NA: |
---|
1302 | break; |
---|
1303 | } |
---|
1304 | |
---|
1305 | /* Post B epilogue. */ |
---|
1306 | } |
---|
1307 | |
---|
1308 | /** |
---|
1309 | * @brief Setup brief. |
---|
1310 | * |
---|
1311 | * Setup description. |
---|
1312 | */ |
---|
1313 | static void Action2_Setup( Action2_Context *ctx ) |
---|
1314 | { |
---|
1315 | /* Setup code */ |
---|
1316 | } |
---|
1317 | |
---|
1318 | static void Action2_Setup_Wrap( void *arg ) |
---|
1319 | { |
---|
1320 | Action2_Context *ctx; |
---|
1321 | |
---|
1322 | ctx = arg; |
---|
1323 | ctx->in_action_loop = false; |
---|
1324 | Action2_Setup( ctx ); |
---|
1325 | } |
---|
1326 | |
---|
1327 | /** |
---|
1328 | * @brief Teardown brief. |
---|
1329 | * |
---|
1330 | * Teardown description. |
---|
1331 | */ |
---|
1332 | static void Action2_Teardown( Action2_Context *ctx ) |
---|
1333 | { |
---|
1334 | /* Teardown code */ |
---|
1335 | } |
---|
1336 | |
---|
1337 | static void Action2_Teardown_Wrap( void *arg ) |
---|
1338 | { |
---|
1339 | Action2_Context *ctx; |
---|
1340 | |
---|
1341 | ctx = arg; |
---|
1342 | ctx->in_action_loop = false; |
---|
1343 | Action2_Teardown( ctx ); |
---|
1344 | } |
---|
1345 | |
---|
1346 | static void Action2_Scope( void *arg, char *buf, size_t n ) |
---|
1347 | { |
---|
1348 | Action2_Context *ctx; |
---|
1349 | |
---|
1350 | ctx = arg; |
---|
1351 | |
---|
1352 | if ( ctx->in_action_loop ) { |
---|
1353 | T_get_scope( Action2_PreDesc, buf, n, ctx->pcs ); |
---|
1354 | } |
---|
1355 | } |
---|
1356 | |
---|
1357 | static T_fixture Action2_Fixture = { |
---|
1358 | .setup = Action2_Setup_Wrap, |
---|
1359 | .stop = NULL, |
---|
1360 | .teardown = Action2_Teardown_Wrap, |
---|
1361 | .scope = Action2_Scope, |
---|
1362 | .initial_context = &Action2_Instance |
---|
1363 | }; |
---|
1364 | |
---|
1365 | static const uint8_t Action2_TransitionMap[][ 2 ] = { |
---|
1366 | { |
---|
1367 | Action2_Post_A_X, |
---|
1368 | Action2_Post_B_Y |
---|
1369 | }, { |
---|
1370 | Action2_Post_A_Y, |
---|
1371 | Action2_Post_B_X |
---|
1372 | }, { |
---|
1373 | Action2_Post_A_X, |
---|
1374 | Action2_Post_B_X |
---|
1375 | }, { |
---|
1376 | Action2_Post_A_X, |
---|
1377 | Action2_Post_B_Y |
---|
1378 | }, { |
---|
1379 | Action2_Post_A_Y, |
---|
1380 | Action2_Post_B_X |
---|
1381 | }, { |
---|
1382 | Action2_Post_A_Y, |
---|
1383 | Action2_Post_B_Y |
---|
1384 | } |
---|
1385 | }; |
---|
1386 | |
---|
1387 | static const struct { |
---|
1388 | uint8_t Skip : 1; |
---|
1389 | uint8_t Pre_A_NA : 1; |
---|
1390 | uint8_t Pre_B_NA : 1; |
---|
1391 | } Action2_TransitionInfo[] = { |
---|
1392 | { |
---|
1393 | 0, 0, 0 |
---|
1394 | }, { |
---|
1395 | 0, 1, 0 |
---|
1396 | }, { |
---|
1397 | 0, 0, 0 |
---|
1398 | }, { |
---|
1399 | 0, 0, 0 |
---|
1400 | }, { |
---|
1401 | 0, 1, 0 |
---|
1402 | }, { |
---|
1403 | 1, 0, 0 |
---|
1404 | } |
---|
1405 | }; |
---|
1406 | |
---|
1407 | static T_fixture_node Action2_Node; |
---|
1408 | |
---|
1409 | void Action2_Run( int *a, int b, int *c ) |
---|
1410 | { |
---|
1411 | Action2_Context *ctx; |
---|
1412 | size_t index; |
---|
1413 | |
---|
1414 | ctx = T_push_fixture( &Action2_Node, &Action2_Fixture ); |
---|
1415 | |
---|
1416 | ctx->a = a; |
---|
1417 | ctx->b = b; |
---|
1418 | ctx->c = c; |
---|
1419 | ctx->in_action_loop = true; |
---|
1420 | index = 0; |
---|
1421 | |
---|
1422 | for ( |
---|
1423 | ctx->pcs[ 0 ] = Action2_Pre_A_X; |
---|
1424 | ctx->pcs[ 0 ] < Action2_Pre_A_NA; |
---|
1425 | ++ctx->pcs[ 0 ] |
---|
1426 | ) { |
---|
1427 | if ( Action2_TransitionInfo[ index ].Pre_A_NA ) { |
---|
1428 | ctx->pcs[ 0 ] = Action2_Pre_A_NA; |
---|
1429 | index += ( Action2_Pre_A_NA - 1 ) |
---|
1430 | * Action2_Pre_B_NA; |
---|
1431 | } |
---|
1432 | |
---|
1433 | for ( |
---|
1434 | ctx->pcs[ 1 ] = Action2_Pre_B_X; |
---|
1435 | ctx->pcs[ 1 ] < Action2_Pre_B_NA; |
---|
1436 | ++ctx->pcs[ 1 ] |
---|
1437 | ) { |
---|
1438 | if ( Action2_TransitionInfo[ index ].Pre_B_NA ) { |
---|
1439 | ctx->pcs[ 1 ] = Action2_Pre_B_NA; |
---|
1440 | index += ( Action2_Pre_B_NA - 1 ); |
---|
1441 | } |
---|
1442 | |
---|
1443 | if ( Action2_TransitionInfo[ index ].Skip ) { |
---|
1444 | ++index; |
---|
1445 | continue; |
---|
1446 | } |
---|
1447 | |
---|
1448 | Action2_Pre_A_Prepare( ctx, ctx->pcs[ 0 ] ); |
---|
1449 | Action2_Pre_B_Prepare( ctx, ctx->pcs[ 1 ] ); |
---|
1450 | /* Action */ |
---|
1451 | Action2_Post_A_Check( |
---|
1452 | ctx, |
---|
1453 | Action2_TransitionMap[ index ][ 0 ] |
---|
1454 | ); |
---|
1455 | Action2_Post_B_Check( |
---|
1456 | ctx, |
---|
1457 | Action2_TransitionMap[ index ][ 1 ] |
---|
1458 | ); |
---|
1459 | ++index; |
---|
1460 | } |
---|
1461 | } |
---|
1462 | |
---|
1463 | T_pop_fixture(); |
---|
1464 | } |
---|
1465 | |
---|
1466 | /** @} */ |
---|
1467 | """ |
---|
1468 | assert content == src.read() |
---|