source: rtems/testsuites/samples/unlimited/test3.c @ 8f71a36

4.104.114.84.95
Last change on this file since 8f71a36 was 8f71a36, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/20/04 at 07:09:31

Remove stray white spaces.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[f4a8ee1]1/*  Init
2 *
3 *  This routine is the initialization task for this test program.
4 *  It is called from init_exec and has the responsibility for creating
5 *  and starting the tasks that make up the test.  If the time of day
6 *  clock is required for the test, it should also be set to a known
7 *  value by this function.
8 *
9 *  Input parameters:  NONE
10 *
11 *  Output parameters:  NONE
12 *
13 *  COPYRIGHT (c) 1989-1997.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may in
17 *  the file LICENSE in this distribution or at
[3e26377b]18 *  http://www.rtems.com/license/LICENSE.
[f4a8ee1]19 *
20 *  $Id$
21 */
22
23#include "system.h"
24#include <stdio.h>
[d25d17b]25#include <stdlib.h>
[f4a8ee1]26
27void test3()
28{
29  rtems_status_code   result;
[4c84d7b]30  uint32_t      remove_task;
31  uint32_t      block;
32  uint32_t      task_count = 0;
[8f71a36]33
[f4a8ee1]34  char               c1 = 'a';
35  char               c2 = 'a';
36  char               c3 = '0';
37  char               c4 = '0';
[8f71a36]38
[f4a8ee1]39  printf( "\n TEST3 : free more than 3 x allocation size, but not the same block,\n"
40            "         then free a block\n");
41
42  /*
43   *  Check the value of the allocation unit
44   */
45
46  if (TASK_ALLOCATION_SIZE < 4)
47  {
48    printf( " FAIL3 : task allocation size must be greater than 4.\n");
49    exit( 1 );
50  }
[8f71a36]51
[f4a8ee1]52   /*
53   *  Allocate as many tasks as possible.
54   */
[8f71a36]55
[f4a8ee1]56  while (task_count < MAX_TASKS)
57  {
58    rtems_name name;
59
60    printf(" TEST3 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
[8f71a36]61
[f4a8ee1]62    name = rtems_build_name(c1, c2, c3, c4);
63
64    result = rtems_task_create(name,
65                               10,
[f59df6b2]66                               RTEMS_MINIMUM_STACK_SIZE,
[f4a8ee1]67                               RTEMS_DEFAULT_ATTRIBUTES,
68                               RTEMS_LOCAL,
69                               &task_id[task_count]);
70
71    if (status_code_bad(result))
72      break;
[8f71a36]73
[f4a8ee1]74    printf("number = %3i, id = %08x, starting, ", task_count, task_id[task_count]);
[f59df6b2]75    fflush(stdout);
[8f71a36]76
[f4a8ee1]77    result = rtems_task_start(task_id[task_count],
78                              test_task,
79                              (rtems_task_argument) task_count);
[8f71a36]80
[f4a8ee1]81    if (status_code_bad(result))
82      break;
[8f71a36]83
[f4a8ee1]84    /*
85     *  Update the name.
86     */
[8f71a36]87
[f4a8ee1]88    NEXT_TASK_NAME(c1, c2, c3, c4);
[8f71a36]89
[f4a8ee1]90    task_count++;
91  }
92
93  /*
94   *  Take out 3 tasks from each block of allocated tasks. Do this for
95   *  allocation size number of blocks.
96   */
97
98  if (task_count < (TASK_ALLOCATION_SIZE * 11))
99  {
100    printf( " FAIL3 : not enough tasks created -\n"
101            "         task created = %i, required number = %i\n",
102            task_count, (TASK_ALLOCATION_SIZE * 11));
103    exit( 1 );
104  }
105
106  for (block = 0; block < TASK_ALLOCATION_SIZE; block++)
107  {
108    for (remove_task = ((block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
109         remove_task < (((block * TASK_ALLOCATION_SIZE) + 3) - TASK_INDEX_OFFSET);
110         remove_task++)
111    {
112      if (!task_id[remove_task])
113      {
114        printf( " FAIL3 : remove task has a 0 id -\n"
115                "         task number = %i\n",
116                remove_task);
117        exit( 1 );
118      }
119
120      printf(" TEST3 : remove, signal task %08x, ", task_id[remove_task]);
121      rtems_event_send(task_id[remove_task], 1);
122      task_id[remove_task] = 0;
123    }
124  }
125
126  /*
127   *  Remove a complete block, not the first, forces a scan of the blocks in the
128   *  allocator's free routine
129   */
[8f71a36]130
[f4a8ee1]131  for (remove_task = (TASK_ALLOCATION_SIZE - TASK_INDEX_OFFSET);
132       remove_task < ((TASK_ALLOCATION_SIZE * 2) - - TASK_INDEX_OFFSET);
133       remove_task++)
134  {
135    if (task_id[remove_task])
136    {
137      printf(" TEST3 : remove, signal task %08x, ", task_id[remove_task]);
138      rtems_event_send(task_id[remove_task], 1);
139      task_id[remove_task] = 0;
140    }
141  }
[8f71a36]142
[f4a8ee1]143  destory_all_tasks("TEST3");
[8f71a36]144
[f4a8ee1]145  printf( " TEST3 : completed\n" );
146}
Note: See TracBrowser for help on using the repository browser.