source: rtems/testsuites/smptests/smp07/init.c @ 015bd1b

4.115
Last change on this file since 015bd1b was 015bd1b, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 6, 2013 at 8:47:38 AM

smptests/smp07: Use suspend instead of delete

  • 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  /* FIXME: Task deletion currently not supported */
62  (void) rtems_task_suspend( RTEMS_SELF );
63}
64
65
66rtems_timer_service_routine TimerMethod(
67  rtems_id  timer,
68  void     *arg
69)
70{
71  /*
72   * Set flag and release the semaphore, allowing the blocked tasks to start.
73   */
74  TSRFired = true;
75
76  rtems_semaphore_release( Semaphore );
77}
78
79rtems_task Init(
80  rtems_task_argument argument
81)
82{
83  int                cpu_num;
84  rtems_id           id;
85  rtems_status_code  status;
86  rtems_interval     per_second;
87  rtems_interval     then;
88  rtems_id           Timer;
89
90  locked_print_initialize();
91  locked_printf( "\n\n*** TEST SMP07 ***\n" );
92
93  if ( rtems_smp_get_processor_count() == 1 ) {
94    success();
95  }
96
97  /* Create/verify semaphore */
98  status = rtems_semaphore_create(
99    rtems_build_name ('S', 'E', 'M', '1'),
100    1,                                             
101    RTEMS_LOCAL                   |
102    RTEMS_SIMPLE_BINARY_SEMAPHORE |
103    RTEMS_PRIORITY,
104    1,
105    &Semaphore
106  );
107  directive_failed( status, "rtems_semaphore_create" );
108
109  /* Lock semaphore */
110  status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0);
111  directive_failed( status,"rtems_semaphore_obtain of SEM1\n");
112
113  /* Create and Start test task. */
114  status = rtems_task_create(
115    rtems_build_name( 'T', 'A', '1', ' ' ),
116    1,
117    RTEMS_MINIMUM_STACK_SIZE,
118    RTEMS_DEFAULT_MODES,
119    RTEMS_DEFAULT_ATTRIBUTES,
120    &id
121  );
122  directive_failed( status, "task create" );
123
124  cpu_num = rtems_smp_get_current_processor();
125  locked_printf(" CPU %d start task TA1\n", cpu_num );
126  status = rtems_task_start( id, Test_task, 1 );
127  directive_failed( status, "task start" );
128
129  /* Create and start TSR */
130  locked_printf(" CPU %d create and start timer\n", cpu_num );
131  status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer);
132  directive_failed( status, "rtems_timer_create" );
133
134  per_second = rtems_clock_get_ticks_per_second();
135  status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL );
136  directive_failed( status, "rtems_timer_fire_after");
137
138  /*
139   *  Wait long enough that TSR should have fired.
140   *
141   *  Spin so CPU 0 is consumed.  This forces task to run on CPU 1.
142   */
143  then = rtems_clock_get_ticks_since_boot() + 4 * per_second;
144  while (1) {
145    if ( rtems_clock_get_ticks_since_boot() > then )
146      break;
147    if ( TSRFired && TaskRan )
148      break;
149  };
150 
151  /* Validate the timer fired and that the task ran */
152  if ( !TSRFired )
153    locked_printf( "*** ERROR TSR DID NOT FIRE ***" );
154
155  if ( !TaskRan ) {
156    locked_printf( "*** ERROR TASK DID NOT RUN ***" );
157    rtems_test_exit(0);
158  }
159
160  /* End the program */
161  success();
162}
163
164/* configuration information */
165
166#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
167#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
168
169#define CONFIGURE_SMP_APPLICATION
170#define CONFIGURE_SMP_MAXIMUM_PROCESSORS   2
171#define CONFIGURE_MAXIMUM_TIMERS           1
172
173#define CONFIGURE_MAXIMUM_TASKS            2
174#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
175#define CONFIGURE_MAXIMUM_SEMAPHORES       2
176
177#define CONFIGURE_INIT
178
179#include <rtems/confdefs.h>
180/* end of file */
Note: See TracBrowser for help on using the repository browser.