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

4.115
Last change on this file since cf288c38 was cf288c38, checked in by Jennifer Averett <Jennifer.Averett@…>, on Jul 29, 2011 at 12:29:34 PM

2011-07-29 Jennifer Averett <Jennifer.Averett@…>

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