1 | /* |
---|
2 | * Copyright (c) 2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems.h> |
---|
20 | #include <rtems/score/percpu.h> |
---|
21 | #include <rtems/score/smpimpl.h> |
---|
22 | |
---|
23 | #include <assert.h> |
---|
24 | #include <stdlib.h> |
---|
25 | |
---|
26 | #define MAX_CPUS 32 |
---|
27 | |
---|
28 | static uint32_t main_cpu; |
---|
29 | |
---|
30 | static void Init(rtems_task_argument arg) |
---|
31 | { |
---|
32 | assert(0); |
---|
33 | } |
---|
34 | |
---|
35 | static void end_of_test(void) |
---|
36 | { |
---|
37 | printk( "*** END OF TEST SMPFATAL 2 ***\n" ); |
---|
38 | } |
---|
39 | |
---|
40 | static void fatal_extension( |
---|
41 | rtems_fatal_source source, |
---|
42 | bool is_internal, |
---|
43 | rtems_fatal_code code |
---|
44 | ) |
---|
45 | { |
---|
46 | if ( |
---|
47 | source == RTEMS_FATAL_SOURCE_APPLICATION |
---|
48 | || source == RTEMS_FATAL_SOURCE_SMP |
---|
49 | ) { |
---|
50 | uint32_t self = rtems_smp_get_current_processor(); |
---|
51 | |
---|
52 | assert(!is_internal); |
---|
53 | |
---|
54 | if (self == main_cpu) { |
---|
55 | uint32_t cpu; |
---|
56 | |
---|
57 | assert(source == RTEMS_FATAL_SOURCE_APPLICATION); |
---|
58 | assert(code == 0xdeadbeef); |
---|
59 | |
---|
60 | for (cpu = 0; cpu < MAX_CPUS; ++cpu) { |
---|
61 | const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu ); |
---|
62 | Per_CPU_State state = per_cpu->state; |
---|
63 | |
---|
64 | assert(state == PER_CPU_STATE_SHUTDOWN); |
---|
65 | } |
---|
66 | |
---|
67 | end_of_test(); |
---|
68 | } else { |
---|
69 | assert(source == RTEMS_FATAL_SOURCE_SMP); |
---|
70 | assert(code == SMP_FATAL_SHUTDOWN); |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | static rtems_status_code test_driver_init( |
---|
76 | rtems_device_major_number major, |
---|
77 | rtems_device_minor_number minor, |
---|
78 | void *arg |
---|
79 | ) |
---|
80 | { |
---|
81 | uint32_t self = rtems_smp_get_current_processor(); |
---|
82 | uint32_t cpu_count = rtems_smp_get_processor_count(); |
---|
83 | uint32_t cpu; |
---|
84 | |
---|
85 | printk("\n\n*** TEST SMPFATAL 2 ***\n"); |
---|
86 | |
---|
87 | assert(rtems_configuration_get_maximum_processors() == MAX_CPUS); |
---|
88 | |
---|
89 | main_cpu = self; |
---|
90 | |
---|
91 | for (cpu = 0; cpu < MAX_CPUS; ++cpu) { |
---|
92 | const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu ); |
---|
93 | Per_CPU_State state = per_cpu->state; |
---|
94 | |
---|
95 | if (cpu == self) { |
---|
96 | assert(state == PER_CPU_STATE_INITIAL); |
---|
97 | } else if (cpu < cpu_count) { |
---|
98 | assert( |
---|
99 | state == PER_CPU_STATE_INITIAL |
---|
100 | || state == PER_CPU_STATE_READY_TO_START_MULTITASKING |
---|
101 | ); |
---|
102 | } else { |
---|
103 | assert(state == PER_CPU_STATE_INITIAL); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | if (cpu_count > 1) { |
---|
108 | rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 0xdeadbeef); |
---|
109 | } else { |
---|
110 | end_of_test(); |
---|
111 | exit(0); |
---|
112 | } |
---|
113 | |
---|
114 | return RTEMS_SUCCESSFUL; |
---|
115 | } |
---|
116 | |
---|
117 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
118 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
119 | |
---|
120 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS \ |
---|
121 | { .initialization_entry = test_driver_init } |
---|
122 | |
---|
123 | #define CONFIGURE_INITIAL_EXTENSIONS { .fatal = fatal_extension } |
---|
124 | |
---|
125 | #define CONFIGURE_SMP_APPLICATION |
---|
126 | |
---|
127 | #define CONFIGURE_SMP_MAXIMUM_PROCESSORS MAX_CPUS |
---|
128 | |
---|
129 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
130 | |
---|
131 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
132 | |
---|
133 | #define CONFIGURE_INIT |
---|
134 | |
---|
135 | #include <rtems/confdefs.h> |
---|