source: rtems-central/rtemsspec/tests/test_validation.py @ e49c759

Last change on this file since e49c759 was e49c759, checked in by Sebastian Huber <sebastian.huber@…>, on 07/15/20 at 08:04:25

Rename "rtemsqual" in "rtemsspec"

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