source: rtems/testsuites/samples/unlimited/test2.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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