source: rtems-central/spec/score/interr/val/terminate.yml @ 96247b3

Last change on this file since 96247b3 was 96247b3, checked in by Sebastian Huber <sebastian.huber@…>, on 01/14/22 at 07:35:49

spec: Fix _Terminate() validation

Enable interrupts before the rtems_extension_delete() directives are
called.

  • Property mode set to 100644
File size: 10.2 KB
Line 
1SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
2copyrights:
3- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
4enabled-by: true
5links: []
6test-actions:
7- action-brief: |
8    Create five dynamic extensions.  Call the system termination procedure.
9    Delete three dynamic extension during the fatal extension invocation.
10    Delete the two remaining dynamic extensions.
11  action-code: |
12    rtems_status_code      sc;
13    rtems_extensions_table table;
14    bool                   shutdown_ok;
15
16    #if defined(RTEMS_SMP)
17    shutdown_ok =
18      ( _Per_CPU_Get_state( _Per_CPU_Get_snapshot() ) == PER_CPU_STATE_UP );
19    #else
20    shutdown_ok = true;
21    #endif
22
23    memset( &table, 0, sizeof( table ) );
24
25    table.fatal = FatalExtension2;
26    sc = rtems_extension_create(
27      rtems_build_name( ' ', ' ', ' ', '2' ),
28      &table,
29      &extension_ids[ 2 ]
30    );
31    T_step_rsc_success( ${step}, sc );
32
33    table.fatal = FatalExtension3;
34    sc = rtems_extension_create(
35      rtems_build_name( ' ', ' ', ' ', '3' ),
36      &table,
37      &extension_ids[ 3 ]
38    );
39    T_step_rsc_success( ${step}, sc );
40
41    table.fatal = FatalExtension4;
42    sc = rtems_extension_create(
43      rtems_build_name( ' ', ' ', ' ', '4' ),
44      &table,
45      &extension_ids[ 4 ]
46    );
47    T_step_rsc_success( ${step}, sc );
48
49    table.fatal = FatalExtension5;
50    sc = rtems_extension_create(
51      rtems_build_name( ' ', ' ', ' ', '5' ),
52      &table,
53      &extension_ids[ 5 ]
54    );
55    T_step_rsc_success( ${step}, sc );
56
57    table.fatal = FatalExtension6;
58    sc = rtems_extension_create(
59      rtems_build_name( ' ', ' ', ' ', '6' ),
60      &table,
61      &extension_ids[ 6 ]
62    );
63    T_step_rsc_success( ${step}, sc );
64
65    test_case_active = true;
66
67    if ( setjmp( before_terminate ) == 0 ) {
68      _Terminate( RTEMS_FATAL_SOURCE_APPLICATION, 123456 );
69    }
70
71    test_case_active = false;
72  checks:
73  - brief: |
74      Where the system was built with SMP support enabled, check that a
75      shutdown request was issued.
76    code: |
77      #if defined(RTEMS_SMP)
78      shutdown_ok = ( shutdown_ok && _ISR_Get_level() != 0 &&
79        _Per_CPU_Get_state( _Per_CPU_Get() ) == PER_CPU_STATE_SHUTDOWN );
80      _ISR_Set_level( 0 );
81      #endif
82      T_step_true( ${step}, shutdown_ok );
83    links:
84    - role: validation
85      uid: ../req/terminate-shutdown
86  - brief: |
87      Delete the dynamic extension sets.
88    code: |
89      sc = rtems_extension_delete( extension_ids[ 2 ] );
90      T_step_rsc_success( ${step}, sc );
91
92      sc = rtems_extension_delete( extension_ids[ 6 ] );
93      T_step_rsc_success( ${step}, sc );
94    links: []
95  - brief: |
96      Check that the fatal extensions were invoked with the expected source.
97    code: |
98      T_step_eq_int(
99        ${step},
100        info[ 0 ].source,
101        RTEMS_FATAL_SOURCE_APPLICATION
102      );
103      T_step_eq_int(
104        ${step},
105        info[ 1 ].source,
106        RTEMS_FATAL_SOURCE_APPLICATION
107      );
108      T_step_eq_int(
109        ${step},
110        info[ 2 ].source,
111        RTEMS_FATAL_SOURCE_APPLICATION
112      );
113      T_step_eq_int(
114        ${step},
115        info[ 4 ].source,
116        RTEMS_FATAL_SOURCE_APPLICATION
117      );
118      T_step_eq_int(
119        ${step},
120        info[ 5 ].source,
121        RTEMS_FATAL_SOURCE_APPLICATION
122      );
123      T_step_eq_int(
124        ${step},
125        info[ 6 ].source,
126        RTEMS_FATAL_SOURCE_APPLICATION
127      );
128    links:
129    - role: validation
130      uid: ../req/terminate-userext
131  - brief: |
132      Check that the fatal extensions were invoked with the expected always set
133      to false argument.
134    code: |
135      T_step_false( ${step}, info[ 0 ].always_set_to_false );
136      T_step_false( ${step}, info[ 1 ].always_set_to_false );
137      T_step_false( ${step}, info[ 2 ].always_set_to_false );
138      T_step_false( ${step}, info[ 4 ].always_set_to_false );
139      T_step_false( ${step}, info[ 5 ].always_set_to_false );
140      T_step_false( ${step}, info[ 6 ].always_set_to_false );
141    links:
142    - role: validation
143      uid: ../req/terminate-userext
144  - brief: |
145      Check that the fatal extensions were invoked with the expected code.
146    code: |
147      T_step_eq_ulong( ${step}, info[ 0 ].code, 123456 );
148      T_step_eq_ulong( ${step}, info[ 1 ].code, 123456 );
149      T_step_eq_ulong( ${step}, info[ 2 ].code, 123456 );
150      T_step_eq_ulong( ${step}, info[ 4 ].code, 123456 );
151      T_step_eq_ulong( ${step}, info[ 5 ].code, 123456 );
152      T_step_eq_ulong( ${step}, info[ 6 ].code, 123456 );
153    links:
154    - role: validation
155      uid: ../req/terminate-userext
156  - brief: |
157      Check that the fatal extensions were invoked in forward order.
158    code: |
159      T_step_eq_uint( ${step}, info[ 0 ].counter, 1 );
160      T_step_eq_uint( ${step}, info[ 1 ].counter, 2 );
161      T_step_eq_uint( ${step}, info[ 2 ].counter, 3 );
162      T_step_eq_uint( ${step}, info[ 4 ].counter, 4 );
163      T_step_eq_uint( ${step}, info[ 5 ].counter, 5 );
164      T_step_eq_uint( ${step}, info[ 6 ].counter, 6 );
165    links:
166    - role: validation
167      uid: /rtems/userext/req/fatal-order
168  - brief: |
169      Check that the fatal extension in the deleted extension set was not
170      invoked.
171    code: |
172      T_step_eq_int( ${step}, info[ 3 ].source, 0 );
173      T_step_false( ${step}, info[ 3 ].always_set_to_false );
174      T_step_eq_ulong( ${step}, info[ 3 ].code, 0 );
175      T_step_eq_uint( ${step}, info[ 3 ].counter, 0 );
176    links:
177    - role: validation
178      uid: /rtems/userext/req/fatal-iterate-remove
179  - brief: |
180      Check that the system state is terminated.
181    code: |
182      T_step_eq_int( ${step}, _System_state_Get(), SYSTEM_STATE_TERMINATED );
183    links:
184    - role: validation
185      uid: ../req/terminate-state
186  - brief: |
187      Check that the system was halted with the expected fatal source.
188    code: |
189      T_step_eq_int( ${step}, halt_source, RTEMS_FATAL_SOURCE_APPLICATION );
190    links:
191    - role: validation
192      uid: ../req/terminate-halt
193    - role: validation
194      uid: ../req/terminate-shutdown-halt
195  - brief: |
196      Check that the system was halted with the expected fatal code.
197    code: |
198      T_step_eq_ulong( ${step}, halt_code, 123456 );
199    links:
200    - role: validation
201      uid: ../req/terminate-halt
202    - role: validation
203      uid: ../req/terminate-shutdown-halt
204  - brief: |
205      Check that the system was finally halted.
206    code: |
207      T_step_eq_uint( ${step}, counter, 7 );
208    links:
209    - role: validation
210      uid: ../req/terminate-halt
211    - role: validation
212      uid: ../req/terminate-shutdown-halt
213  links:
214  - role: validation
215    uid: ../req/terminate
216test-brief: |
217  Tests system termination procedure.
218test-context: []
219test-context-support: null
220test-description: null
221test-header: null
222test-includes:
223- bsp.h
224- rtems/bspIo.h
225- rtems/score/atomic.h
226- rtems/score/io.h
227- rtems/score/percpu.h
228- rtems/score/sysstate.h
229- setjmp.h
230- string.h
231test-local-includes:
232- tc-userext.h
233test-setup: null
234test-stop: null
235test-support: |
236  typedef struct {
237    unsigned int       counter;
238    rtems_fatal_source source;
239    bool               always_set_to_false;
240    rtems_fatal_code   code;
241  } FatalInfo;
242
243  static Atomic_Uint counter;
244
245  static FatalInfo info[ 7 ];
246
247  static bool test_case_active;
248
249  static const rtems_extensions_table bsp = BSP_INITIAL_EXTENSION;
250
251  static jmp_buf before_terminate;
252
253  static unsigned int halt_counter;
254
255  static rtems_fatal_source halt_source;
256
257  static rtems_fatal_code halt_code;
258
259  static rtems_id extension_ids[ 7 ];
260
261  static unsigned int GetCounter( void )
262  {
263    return _Atomic_Fetch_add_uint( &counter, 1, ATOMIC_ORDER_RELAXED ) + 1;
264  }
265
266  void __real__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code );
267
268  void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code );
269
270  void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code )
271  {
272    if ( test_case_active ) {
273      halt_counter = GetCounter();
274      halt_source = source;
275      halt_code = code;
276      longjmp( before_terminate, 1 );
277    } else {
278  #if defined(RTEMS_COVERAGE)
279      _IO_Dump_gcov_info( rtems_put_char, NULL );
280  #endif
281      __real__CPU_Fatal_halt( source, code );
282    }
283  }
284
285  static void FatalExtension(
286    rtems_fatal_source source,
287    bool               always_set_to_false,
288    rtems_fatal_code   code,
289    size_t             index
290  )
291  {
292    if ( test_case_active ) {
293      info[ index ].counter = GetCounter();
294      info[ index ].source = source;
295      info[ index ].always_set_to_false = always_set_to_false;
296      info[ index ].code = code;
297    } else {
298      ( *bsp.fatal )( source, always_set_to_false, code );
299    }
300  }
301
302  void FatalExtension0(
303    rtems_fatal_source source,
304    bool               always_set_to_false,
305    rtems_fatal_code   code
306  )
307  {
308    FatalExtension( source, always_set_to_false, code, 0 );
309  }
310
311  void FatalExtension1(
312    rtems_fatal_source source,
313    bool               always_set_to_false,
314    rtems_fatal_code   code
315  )
316  {
317    FatalExtension( source, always_set_to_false, code, 1 );
318  }
319
320  static void FatalExtension2(
321    rtems_fatal_source source,
322    bool               always_set_to_false,
323    rtems_fatal_code   code
324  )
325  {
326    rtems_status_code sc;
327
328    FatalExtension( source, always_set_to_false, code, 2 );
329
330    sc = rtems_extension_delete( extension_ids[ 3 ] );
331    T_quiet_rsc_success( sc );
332  }
333
334  static void FatalExtension3(
335    rtems_fatal_source source,
336    bool               always_set_to_false,
337    rtems_fatal_code   code
338  )
339  {
340    FatalExtension( source, always_set_to_false, code, 3 );
341  }
342
343  static void FatalExtension4(
344    rtems_fatal_source source,
345    bool               always_set_to_false,
346    rtems_fatal_code   code
347  )
348  {
349    FatalExtension( source, always_set_to_false, code, 4 );
350  }
351
352  static void FatalExtension5(
353    rtems_fatal_source source,
354    bool               always_set_to_false,
355    rtems_fatal_code   code
356  )
357  {
358    rtems_status_code sc;
359
360    FatalExtension( source, always_set_to_false, code, 5 );
361
362    sc = rtems_extension_delete( extension_ids[ 5 ] );
363    T_quiet_rsc_success( sc );
364  }
365
366  static void FatalExtension6(
367    rtems_fatal_source source,
368    bool               always_set_to_false,
369    rtems_fatal_code   code
370  )
371  {
372    rtems_status_code sc;
373
374    FatalExtension( source, always_set_to_false, code, 6 );
375
376    sc = rtems_extension_delete( extension_ids[ 4 ] );
377    T_quiet_rsc_success( sc );
378  }
379test-target: testsuites/validation/tc-terminate.c
380test-teardown: null
381type: test-case
Note: See TracBrowser for help on using the repository browser.