source: rtems/testsuites/smptests/smpfatal02/init.c @ 03c9f24

5
Last change on this file since 03c9f24 was 03c9f24, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 5, 2019 at 6:03:12 AM

rtems: Add rtems_scheduler_get_processor()

Add rtems_scheduler_get_processor() as a replacement for
rtems_get_current_processor(). The rtems_get_current_processor() is a
bit orphaned. Adopt it by the Scheduler Manager. This is in line with
the glibc sched_getcpu() function.

Deprecate rtems_get_current_processor().

Update #3731.

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