source: rtems/testsuites/samples/unlimited/test2.c @ 3a9d9e1

4.115
Last change on this file since 3a9d9e1 was e313551, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 10:58:44

Add HAVE_CONFIG_H.

  • Property mode set to 100644
File size: 6.2 KB
Line 
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
18 *  http://www.rtems.com/license/LICENSE.
19 *
20 *  $Id$
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <inttypes.h>
28#include <stdio.h>
29#include <stdlib.h>
30
31#include "system.h"
32#include "tmacros.h"
33
34void test2()
35{
36  rtems_status_code   result;
37  uint32_t      remove_task;
38  uint32_t      task;
39  uint32_t      block;
40  uint32_t      task_count = 0;
41  rtems_id      removed_ids[TASK_ALLOCATION_SIZE * 2];
42
43  char               c1 = 'a';
44  char               c2 = 'a';
45  char               c3 = '0';
46  char               c4 = '0';
47
48  printf( "\n TEST2 : re-allocate of index numbers, and a block free'ed and one inactive\n" );
49
50  /*
51   *  Allocate enought tasks so the Inactive list is empty. Remember
52   *  to count the Init task, ie ... - 1.
53   */
54
55  while (task_count < ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET))
56  {
57    rtems_name name;
58
59    printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
60
61    name = rtems_build_name(c1, c2, c3, c4);
62
63    result = rtems_task_create(name,
64                               10,
65                               RTEMS_MINIMUM_STACK_SIZE,
66                               RTEMS_DEFAULT_ATTRIBUTES,
67                               RTEMS_LOCAL,
68                               &task_id[task_count]);
69
70    if (status_code_bad(result))
71      break;
72
73    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
74    fflush(stdout);
75
76    result = rtems_task_start(task_id[task_count],
77                              test_task,
78                              (rtems_task_argument) task_count);
79
80    if (status_code_bad(result))
81      break;
82
83    /*
84     *  Update the name.
85     */
86
87    NEXT_TASK_NAME(c1, c2, c3, c4);
88
89    task_count++;
90  }
91
92  /*
93   *  Take out the second and fourth allocation size block of tasks
94   */
95
96  if (task_count != ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) {
97    printf( " FAIL2 : not enough tasks created -\n"
98            "         task created = %" PRIi32 ", required number = %i\n",
99            task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET);
100    destory_all_tasks("TEST2");
101    exit( 1 );
102  }
103
104  task = 0;
105
106  for (block = 1; block < 4; block += 2)
107  {
108    for (remove_task = (block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET;
109         remove_task < (((block + 1) * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
110         remove_task++)
111    {
112      if (!task_id[remove_task])
113      {
114        printf( " FAIL2 : remove task has a 0 id -\n"
115                "         task number = %" PRIi32 "\n",
116                remove_task);
117        destory_all_tasks("TEST2");
118        exit( 1 );
119      }
120
121      /*
122       * Save the id's to match them against the reallocated ids
123       */
124
125      removed_ids[task++] = task_id[remove_task];
126
127      printf(" TEST2 : block %" PRIi32 " remove, signal task %08" PRIxrtems_id ", ", block, task_id[remove_task]);
128      rtems_event_send(task_id[remove_task], 1);
129      task_id[remove_task] = 0;
130    }
131  }
132
133  for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++)
134  {
135    rtems_name       name;
136    uint32_t   id_slot;
137
138    /*
139     *  Find a free slot in the task id table.
140     */
141
142    for (id_slot = 0; id_slot < MAX_TASKS; id_slot++)
143      if (!task_id[id_slot])
144        break;
145
146    if (id_slot == MAX_TASKS)
147    {
148      printf( " FAIL2 : no free task id slot.\n");
149      destory_all_tasks("TEST2");
150      exit( 1 );
151    }
152
153    printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
154
155    name = rtems_build_name(c1, c2, c3, c4);
156
157    result = rtems_task_create(name,
158                               10,
159                               RTEMS_MINIMUM_STACK_SIZE,
160                               RTEMS_DEFAULT_ATTRIBUTES,
161                               RTEMS_LOCAL,
162                               &task_id[id_slot]);
163
164    if (status_code_bad(result))
165    {
166      printf( " FAIL2 : re-creating a task -\n"
167              "         task number = %" PRIi32 "\n",
168              id_slot);
169      destory_all_tasks("TEST2");
170      exit( 1 );
171    }
172
173    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[id_slot]);
174
175    result = rtems_task_start(task_id[id_slot],
176                              test_task,
177                              (rtems_task_argument) task_count);
178
179    if (status_code_bad(result))
180    {
181      printf( " FAIL : re-starting a task -\n"
182              "        task number = %" PRIi32 "\n",
183              id_slot);
184      destory_all_tasks("TEST2");
185      exit( 1 );
186    }
187
188    /*
189     *  Update the name.
190     */
191
192    NEXT_TASK_NAME(c1, c2, c3, c4);
193
194    /*
195     *  Search the removed ids to see if it existed, clear the removed id when found
196     */
197
198    for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++)
199      if (removed_ids[remove_task] == task_id[id_slot])
200      {
201        removed_ids[remove_task] = 0;
202        break;
203      }
204
205    /*
206     *  If not located in the removed id table, check and make sure it is not
207     *  already allocated
208     */
209
210    if (remove_task == (TASK_ALLOCATION_SIZE * 2))
211    {
212      uint32_t   allocated_id;
213
214      for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++)
215        if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id))
216        {
217          printf( " FAIL2 : the new id is the same as an id already allocated -\n"
218                  "         task id = %08" PRIxrtems_id "\n",
219                  task_id[id_slot]);
220          exit( 1 );
221        }
222
223      printf( " FAIL2 : could not find the task id in the removed table -\n"
224              "         task id = %08" PRIxrtems_id "\n",
225              task_id[id_slot]);
226      exit( 1 );
227    }
228
229    task_count++;
230  }
231
232  destory_all_tasks("TEST2");
233
234  printf( " TEST2 : completed\n" );
235}
Note: See TracBrowser for help on using the repository browser.