summaryrefslogtreecommitdiffstats
path: root/spec/bsp/sparc/leon3/val/fatal-shutdown.yml
blob: 17ae35a8b1d06a10de93a699c0d626321a4aea6a (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
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
copyrights:
- Copyright (C) 2021, 2022 embedded brains GmbH (http://www.embedded-brains.de)
enabled-by:
  and:
  - RTEMS_SMP
  - bsps/sparc/leon3
links: []
test-actions:
- action-brief: |
    Check the effects of the leon3 BSP family shutdown procedure.
  action-code: |
    irqamp  *regs;
    uint32_t counter;

    regs = LEON3_IrqCtrl_Regs;
  checks:
  - brief: |
      Check that the second processor was not powered down during system
      initialization.
    code: |
      T_step_eq_u32( ${.:/step}, mpstat_during_sysinit & 0x2, 0 );
    links: []
  - brief: |
      Wait until the second processor is powered down.
    code: |
      while ( ( grlib_load_32( &regs->mpstat ) & 0x2 ) != 0x2U ) {
        /* Wait */
      }
    links: []
  - brief: |
      Check that the RTEMS_FATAL_SOURCE_SMP with SMP_FATAL_SHUTDOWN_RESPONSE
      fatal error occurred exactly once.
    code: |
      counter = Add( &shutdown_response_counter, 0 );
      T_step_eq_uint( ${.:/step}, counter, 1 );
    links: []
  - brief: |
      Check that the RTEMS_FATAL_SOURCE_SMP with SMP_FATAL_SHUTDOWN_RESPONSE
      fatal error occurred on the second processor.
    code: |
      T_step_eq_u32( ${.:/step}, shutdown_response_cpu_index, 1 );
    links: []
  - brief: |
      Check that no dynamic fatal error extension was invoked.  This shows that
      the leon3 BSP family shutdown procedure called the wrapped
      _CPU_Fatal_halt() function of the test suite.
    code: |
      T_step_rsc_success( ${.:/step}, status );
      counter = Add( &dynamic_fatal_extension_counter, 0 );
      T_step_eq_u32( ${.:/step}, dynamic_fatal_extension_counter, 0 );
    links:
    - role: validation
      uid: ../req/fatal-shutdown-halt
  links:
  - role: validation
    uid: ../req/fatal-shutdown-request
  - role: validation
    uid: ../req/fatal-shutdown-response
test-brief: |
  Tests the leon3 BSP family shutdown procedure.
test-context: []
test-context-support: null
test-description: null
test-header: null
test-includes:
- rtems/sysinit.h
- rtems/score/smpimpl.h
- bsp/leon3.h
test-local-includes:
- tx-support.h
test-setup: null
test-stop: null
test-support: |
  static uint32_t mpstat_during_sysinit;

  static Atomic_Uint shutdown_response_counter;

  static uint32_t shutdown_response_cpu_index = UINT32_MAX;

  static Atomic_Uint dynamic_fatal_extension_counter;

  static rtems_status_code status;

  static unsigned int Add( Atomic_Uint *a, unsigned int b )
  {
    return _Atomic_Fetch_add_uint( a, b, ATOMIC_ORDER_RELAXED );
  }

  static void ShutdownFatalHandler(
    rtems_fatal_source source,
    rtems_fatal_code   code,
    void              *arg
  )
  {
    T_null( arg );

    if (
      source == RTEMS_FATAL_SOURCE_SMP &&
      code == SMP_FATAL_SHUTDOWN_RESPONSE
    ) {
      (void) Add( &shutdown_response_counter, 1 );
      shutdown_response_cpu_index = rtems_scheduler_get_processor();
    }
  }

  static void DynamicFatalHandler(
    rtems_fatal_source source,
    bool               always_set_to_false,
    rtems_fatal_code   code
  )
  {
    (void) source;
    (void) code;
    (void) always_set_to_false;
    (void) Add( &dynamic_fatal_extension_counter, 1 );
  }

  static void InitTestCase( void )
  {
    rtems_extensions_table table = { .fatal = DynamicFatalHandler };
    irqamp                *regs;
    rtems_id               id;

    regs = LEON3_IrqCtrl_Regs;
    mpstat_during_sysinit = grlib_load_32( &regs->mpstat );
    SetFatalHandler( ShutdownFatalHandler, NULL );
    status = rtems_extension_create( OBJECT_NAME, &table, &id );
  }

  RTEMS_SYSINIT_ITEM(
    InitTestCase,
    RTEMS_SYSINIT_DEVICE_DRIVERS,
    RTEMS_SYSINIT_ORDER_MIDDLE
  );
test-target: testsuites/validation/tc-fatal-bsp-sparc-leon3-shutdown.c
test-teardown: null
type: test-case