source: rtems/testsuites/smptests/smpfatal03/init.c @ 2a2a1695

4.115
Last change on this file since 2a2a1695 was 2a2a1695, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 10, 2014 at 9:42:19 AM

smptest/smpfatal03: Update due to API changes

  • 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/counter.h>
21#include <rtems/test.h>
22#include <rtems/score/smpbarrier.h>
23#include <rtems/score/smpimpl.h>
24#include <rtems/score/threaddispatch.h>
25
26#include <assert.h>
27#include <stdlib.h>
28
29const char rtems_test_name[] = "SMPFATAL 3";
30
31#define CPU_COUNT 2
32
33static uint32_t main_cpu;
34
35static SMP_barrier_Control giant_barrier = SMP_BARRIER_CONTROL_INITIALIZER;
36
37static SMP_barrier_Control fatal_barrier = SMP_BARRIER_CONTROL_INITIALIZER;
38
39static void acquire_giant_and_fatal_task(rtems_task_argument arg)
40{
41  SMP_barrier_State state = SMP_BARRIER_STATE_INITIALIZER;
42  int i;
43
44  for (i = 0; i < 13; ++i) {
45    _Giant_Acquire();
46  }
47
48  _SMP_barrier_Wait(&giant_barrier, &state, CPU_COUNT);
49
50  /*
51   * Now we have to wait some time so that the other thread can actually start
52   * with the _Giant_Acquire() procedure.
53   */
54  rtems_counter_delay_nanoseconds(1000000);
55
56  rtems_fatal(RTEMS_FATAL_SOURCE_APPLICATION, 0xdeadbeef);
57}
58
59static void wait_for_giant(void)
60{
61  SMP_barrier_State state = SMP_BARRIER_STATE_INITIALIZER;
62
63  _SMP_barrier_Wait(&giant_barrier, &state, CPU_COUNT);
64
65  _Giant_Acquire();
66}
67
68static void Init(rtems_task_argument arg)
69{
70  uint32_t self = rtems_get_current_processor();
71  uint32_t cpu_count = rtems_get_processor_count();
72
73  rtems_test_begink();
74
75  main_cpu = self;
76
77  if (cpu_count >= CPU_COUNT) {
78    rtems_status_code sc;
79    rtems_id id;
80
81    sc = rtems_task_create(
82      rtems_build_name( 'W', 'A', 'I', 'T' ),
83      1,
84      RTEMS_MINIMUM_STACK_SIZE,
85      RTEMS_DEFAULT_MODES,
86      RTEMS_DEFAULT_ATTRIBUTES,
87      &id
88    );
89    assert(sc == RTEMS_SUCCESSFUL);
90
91    sc = rtems_task_start(id, acquire_giant_and_fatal_task, 0);
92    assert(sc == RTEMS_SUCCESSFUL);
93
94    wait_for_giant();
95  } else {
96    rtems_test_endk();
97    exit(0);
98  }
99}
100
101static void fatal_extension(
102  rtems_fatal_source source,
103  bool is_internal,
104  rtems_fatal_code code
105)
106{
107  if (
108    source == RTEMS_FATAL_SOURCE_APPLICATION
109      || source == RTEMS_FATAL_SOURCE_SMP
110  ) {
111    uint32_t self = rtems_get_current_processor();
112    SMP_barrier_State state = SMP_BARRIER_STATE_INITIALIZER;
113
114    assert(!is_internal);
115
116    if (self == main_cpu) {
117      assert(source == RTEMS_FATAL_SOURCE_SMP);
118      assert(code == SMP_FATAL_SHUTDOWN_RESPONSE);
119    } else {
120      assert(source == RTEMS_FATAL_SOURCE_APPLICATION);
121      assert(code == 0xdeadbeef);
122    }
123
124    _SMP_barrier_Wait(&fatal_barrier, &state, CPU_COUNT);
125
126    if (self == 0) {
127      rtems_test_endk();
128    }
129  }
130}
131
132#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
133#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
134
135#define CONFIGURE_INITIAL_EXTENSIONS \
136  { .fatal = fatal_extension }, \
137  RTEMS_TEST_INITIAL_EXTENSION
138
139#define CONFIGURE_SMP_APPLICATION
140
141#define CONFIGURE_SMP_MAXIMUM_PROCESSORS CPU_COUNT
142
143#define CONFIGURE_MAXIMUM_TASKS 2
144
145#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
146
147#define CONFIGURE_INIT
148
149#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.