source: rtems/testsuites/smptests/smp07/init.c @ 57c88056

4.115
Last change on this file since 57c88056 was 57c88056, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 19, 2013 at 8:12:13 AM

smptests: Be successful on one processor

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