source: rtems/testsuites/smptests/smp07/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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