source: rtems/testsuites/sptests/sp33/init.c @ a611d80

4.104.11
Last change on this file since a611d80 was a611d80, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 28, 2009 at 6:10:52 PM

2009-09-28 Joel Sherrill <joel.sherrill@…>

  • sp33/init.c, sp33/sp33.scn: Add some barrier error cases uncovered by uC5282 coverage runs.
  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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#define CONFIGURE_INIT
13#include <tmacros.h>  /* includes bsp.h, stdio, etc... */
14
15/* prototype */
16rtems_task Init (rtems_task_argument ignored);
17
18#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
19
20#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
21#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
22#define CONFIGURE_MAXIMUM_TASKS     5
23#define CONFIGURE_MAXIMUM_BARRIERS  1
24
25#define CONFIGURE_INIT
26
27rtems_task Waiter(
28  rtems_task_argument number
29);
30
31rtems_id    Barrier;
32
33int SuccessfulCase;
34int DeletedCase;
35
36rtems_task Waiter(
37  rtems_task_argument number
38)
39{
40  rtems_status_code status;
41
42  printf( "Waiter %d waiting on barrier\n", number );
43  status = rtems_barrier_wait( Barrier, RTEMS_NO_TIMEOUT );
44
45  printf( "Waiter %d back from barrier\n", number );
46
47  if ( SuccessfulCase == TRUE ) {
48    directive_failed(status, "rtems_barrier_wait");
49  } else if ( DeletedCase == TRUE ) {
50    fatal_directive_status(
51      status,
52      RTEMS_OBJECT_WAS_DELETED,
53      "rtems_barrier_wait did not get deleted"
54    );
55  }
56
57  rtems_task_delete( RTEMS_SELF );
58}
59
60#include <rtems/confdefs.h>
61
62rtems_task Init(
63  rtems_task_argument ignored
64)
65{
66  rtems_status_code status;
67  rtems_name        name = rtems_build_name('B','A','R','1');
68  uint32_t          released;
69  rtems_id          testId;
70  rtems_id          Tasks[CONFIGURE_MAXIMUM_TASKS-1];
71  uint32_t          i;
72
73  puts("\n\n*** TEST 33 ***");
74
75  /* Check bad argument cases */
76  puts( "rtems_barrier_delete - bad id - INVALID_ID" );
77  status = rtems_barrier_delete( 100 );
78  fatal_directive_status(
79    status,
80    RTEMS_INVALID_ID,
81    "rtems_barrier_delete did not return RTEMS_INVALID_ID"
82  );
83
84  puts( "rtems_barrier_release - bad id - INVALID_ID" );
85  status = rtems_barrier_release( 100, &released );
86  fatal_directive_status(
87    status,
88    RTEMS_INVALID_ID,
89    "rtems_barrier_release did not return RTEMS_INVALID_ID"
90  );
91
92  puts( "rtems_barrier_wait - bad id - INVALID_ID" );
93  status = rtems_barrier_wait( 100, 10 );
94  fatal_directive_status(
95    status,
96    RTEMS_INVALID_ID,
97    "rtems_barrier_wait did not return RTEMS_INVALID_ID"
98  );
99
100  /* Create barrier with automatic release and 0 maximum waiters */
101  puts( "Create barrier with automatic release and 0 max waiters" );
102  status = rtems_barrier_create(
103    name, RTEMS_BARRIER_AUTOMATIC_RELEASE, 0, &Barrier
104  );
105  fatal_directive_status(
106    status,
107    RTEMS_INVALID_NUMBER,
108    "rtems_barrier_create did not return RTEMS_INVALID_NUMBER"
109  );
110
111  /* create barrier with bad name */
112  puts( "rtems_barrier_create - bad name - INVALID_NAME" );
113  status = rtems_barrier_create(
114    0, RTEMS_BARRIER_AUTOMATIC_RELEASE, 1, &Barrier);
115  fatal_directive_status(
116    status,
117    RTEMS_INVALID_NAME,
118    "rtems_barrier_create did not return RTEMS_INVALID_NAME"
119  );
120
121  /* create barrier with bad id return address */
122  puts( "rtems_barrier_create - NULL barrier ID - INVALID_ADDRESS" );
123  status = rtems_barrier_create(name, RTEMS_BARRIER_AUTOMATIC_RELEASE, 1, NULL);
124  fatal_directive_status(
125    status,
126    RTEMS_INVALID_ADDRESS,
127    "rtems_barrier_create did not return RTEMS_INVALID_ADDRESS"
128  );
129
130  /* Create barrier */
131  puts( "rtems_barrier_create - OK" );
132  status = rtems_barrier_create( name, RTEMS_DEFAULT_ATTRIBUTES, 0, &Barrier );
133  directive_failed(status, "rtems_barrier_create");
134
135  /* Check for creating too many */
136  puts( "rtems_barrier_create - too many" );
137  status = rtems_barrier_create( name, RTEMS_DEFAULT_ATTRIBUTES, 0, &Barrier );
138  fatal_directive_status(
139    status,
140    RTEMS_TOO_MANY,
141    "rtems_barrier_create did not return RTEMS_TOO_MANY"
142  );
143
144  puts( "Check barrier ident" );
145  status = rtems_barrier_ident( name, &testId );
146  directive_failed(status, "rtems_barrier_ident");
147  if ( testId != Barrier ) {
148    printf( "ERROR -- rtems_barrier_create -- did not get Id expected\n" );
149    exit( 0 );
150  }
151
152  puts( "Wait on barrier w/timeout and TIMEOUT" );
153  status = rtems_barrier_wait( Barrier, 25 );
154  fatal_directive_status(
155    status,
156    RTEMS_TIMEOUT,
157    "rtems_barrier_wait did not timeout"
158  );
159
160  /* Release with bad return pointer */
161  puts( "rtems_barrier_release - NULL return count - INVALID_ADDRESS" );
162  status = rtems_barrier_release( Barrier, NULL );
163  fatal_directive_status(
164    status,
165    RTEMS_INVALID_ADDRESS,
166    "rtems_barrier_release bad return pointer"
167  );
168
169  /* Release no tasks */
170  status = rtems_barrier_release( Barrier, &released );
171  directive_failed(status, "rtems_barrier_release");
172  if ( released != 0 ) {
173    printf( "ERROR -- rtems_barrier_release -- released != 0, = %d", released);
174    exit(0);
175  }
176
177  /*  Create some tasks to wait for the barrier */
178  SuccessfulCase = TRUE;
179  DeletedCase    = FALSE;
180  puts( "\n*** Testing manual release of barrier ***" );
181  for (i=0 ; i<(CONFIGURE_MAXIMUM_TASKS-1) ; i++) {
182    status = rtems_task_create(
183      rtems_build_name('W','A','I','T'),
184      1,
185      RTEMS_MINIMUM_STACK_SIZE,
186      RTEMS_DEFAULT_MODES,
187      RTEMS_DEFAULT_ATTRIBUTES,
188      &Tasks[ i ]
189    );
190    directive_failed( status, "rtems_task_create of Waiter" );
191
192    status = rtems_task_start( Tasks[ i ], Waiter, i );
193    directive_failed( status, "rtems_task_start of Waiter" );
194  }
195
196  puts( "Delay to let Waiters block" ); 
197  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
198  directive_failed(status, "rtems_task_wake_after");
199
200  /* Release tasks which were waiting */
201  puts( "Releasing tasks" );
202  status = rtems_barrier_release( Barrier, &released );
203  directive_failed(status, "rtems_barrier_release");
204  if ( released != (CONFIGURE_MAXIMUM_TASKS-1) ) {
205    printf( "ERROR -- rtems_barrier_release -- released != %d, = %d",
206         (CONFIGURE_MAXIMUM_TASKS-1), released);
207    exit(0);
208  }
209
210  puts( "Delay to let Waiters print a message" ); 
211  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
212  directive_failed(status, "rtems_task_wake_after");
213
214  /*  Create some tasks to wait for the barrier */
215  SuccessfulCase = FALSE;
216  DeletedCase    = TRUE;
217  puts( "\n*** Testing Deletion of barrier ***" );
218  for (i=0 ; i<(CONFIGURE_MAXIMUM_TASKS-1) ; i++) {
219    status = rtems_task_create(
220      rtems_build_name('W','A','I','T'),
221      1,
222      RTEMS_MINIMUM_STACK_SIZE,
223      RTEMS_DEFAULT_MODES,
224      RTEMS_DEFAULT_ATTRIBUTES,
225      &Tasks[ i ]
226    );
227    directive_failed( status, "rtems_task_create of Waiter" );
228
229    status = rtems_task_start( Tasks[ i ], Waiter, i );
230    directive_failed( status, "rtems_task_start of Waiter" );
231  }
232
233  puts( "Delay to let Waiters block" ); 
234  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
235  directive_failed(status, "rtems_task_wake_after");
236
237  puts( "rtems_barrier_delete - OK" );
238  status = rtems_barrier_delete( Barrier );
239  directive_failed(status, "rtems_barrier_delete");
240
241  puts( "Delay to let Waiters print a message" ); 
242  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
243  directive_failed(status, "rtems_task_wake_after");
244
245  /* Create barrier with automatic release */
246  puts( "rtems_barrier_create - OK" );
247  status = rtems_barrier_create(
248    name, RTEMS_BARRIER_AUTOMATIC_RELEASE, CONFIGURE_MAXIMUM_TASKS-1, &Barrier
249  );
250  directive_failed(status, "rtems_barrier_create");
251
252  /*  Create some tasks to wait for the barrier */
253  SuccessfulCase = TRUE;
254  DeletedCase    = FALSE;
255  puts( "\n*** Testing automatic release of barrier ***" );
256  for (i=0 ; i<(CONFIGURE_MAXIMUM_TASKS-1) ; i++) {
257    status = rtems_task_create(
258      rtems_build_name('W','A','I','T'),
259      1,
260      RTEMS_MINIMUM_STACK_SIZE,
261      RTEMS_DEFAULT_MODES,
262      RTEMS_DEFAULT_ATTRIBUTES,
263      &Tasks[ i ]
264    );
265    directive_failed( status, "rtems_task_create of Waiter" );
266
267    status = rtems_task_start( Tasks[ i ], Waiter, i );
268    directive_failed( status, "rtems_task_start of Waiter" );
269  }
270
271  puts( "Delay to let task wait on barrier" ); 
272  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
273  directive_failed(status, "rtems_task_wake_after");
274
275  /* the end */
276  puts("*** END OF TEST 33 ***");
277  rtems_test_exit(0);
278}
Note: See TracBrowser for help on using the repository browser.