source: rtems/testsuites/sptests/sp28/init.c @ 4389287a

4.104.11
Last change on this file since 4389287a was a986c07, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 14, 2008 at 6:36:00 PM

2008-12-14 Joel Sherrill <joel.sherrill@…>

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