source: rtems/testsuites/smptests/smp07/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: 4.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define TEST_INIT
15
16#include <tmacros.h>
17#include "test_support.h"
18
19const char rtems_test_name[] = "SMP 7";
20
21volatile bool TaskRan = false;
22volatile bool TSRFired = false;
23rtems_id      Semaphore;
24
25rtems_task Init(
26  rtems_task_argument argument
27);
28
29rtems_task Test_task(
30  rtems_task_argument argument
31);
32
33static void success(void)
34{
35  rtems_test_end( );
36  rtems_test_exit( 0 );
37}
38
39rtems_task Test_task(
40  rtems_task_argument argument
41)
42{
43  uint32_t          cpu_num;
44  rtems_status_code sc;
45  char              name[5];
46  char             *p;
47
48  /* Get the task name */
49  p = rtems_object_get_name( RTEMS_SELF, 5, name );
50  rtems_test_assert( p != NULL );
51
52   /* Get the CPU Number */
53  cpu_num = rtems_get_current_processor();
54
55  /* Print that the task is up and running. */
56  locked_printf(" CPU %" PRIu32 " runnng Task %s and blocking\n", cpu_num, name);
57
58  sc = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
59  directive_failed( sc,"obtain in test task");
60
61  if ( !TSRFired )
62    locked_printf( "*** ERROR TSR DID NOT FIRE BUT TEST TASK AWAKE***" );
63
64  TaskRan = true;
65
66  /* Print that the task is up and running. */
67  locked_printf(
68    " CPU %" PRIu32 " running Task %s after semaphore release\n",
69    cpu_num,
70    name
71  );
72
73  /* FIXME: Task deletion currently not supported */
74  (void) rtems_task_suspend( RTEMS_SELF );
75}
76
77
78static rtems_timer_service_routine TimerMethod(
79  rtems_id  timer,
80  void     *arg
81)
82{
83  /*
84   * Set flag and release the semaphore, allowing the blocked tasks to start.
85   */
86  TSRFired = true;
87
88  rtems_semaphore_release( Semaphore );
89}
90
91rtems_task Init(
92  rtems_task_argument argument
93)
94{
95  int                cpu_num;
96  rtems_id           id;
97  rtems_status_code  status;
98  rtems_interval     per_second;
99  rtems_interval     then;
100  rtems_id           Timer;
101
102  locked_print_initialize();
103  rtems_test_begin();
104
105  if ( rtems_get_processor_count() == 1 ) {
106    success();
107  }
108
109  /* Create/verify semaphore */
110  status = rtems_semaphore_create(
111    rtems_build_name ('S', 'E', 'M', '1'),
112    1,
113    RTEMS_LOCAL                   |
114    RTEMS_SIMPLE_BINARY_SEMAPHORE |
115    RTEMS_PRIORITY,
116    1,
117    &Semaphore
118  );
119  directive_failed( status, "rtems_semaphore_create" );
120
121  /* Lock semaphore */
122  status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0);
123  directive_failed( status,"rtems_semaphore_obtain of SEM1\n");
124
125  /* Create and Start test task. */
126  status = rtems_task_create(
127    rtems_build_name( 'T', 'A', '1', ' ' ),
128    1,
129    RTEMS_MINIMUM_STACK_SIZE,
130    RTEMS_DEFAULT_MODES,
131    RTEMS_DEFAULT_ATTRIBUTES,
132    &id
133  );
134  directive_failed( status, "task create" );
135
136  cpu_num = rtems_get_current_processor();
137  locked_printf(" CPU %d start task TA1\n", cpu_num );
138  status = rtems_task_start( id, Test_task, 1 );
139  directive_failed( status, "task start" );
140
141  /* Create and start TSR */
142  locked_printf(" CPU %d create and start timer\n", cpu_num );
143  status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer);
144  directive_failed( status, "rtems_timer_create" );
145
146  per_second = rtems_clock_get_ticks_per_second();
147  status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL );
148  directive_failed( status, "rtems_timer_fire_after");
149
150  /*
151   *  Wait long enough that TSR should have fired.
152   *
153   *  Spin so CPU 0 is consumed.  This forces task to run on CPU 1.
154   */
155  then = rtems_clock_get_ticks_since_boot() + 4 * per_second;
156  while (1) {
157    if ( rtems_clock_get_ticks_since_boot() > then )
158      break;
159    if ( TSRFired && TaskRan )
160      break;
161  };
162
163  /* Validate the timer fired and that the task ran */
164  if ( !TSRFired )
165    locked_printf( "*** ERROR TSR DID NOT FIRE ***" );
166
167  if ( !TaskRan ) {
168    locked_printf( "*** ERROR TASK DID NOT RUN ***" );
169    rtems_test_exit(0);
170  }
171
172  /* End the program */
173  success();
174}
175
176/* configuration information */
177
178#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
179#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
180
181#define CONFIGURE_MAXIMUM_PROCESSORS   2
182#define CONFIGURE_MAXIMUM_TIMERS           1
183
184#define CONFIGURE_MAXIMUM_TASKS            2
185#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
186
187#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
188#define CONFIGURE_MAXIMUM_SEMAPHORES       2
189
190#define CONFIGURE_INIT
191
192#include <rtems/confdefs.h>
193/* end of file */
Note: See TracBrowser for help on using the repository browser.