source: rtems/testsuites/smptests/smpfatal02/init.c @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

  • 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#define TEST_INIT
20
21#define TESTS_USE_PRINTK
22#include "tmacros.h"
23
24#include <rtems.h>
25#include <rtems/score/percpu.h>
26#include <rtems/score/smpimpl.h>
27#include <rtems/score/smpbarrier.h>
28
29#include <assert.h>
30#include <stdlib.h>
31
32const char rtems_test_name[] = "SMPFATAL 2";
33
34#define MAX_CPUS 32
35
36static uint32_t main_cpu;
37
38static SMP_barrier_Control barrier = SMP_BARRIER_CONTROL_INITIALIZER;
39
40static void Init(rtems_task_argument arg)
41{
42  assert(0);
43}
44
45static void fatal_extension(
46  rtems_fatal_source source,
47  bool always_set_to_false,
48  rtems_fatal_code code
49)
50{
51  SMP_barrier_State barrier_state = SMP_BARRIER_STATE_INITIALIZER;
52  uint32_t self = rtems_get_current_processor();
53
54  assert(!always_set_to_false);
55
56  if ( source == RTEMS_FATAL_SOURCE_APPLICATION ) {
57    uint32_t cpu;
58
59    assert(self == main_cpu);
60    assert(code == 0xdeadbeef);
61
62    _SMP_Request_shutdown();
63
64    for (cpu = 0; cpu < MAX_CPUS; ++cpu) {
65      const Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
66      Per_CPU_State state = per_cpu->state;
67
68      assert(state == PER_CPU_STATE_SHUTDOWN);
69    }
70
71    TEST_END();
72  } else if ( source == RTEMS_FATAL_SOURCE_SMP ) {
73    assert(self != main_cpu);
74    assert(code == SMP_FATAL_SHUTDOWN);
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  TEST_BEGIN();
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    TEST_END();
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_MAXIMUM_PROCESSORS MAX_CPUS
133
134#define CONFIGURE_MAXIMUM_TASKS 1
135
136#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
137
138#define CONFIGURE_INIT
139
140#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.