source: rtems/testsuites/smptests/smpfatal01/init.c @ ad48ebb

4.115
Last change on this file since ad48ebb was ad48ebb, checked in by Sebastian Huber <sebastian.huber@…>, on 03/17/14 at 07:10:19

tests/smptests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 2.8 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.com/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
24#include <assert.h>
25#include <stdlib.h>
26
27const char rtems_test_name[] = "SMPFATAL 1";
28
29#define MAX_CPUS 32
30
31static uint32_t main_cpu;
32
33static void Init(rtems_task_argument arg)
34{
35  assert(0);
36}
37
38static void fatal_extension(
39  rtems_fatal_source source,
40  bool is_internal,
41  rtems_fatal_code code
42)
43{
44  if (source == RTEMS_FATAL_SOURCE_SMP) {
45    uint32_t self = rtems_smp_get_current_processor();
46
47    assert(!is_internal);
48    assert(code == SMP_FATAL_SHUTDOWN);
49
50    if (self == main_cpu) {
51      uint32_t cpu;
52
53      for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
54        const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
55        Per_CPU_State state = per_cpu->state;
56
57        assert(state == PER_CPU_STATE_SHUTDOWN);
58      }
59
60      rtems_test_endk();
61    }
62  }
63}
64
65static rtems_status_code test_driver_init(
66  rtems_device_major_number major,
67  rtems_device_minor_number minor,
68  void *arg
69)
70{
71  uint32_t self = rtems_smp_get_current_processor();
72  uint32_t cpu_count = rtems_smp_get_processor_count();
73  uint32_t cpu;
74
75  rtems_test_begink();
76
77  assert(rtems_configuration_get_maximum_processors() == MAX_CPUS);
78
79  main_cpu = self;
80
81  for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
82    const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
83    Per_CPU_State state = per_cpu->state;
84
85    if (cpu == self) {
86      assert(state == PER_CPU_STATE_INITIAL);
87    } else if (cpu < cpu_count) {
88      assert(
89        state == PER_CPU_STATE_INITIAL
90          || state == PER_CPU_STATE_READY_TO_START_MULTITASKING
91      );
92    } else {
93      assert(state == PER_CPU_STATE_INITIAL);
94    }
95  }
96
97  if (cpu_count > 1) {
98    uint32_t other = (self + 1) % cpu_count;
99    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( other );
100
101    per_cpu->state = PER_CPU_STATE_SHUTDOWN;
102  } else {
103    rtems_test_endk();
104    exit(0);
105  }
106
107  return RTEMS_SUCCESSFUL;
108}
109
110#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
111#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
112
113#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
114  { .initialization_entry = test_driver_init }
115
116#define CONFIGURE_INITIAL_EXTENSIONS \
117  { .fatal = fatal_extension }, \
118  RTEMS_TEST_INITIAL_EXTENSION
119
120#define CONFIGURE_SMP_APPLICATION
121
122#define CONFIGURE_SMP_MAXIMUM_PROCESSORS MAX_CPUS
123
124#define CONFIGURE_MAXIMUM_TASKS 1
125
126#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
127
128#define CONFIGURE_INIT
129
130#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.