summaryrefslogtreecommitdiffstats
path: root/spec/score/interr/val/terminate.yml
blob: 7bd2c92fe897dd7d65cbd299ae8de8f4ffdaade3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021 embedded brains GmbH & Co. KG
enabled-by: true
links: []
test-actions:
- action-brief: |
    Create five dynamic extensions.  Call the system termination procedure.
    Delete three dynamic extension during the fatal extension invocation.
    Delete the two remaining dynamic extensions.
  action-code: |
    rtems_status_code      sc;
    rtems_extensions_table table;
    bool                   shutdown_ok;

    #if defined(RTEMS_SMP)
    shutdown_ok =
      ( _Per_CPU_Get_state( _Per_CPU_Get_snapshot() ) == PER_CPU_STATE_UP );
    #else
    shutdown_ok = true;
    #endif

    memset( &table, 0, sizeof( table ) );

    table.fatal = FatalExtension2;
    sc = rtems_extension_create(
      rtems_build_name( ' ', ' ', ' ', '2' ),
      &table,
      &extension_ids[ 2 ]
    );
    T_step_rsc_success( ${.:/step}, sc );

    table.fatal = FatalExtension3;
    sc = rtems_extension_create(
      rtems_build_name( ' ', ' ', ' ', '3' ),
      &table,
      &extension_ids[ 3 ]
    );
    T_step_rsc_success( ${.:/step}, sc );

    table.fatal = FatalExtension4;
    sc = rtems_extension_create(
      rtems_build_name( ' ', ' ', ' ', '4' ),
      &table,
      &extension_ids[ 4 ]
    );
    T_step_rsc_success( ${.:/step}, sc );

    table.fatal = FatalExtension5;
    sc = rtems_extension_create(
      rtems_build_name( ' ', ' ', ' ', '5' ),
      &table,
      &extension_ids[ 5 ]
    );
    T_step_rsc_success( ${.:/step}, sc );

    table.fatal = FatalExtension6;
    sc = rtems_extension_create(
      rtems_build_name( ' ', ' ', ' ', '6' ),
      &table,
      &extension_ids[ 6 ]
    );
    T_step_rsc_success( ${.:/step}, sc );

    test_case_active = true;

    if ( setjmp( before_terminate ) == 0 ) {
      _Terminate( RTEMS_FATAL_SOURCE_APPLICATION, 123456 );
    }

    test_case_active = false;
  checks:
  - brief: |
      Where the system was built with SMP support enabled, check that a
      shutdown request was issued.
    code: |
      #if defined(RTEMS_SMP)
      shutdown_ok = ( shutdown_ok && _ISR_Get_level() != 0 &&
        _Per_CPU_Get_state( _Per_CPU_Get() ) == PER_CPU_STATE_SHUTDOWN );
      _ISR_Set_level( 0 );
      #endif
      T_step_true( ${.:/step}, shutdown_ok );
    links:
    - role: validation
      uid: ../req/terminate-shutdown
  - brief: |
      Delete the dynamic extension sets.
    code: |
      sc = rtems_extension_delete( extension_ids[ 2 ] );
      T_step_rsc_success( ${.:/step}, sc );

      sc = rtems_extension_delete( extension_ids[ 6 ] );
      T_step_rsc_success( ${.:/step}, sc );
    links: []
  - brief: |
      Check that the fatal extensions were invoked with the expected source.
    code: |
      T_step_eq_int(
        ${.:/step},
        info[ 0 ].source,
        RTEMS_FATAL_SOURCE_APPLICATION
      );
      T_step_eq_int(
        ${.:/step},
        info[ 1 ].source,
        RTEMS_FATAL_SOURCE_APPLICATION
      );
      T_step_eq_int(
        ${.:/step},
        info[ 2 ].source,
        RTEMS_FATAL_SOURCE_APPLICATION
      );
      T_step_eq_int(
        ${.:/step},
        info[ 4 ].source,
        RTEMS_FATAL_SOURCE_APPLICATION
      );
      T_step_eq_int(
        ${.:/step},
        info[ 5 ].source,
        RTEMS_FATAL_SOURCE_APPLICATION
      );
      T_step_eq_int(
        ${.:/step},
        info[ 6 ].source,
        RTEMS_FATAL_SOURCE_APPLICATION
      );
    links:
    - role: validation
      uid: ../req/terminate-userext
  - brief: |
      Check that the fatal extensions were invoked with the expected always set
      to false argument.
    code: |
      T_step_false( ${.:/step}, info[ 0 ].always_set_to_false );
      T_step_false( ${.:/step}, info[ 1 ].always_set_to_false );
      T_step_false( ${.:/step}, info[ 2 ].always_set_to_false );
      T_step_false( ${.:/step}, info[ 4 ].always_set_to_false );
      T_step_false( ${.:/step}, info[ 5 ].always_set_to_false );
      T_step_false( ${.:/step}, info[ 6 ].always_set_to_false );
    links:
    - role: validation
      uid: ../req/terminate-userext
  - brief: |
      Check that the fatal extensions were invoked with the expected code.
    code: |
      T_step_eq_ulong( ${.:/step}, info[ 0 ].code, 123456 );
      T_step_eq_ulong( ${.:/step}, info[ 1 ].code, 123456 );
      T_step_eq_ulong( ${.:/step}, info[ 2 ].code, 123456 );
      T_step_eq_ulong( ${.:/step}, info[ 4 ].code, 123456 );
      T_step_eq_ulong( ${.:/step}, info[ 5 ].code, 123456 );
      T_step_eq_ulong( ${.:/step}, info[ 6 ].code, 123456 );
    links:
    - role: validation
      uid: ../req/terminate-userext
  - brief: |
      Check that the fatal extensions were invoked in forward order.
    code: |
      T_step_eq_uint( ${.:/step}, info[ 0 ].counter, 1 );
      T_step_eq_uint( ${.:/step}, info[ 1 ].counter, 2 );
      T_step_eq_uint( ${.:/step}, info[ 2 ].counter, 3 );
      T_step_eq_uint( ${.:/step}, info[ 4 ].counter, 4 );
      T_step_eq_uint( ${.:/step}, info[ 5 ].counter, 5 );
      T_step_eq_uint( ${.:/step}, info[ 6 ].counter, 6 );
    links:
    - role: validation
      uid: /rtems/userext/req/fatal-order
  - brief: |
      Check that the fatal extension in the deleted extension set was not
      invoked.
    code: |
      T_step_eq_int( ${.:/step}, info[ 3 ].source, 0 );
      T_step_false( ${.:/step}, info[ 3 ].always_set_to_false );
      T_step_eq_ulong( ${.:/step}, info[ 3 ].code, 0 );
      T_step_eq_uint( ${.:/step}, info[ 3 ].counter, 0 );
    links:
    - role: validation
      uid: /rtems/userext/req/fatal-iterate-remove
  - brief: |
      Check that the system state is terminated.
    code: |
      T_step_eq_int( ${.:/step}, _System_state_Get(), SYSTEM_STATE_TERMINATED );
    links:
    - role: validation
      uid: ../req/terminate-state
  - brief: |
      Check that the system was halted with the expected fatal source.
    code: |
      T_step_eq_int( ${.:/step}, halt_source, RTEMS_FATAL_SOURCE_APPLICATION );
    links:
    - role: validation
      uid: ../req/terminate-halt
    - role: validation
      uid: ../req/terminate-shutdown-halt
  - brief: |
      Check that the system was halted with the expected fatal code.
    code: |
      T_step_eq_ulong( ${.:/step}, halt_code, 123456 );
    links:
    - role: validation
      uid: ../req/terminate-halt
    - role: validation
      uid: ../req/terminate-shutdown-halt
  - brief: |
      Check that the system was finally halted.
    code: |
      T_step_eq_uint( ${.:/step}, counter, 7 );
    links:
    - role: validation
      uid: ../req/terminate-halt
    - role: validation
      uid: ../req/terminate-shutdown-halt
  links:
  - role: validation
    uid: ../req/terminate
test-brief: |
  Tests system termination procedure.
test-context: []
test-context-support: null
test-description: null
test-header: null
test-includes:
- bsp.h
- rtems/bspIo.h
- rtems/test-info.h
- rtems/score/atomic.h
- rtems/score/io.h
- rtems/score/percpu.h
- rtems/score/sysstate.h
- setjmp.h
- string.h
test-local-includes:
- tc-userext.h
test-setup: null
test-stop: null
test-support: |
  typedef struct {
    unsigned int       counter;
    rtems_fatal_source source;
    bool               always_set_to_false;
    rtems_fatal_code   code;
  } FatalInfo;

  static Atomic_Uint counter;

  static FatalInfo info[ 7 ];

  static bool test_case_active;

  static const rtems_extensions_table bsp = BSP_INITIAL_EXTENSION;

  static jmp_buf before_terminate;

  static unsigned int halt_counter;

  static rtems_fatal_source halt_source;

  static rtems_fatal_code halt_code;

  static rtems_id extension_ids[ 7 ];

  static unsigned int GetCounter( void )
  {
    return _Atomic_Fetch_add_uint( &counter, 1, ATOMIC_ORDER_RELAXED ) + 1;
  }

  void __real__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code );

  void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code );

  void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code )
  {
    if ( test_case_active ) {
      halt_counter = GetCounter();
      halt_source = source;
      halt_code = code;
      longjmp( before_terminate, 1 );
    } else {
  #if defined(RTEMS_GCOV_COVERAGE)
      rtems_test_gcov_dump_info();
  #endif
      __real__CPU_Fatal_halt( source, code );
    }
  }

  static void FatalExtension(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code,
    size_t             index
  )
  {
    if ( test_case_active ) {
      info[ index ].counter = GetCounter();
      info[ index ].source = source;
      info[ index ].always_set_to_false = always_set_to_false;
      info[ index ].code = code;
    } else {
      ( *bsp.fatal )( source, always_set_to_false, code );
    }
  }

  void FatalExtension0(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    FatalExtension( source, always_set_to_false, code, 0 );
  }

  void FatalExtension1(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    FatalExtension( source, always_set_to_false, code, 1 );
  }

  static void FatalExtension2(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    rtems_status_code sc;

    FatalExtension( source, always_set_to_false, code, 2 );

    sc = rtems_extension_delete( extension_ids[ 3 ] );
    T_quiet_rsc_success( sc );
  }

  static void FatalExtension3(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    FatalExtension( source, always_set_to_false, code, 3 );
  }

  static void FatalExtension4(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    FatalExtension( source, always_set_to_false, code, 4 );
  }

  static void FatalExtension5(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    rtems_status_code sc;

    FatalExtension( source, always_set_to_false, code, 5 );

    sc = rtems_extension_delete( extension_ids[ 5 ] );
    T_quiet_rsc_success( sc );
  }

  static void FatalExtension6(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    rtems_status_code sc;

    FatalExtension( source, always_set_to_false, code, 6 );

    sc = rtems_extension_delete( extension_ids[ 4 ] );
    T_quiet_rsc_success( sc );
  }
test-target: testsuites/validation/tc-terminate.c
test-teardown: null
type: test-case