source: rtems/c/src/tests/samples/unlimited/test2.c @ f4a8ee1

4.104.114.84.95
Last change on this file since f4a8ee1 was f4a8ee1, checked in by Joel Sherrill <joel.sherrill@…>, on 03/17/99 at 16:01:03

Unlimited objects patch from Chris Johns <ccj@…>. Email follows:

First, the unlimited patch. I have compiled the unlmited patch for the
Linux posix BSP only and it seems to work cleanly. I would like a really
major application run on this change before commiting as the changes are
very core and significant. I am currently building all the tests to run.

I have no targets suitable to test on at the moment.

I have tested the patch for inline functions and macros.

Turning macros on has found some core bugs. I have fixed these but have
not run all the tests. Please review the patch for these changes. They
are:

1) The conditional compilation for MP support broke the core messages
code. You cannot embed a conditional macro in another macro. The Send
and Urgent Send calls are macros.

2) User extensions handler initialisation now has two parameters. I have
updated the macros to support the extra parameter.

The patch also contains the gcc-target-default.cfg fix required to build
the kernel. More of a by product than a fix for you.

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