File indexing completed on 2025-05-11 08:24:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include "tmacros.h"
0033
0034 #include <rtems.h>
0035 #include <rtems/score/percpu.h>
0036 #include <rtems/score/smpimpl.h>
0037 #include <rtems/score/smpbarrier.h>
0038
0039 #include <assert.h>
0040 #include <stdlib.h>
0041
0042 const char rtems_test_name[] = "SMPFATAL 2";
0043
0044 #define MAX_CPUS 32
0045
0046 static uint32_t main_cpu;
0047
0048 static SMP_barrier_Control barrier = SMP_BARRIER_CONTROL_INITIALIZER;
0049
0050 static void Init(rtems_task_argument arg)
0051 {
0052 assert(0);
0053 }
0054
0055 static void fatal_extension(
0056 rtems_fatal_source source,
0057 bool always_set_to_false,
0058 rtems_fatal_code code
0059 )
0060 {
0061 SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
0062 uint32_t self = rtems_scheduler_get_processor();
0063 uint32_t cpu_count = rtems_scheduler_get_processor_maximum();
0064
0065 assert(!always_set_to_false);
0066
0067 if ( source == RTEMS_FATAL_SOURCE_APPLICATION ) {
0068 uint32_t cpu;
0069
0070 assert(self == main_cpu);
0071 assert(code == 0xdeadbeef);
0072
0073 _SMP_Request_shutdown();
0074 _SMP_barrier_Wait(&barrier, &barrier_state, cpu_count);
0075
0076 for (cpu = 0; cpu < cpu_count; ++cpu) {
0077 const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
0078 Per_CPU_State state = _Per_CPU_Get_state(per_cpu);
0079
0080 assert(state == PER_CPU_STATE_SHUTDOWN);
0081 }
0082
0083 for (cpu = cpu_count; cpu < MAX_CPUS; ++cpu) {
0084 const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
0085 Per_CPU_State state = _Per_CPU_Get_state(per_cpu);
0086
0087 assert(state == PER_CPU_STATE_INITIAL);
0088 }
0089
0090 TEST_END();
0091 } else if ( source == RTEMS_FATAL_SOURCE_SMP ) {
0092 assert(self != main_cpu);
0093 assert(code == SMP_FATAL_SHUTDOWN_RESPONSE);
0094 _SMP_barrier_Wait(&barrier, &barrier_state, cpu_count);
0095 _SMP_barrier_Wait(&barrier, &barrier_state, cpu_count);
0096 }
0097 }
0098
0099 static rtems_status_code test_driver_init(
0100 rtems_device_major_number major,
0101 rtems_device_minor_number minor,
0102 void *arg
0103 )
0104 {
0105 uint32_t self = rtems_scheduler_get_processor();
0106 uint32_t cpu_count = rtems_scheduler_get_processor_maximum();
0107 uint32_t cpu;
0108
0109 TEST_BEGIN();
0110
0111 assert(rtems_configuration_get_maximum_processors() == MAX_CPUS);
0112
0113 main_cpu = self;
0114
0115 for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
0116 const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
0117 Per_CPU_State state = _Per_CPU_Get_state(per_cpu);
0118
0119 if (cpu == self) {
0120 assert(state == PER_CPU_STATE_INITIAL);
0121 } else if (cpu < cpu_count) {
0122 assert(
0123 state == PER_CPU_STATE_INITIAL
0124 || state == PER_CPU_STATE_READY_TO_START_MULTITASKING
0125 );
0126 } else {
0127 assert(state == PER_CPU_STATE_INITIAL);
0128 }
0129 }
0130
0131 if (cpu_count > 1) {
0132 rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 0xdeadbeef);
0133 } else {
0134 TEST_END();
0135 exit(0);
0136 }
0137
0138 return RTEMS_SUCCESSFUL;
0139 }
0140
0141 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0142 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0143
0144 #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
0145 { .initialization_entry = test_driver_init }
0146
0147 #define CONFIGURE_INITIAL_EXTENSIONS \
0148 { .fatal = fatal_extension }, \
0149 RTEMS_TEST_INITIAL_EXTENSION
0150
0151 #define CONFIGURE_MAXIMUM_PROCESSORS MAX_CPUS
0152
0153 #define CONFIGURE_MAXIMUM_TASKS 1
0154
0155 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0156
0157 #define CONFIGURE_INIT
0158
0159 #include <rtems/confdefs.h>