source: rtems/testsuites/smptests/smpfatal02/init.c @ 092b8c5

4.115
Last change on this file since 092b8c5 was 092b8c5, checked in by Sebastian Huber <sebastian.huber@…>, on 10/24/14 at 05:21:51

tests/smptests: Normal use of test extension

  • Property mode set to 100644
File size: 3.2 KB
Line 
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.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems.h>
20#include <rtems/test.h>
21#include <rtems/score/percpu.h>
22#include <rtems/score/smpimpl.h>
23#include <rtems/score/smpbarrier.h>
24
25#include <assert.h>
26#include <stdlib.h>
27
28const char rtems_test_name[] = "SMPFATAL 2";
29
30#define MAX_CPUS 32
31
32static uint32_t main_cpu;
33
34static SMP_barrier_Control barrier = SMP_BARRIER_CONTROL_INITIALIZER;
35
36static void Init(rtems_task_argument arg)
37{
38  assert(0);
39}
40
41static void fatal_extension(
42  rtems_fatal_source source,
43  bool is_internal,
44  rtems_fatal_code code
45)
46{
47  SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
48
49  if (
50    source == RTEMS_FATAL_SOURCE_APPLICATION
51      || source == RTEMS_FATAL_SOURCE_SMP
52  ) {
53    uint32_t self = rtems_get_current_processor();
54
55    assert(!is_internal);
56
57    if (self == main_cpu) {
58      uint32_t cpu;
59
60      assert(source == RTEMS_FATAL_SOURCE_APPLICATION);
61      assert(code == 0xdeadbeef);
62
63      for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
64        const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
65        Per_CPU_State state = per_cpu->state;
66
67        assert(state == PER_CPU_STATE_SHUTDOWN);
68      }
69
70      rtems_test_endk();
71    } else {
72      assert(source == RTEMS_FATAL_SOURCE_SMP);
73      assert(code == SMP_FATAL_SHUTDOWN);
74    }
75  }
76
77  _SMP_barrier_Wait(&barrier, &barrier_state, rtems_get_processor_count());
78}
79
80static rtems_status_code test_driver_init(
81  rtems_device_major_number major,
82  rtems_device_minor_number minor,
83  void *arg
84)
85{
86  uint32_t self = rtems_get_current_processor();
87  uint32_t cpu_count = rtems_get_processor_count();
88  uint32_t cpu;
89
90  rtems_test_begink();
91
92  assert(rtems_configuration_get_maximum_processors() == MAX_CPUS);
93
94  main_cpu = self;
95
96  for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
97    const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
98    Per_CPU_State state = per_cpu->state;
99
100    if (cpu == self) {
101      assert(state == PER_CPU_STATE_INITIAL);
102    } else if (cpu < cpu_count) {
103      assert(
104        state == PER_CPU_STATE_INITIAL
105          || state == PER_CPU_STATE_READY_TO_START_MULTITASKING
106      );
107    } else {
108      assert(state == PER_CPU_STATE_INITIAL);
109    }
110  }
111
112  if (cpu_count > 1) {
113    rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 0xdeadbeef);
114  } else {
115    rtems_test_endk();
116    exit(0);
117  }
118
119  return RTEMS_SUCCESSFUL;
120}
121
122#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
123#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
124
125#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
126  { .initialization_entry = test_driver_init }
127
128#define CONFIGURE_INITIAL_EXTENSIONS \
129  { .fatal = fatal_extension }, \
130  RTEMS_TEST_INITIAL_EXTENSION
131
132#define CONFIGURE_SMP_APPLICATION
133
134#define CONFIGURE_SMP_MAXIMUM_PROCESSORS MAX_CPUS
135
136#define CONFIGURE_MAXIMUM_TASKS 1
137
138#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
139
140#define CONFIGURE_INIT
141
142#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.