source: rtems/testsuites/sptests/sp28/init.c @ b84f1fdc

4.104.11
Last change on this file since b84f1fdc was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on May 10, 2009 at 2:39:46 PM

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • sp04/system.h, sp04/task1.c, sp04/tswitch.c, sp07/init.c, sp12/init.c, sp13/putbuff.c, sp13/system.h, sp13/task1.c, sp15/init.c, sp16/system.h, sp19/fptask.c, sp25/system.h, sp26/task1.c, sp27/init.c, sp28/init.c, sp29/init.c, sp31/task1.c, sp33/init.c, sp34/changepri.c, sp35/priinv.c, sp37/init.c, sp38/init.c, sp39/init.c, sp41/init.c, sp42/init.c, sp43/init.c, sp44/init.c, sp45/init.c, sp46/init.c, sp47/init.c, sp48/init.c, spfatal03/testcase.h, spfatal05/testcase.h, spfatal06/testcase.h, spfatal_support/system.h, spobjgetnext/init.c, spsize/getint.c, spsize/size.c: Fix warnings.
  • Property mode set to 100644
File size: 10.3 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>
14
15rtems_task Init(rtems_task_argument argument);
16
17#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
18#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
19#define CONFIGURE_MAXIMUM_USER_EXTENSIONS    2
20
21#define CONFIGURE_MAXIMUM_TASKS              4
22#define CONFIGURE_MAXIMUM_TASK_VARIABLES     (4)
23#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
24#define CONFIGURE_MICROSECONDS_PER_TICK      10000
25
26#define CONFIGURE_MICROSECONDS_INIT
27
28#include <rtems/confdefs.h>
29
30#include <bsp.h>
31#include <rtems/error.h>
32#include <stdio.h>
33
34rtems_task subtask(rtems_task_argument arg);
35rtems_task Task_variable_deleter(rtems_task_argument ignored);
36void starttask(int arg);
37void test_errors(void);
38void test_dtor(void *pointer);
39void test_multiple_taskvars(void);
40void test_out_of_memory(void);
41rtems_task Other_Task(rtems_task_argument ignored);
42void test_delete_from_other_task(void);
43void test_delete_as_side_effect(void);
44
45volatile void *taskvar;
46volatile int nRunning;
47volatile int nDeleted;
48
49rtems_task
50subtask (rtems_task_argument arg)
51{
52  uintptr_t localvar = arg;
53  int i;
54  rtems_status_code sc;
55
56  nRunning++;
57  while (nRunning != 3)
58    rtems_task_wake_after (0);
59  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar, NULL);
60  directive_failed( sc, "task variable add" );
61
62  taskvar = (void *)localvar;
63  while (localvar < 1000) {
64    localvar++;
65    rtems_task_wake_after (0);
66    taskvar = (void *)((uintptr_t)taskvar + 1);
67    rtems_task_wake_after (0);
68    if ((uintptr_t)taskvar != localvar) {
69      printf ("Task:%d taskvar:%d localvar:%d\n",
70        arg, (uintptr_t)taskvar, localvar);
71      rtems_task_suspend (RTEMS_SELF);
72    }
73  }
74  sc = rtems_task_variable_delete(RTEMS_SELF, (void **)&taskvar);
75  nDeleted++;
76  directive_failed( sc, "task variable delete" );
77
78  if ((uintptr_t)taskvar == localvar) {
79    printf("Task:%d deleted taskvar:%d localvar:%d\n",
80      arg, (uintptr_t)taskvar, localvar);
81    nRunning--;
82    rtems_task_suspend (RTEMS_SELF);
83  }
84  while (nDeleted != 3)
85    rtems_task_wake_after (0);
86  for (i = 0 ; i < 1000 ; i++) {
87    taskvar = (void *)(localvar = 100 * arg);
88    rtems_task_wake_after(0);
89    if (nRunning <= 1)
90      break;
91    if ((uintptr_t)taskvar == localvar) {
92      printf("Task:%d taskvar:%d localvar:%d\n",
93        arg, (uintptr_t)taskvar, localvar);
94      nRunning--;
95      rtems_task_suspend(RTEMS_SELF);
96    }
97  }
98  nRunning--;
99  while (nRunning)
100    rtems_task_wake_after(0);
101
102  puts("*** END OF TEST 28 ***" );
103  rtems_test_exit(0);
104}
105
106void
107starttask (int arg)
108{
109  rtems_id tid;
110  rtems_status_code sc;
111
112  sc = rtems_task_create(rtems_build_name ('S', 'R', 'V', arg + 'A'),
113    RTEMS_MAXIMUM_PRIORITY - 1u,
114    RTEMS_MINIMUM_STACK_SIZE,
115    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
116    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
117    &tid
118  );
119  directive_failed( sc, "task create" );
120
121  sc = rtems_task_start(tid, subtask, arg);
122  directive_failed( sc, "task start" );
123}
124
125volatile void *taskvar1;
126volatile void *taskvar2;
127volatile void *taskvar3;
128
129void test_errors(void)
130{
131  rtems_status_code  sc;
132  void              *value;
133
134  /*
135   *  task variable get error status codes
136   */
137  puts( "task variable get - NULL pointer - RTEMS_INVALID_ADDRESS" );
138  sc = rtems_task_variable_get(RTEMS_SELF, NULL, &value );
139  fatal_directive_status( sc, RTEMS_INVALID_ADDRESS, "get NULL pointer" );
140
141  puts( "task variable get - bad result - RTEMS_INVALID_ADDRESS" );
142  sc = rtems_task_variable_get(RTEMS_SELF, (void **)&taskvar1, NULL);
143  fatal_directive_status( sc, RTEMS_INVALID_ADDRESS, "get bad result" );
144
145  puts( "task variable get - bad pointer - RTEMS_INVALID_ADDRESS" );
146  sc = rtems_task_variable_get(RTEMS_SELF, (void **)&taskvar1, &value);
147  fatal_directive_status( sc, RTEMS_INVALID_ADDRESS, "get bad pointer" );
148
149  /*
150   *  task variable delete error status codes
151   */
152  puts( "task variable delete - NULL pointer - RTEMS_INVALID_ADDRESS" );
153  sc = rtems_task_variable_delete(RTEMS_SELF, NULL);
154  fatal_directive_status( sc, RTEMS_INVALID_ADDRESS, "delete NULL pointer" );
155
156  puts( "task variable delete - bad pointer - RTEMS_INVALID_ADDRESS" );
157  sc = rtems_task_variable_delete(RTEMS_SELF, (void **)&taskvar1);
158  fatal_directive_status( sc, RTEMS_INVALID_ADDRESS, "delete bad pointer" );
159
160}
161
162volatile uint32_t test_dtor_ran;
163
164void test_dtor(void *pointer)
165{
166  test_dtor_ran++;
167}
168
169
170void test_multiple_taskvars(void)
171{
172  rtems_status_code  sc;
173  void              *value;
174
175  test_dtor_ran = 0;
176
177  /*
178   *  Add multiple task variables and add each twice to
179   *  verify that behavior is OK
180   */
181  puts( "Adding multiple task variables" );
182  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar1, NULL);
183  directive_failed( sc, "add multiple #1" );
184
185  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar1, test_dtor);
186  directive_failed( sc, "add multiple #2" );
187
188  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar2, test_dtor);
189  directive_failed( sc, "add multiple #3" );
190
191  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar2, NULL);
192  directive_failed( sc, "add multiple #4" );
193
194  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar3, NULL);
195  directive_failed( sc, "add multiple #5" );
196
197  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar3, test_dtor);
198  directive_failed( sc, "add multiple #6" );
199
200  /*
201   *  Obtain task variables in various spots on the chain
202   */
203  puts( "Obtaining multiple task variables" );
204  sc = rtems_task_variable_get( RTEMS_SELF, (void **)&taskvar3, &value );
205  directive_failed( sc, "get multiple #1" );
206  sc = rtems_task_variable_get( RTEMS_SELF, (void **)&taskvar2, &value );
207  directive_failed( sc, "get multiple #2" );
208  sc = rtems_task_variable_get( RTEMS_SELF, (void **)&taskvar1, &value );
209  directive_failed( sc, "get multiple #2" );
210 
211  /*
212   *  Delete task variables in various spots on the chain
213   */
214
215  /* to trip the destructors */
216  taskvar1 = (void *)1;
217  taskvar2 = (void *)2;
218  taskvar3 = (void *)3;
219
220  puts( "Deleting multiple task variables" );
221  sc = rtems_task_variable_delete(RTEMS_SELF, (void **)&taskvar2);
222  directive_failed( sc, "delete multiple #1" );
223  sc = rtems_task_variable_delete(RTEMS_SELF, (void **)&taskvar3);
224  directive_failed( sc, "delete multiple #2" );
225  sc = rtems_task_variable_delete(RTEMS_SELF, (void **)&taskvar1);
226  directive_failed( sc, "delete multiple #3" );
227
228  if ( test_dtor_ran != 2 ) {
229    printf( "Test dtor ran %d times not 2 times as expected\n", test_dtor_ran );
230    rtems_test_exit(0);
231  }
232}
233
234#define MAX_VARS 4096
235
236void *Pointers[MAX_VARS];
237
238void test_out_of_memory(void)
239{
240  int                 i;
241  int                 max;
242  rtems_status_code   sc;
243  int                 ran_out = 0;
244  void              **base;
245
246  base = Pointers;
247
248  for (i=0 ; i<MAX_VARS ; i++ ) {
249    sc = rtems_task_variable_add(RTEMS_SELF, &base[i], NULL);
250    if ( sc == RTEMS_NO_MEMORY ) {
251      puts( "task_variable_add - returns NO_MEMORY" );
252      max = i;
253      ran_out = 1;
254      break;
255    }
256    directive_failed( sc, "add loop until out of memory" );
257  }
258
259  if ( !ran_out ) {
260    puts( "ERROR!!! did not run out of memory adding task variables!" );
261    rtems_test_exit(0);
262  }
263
264  for (i=0 ; i<max ; i++ ) {
265    sc = rtems_task_variable_delete(RTEMS_SELF, &base[i]);
266    directive_failed( sc, "delete loop until out of memory" );
267  }
268}
269
270rtems_id main_task;
271rtems_id other_task;
272
273rtems_task Other_Task(rtems_task_argument ignored)
274{
275  rtems_status_code sc;
276
277  puts( "Deleting task variables in another task" );
278  sc = rtems_task_variable_delete(main_task, (void **)&taskvar1);
279  directive_failed( sc, "delete loop for other task" );
280
281  (void) rtems_task_delete( RTEMS_SELF );
282}
283
284void test_delete_from_other_task(void)
285{
286  rtems_status_code sc;
287
288  test_dtor_ran = 0;
289
290  sc = rtems_task_ident( RTEMS_SELF, 0, &main_task );
291  directive_failed( sc, "task ident" );
292
293  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar1, test_dtor);
294  directive_failed( sc, "add for other task case" );
295
296  sc = rtems_task_create(rtems_build_name ('O', 'T', 'H', 'R'),
297    RTEMS_MAXIMUM_PRIORITY - 1u,
298    RTEMS_MINIMUM_STACK_SIZE,
299    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
300    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
301    &other_task
302  );
303  directive_failed( sc, "task create other" );
304
305  sc = rtems_task_start(other_task, Other_Task, 0);
306  directive_failed( sc, "task start other" );
307
308  rtems_task_wake_after( 100 );
309 
310  if ( test_dtor_ran != 1 ) {
311    printf( "Test dtor ran %d times not 1 times as expected\n", test_dtor_ran );
312    rtems_test_exit(0);
313  }
314}
315
316/*
317 *  Task which adds task variables just to delete them
318 */
319rtems_task Task_variable_deleter(rtems_task_argument ignored)
320{
321  rtems_status_code sc;
322
323  puts( "Adding multiple task variables to delete implicitly" );
324  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar1, test_dtor);
325  directive_failed( sc, "add multiple for delete #1" );
326
327  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar2, NULL);
328  directive_failed( sc, "add multiple for delete #2" );
329
330  sc = rtems_task_variable_add(RTEMS_SELF, (void **)&taskvar3, test_dtor);
331  directive_failed( sc, "add multiple for delete #3" );
332
333  (void) rtems_task_delete( RTEMS_SELF );
334}
335
336void test_delete_as_side_effect(void)
337{
338  rtems_status_code sc;
339  rtems_id          deleter_task;
340
341  test_dtor_ran = 0;
342
343  sc = rtems_task_create(rtems_build_name ('O', 'T', 'H', 'R'),
344    RTEMS_MAXIMUM_PRIORITY - 1u,
345    RTEMS_MINIMUM_STACK_SIZE,
346    RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
347    RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
348    &deleter_task
349  );
350  directive_failed( sc, "task create deleter" );
351
352  sc = rtems_task_start(deleter_task, Task_variable_deleter, 0);
353  directive_failed( sc, "task start deleter" );
354
355  rtems_task_wake_after( 100 );
356 
357  if ( test_dtor_ran != 2 ) {
358    printf( "Test dtor ran %d times not 2 times as expected\n", test_dtor_ran );
359    rtems_test_exit(0);
360  }
361}
362
363rtems_task Init (rtems_task_argument ignored)
364{
365  puts("*** START OF TEST 28 ***" );
366
367  test_errors();
368
369  test_multiple_taskvars();
370
371  test_delete_as_side_effect();
372
373  test_delete_from_other_task();
374
375  starttask (1);
376  starttask (2);
377  starttask (3);
378
379  test_out_of_memory();
380
381  rtems_task_suspend (RTEMS_SELF);
382}
Note: See TracBrowser for help on using the repository browser.