OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [tests/] [samples/] [unlimited/] [test2.c] - Blame information for rev 208

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*  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 208 chris
 *  $Id: test2.c,v 1.2 2001-09-27 12:02:29 chris Exp $
22 158 chris
 */
23
 
24
#include "system.h"
25
#include <stdio.h>
26
 
27
void 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
                               RTEMS_MINIMUM_STACK_SIZE,
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
    fflush(stdout);
68
 
69
    result = rtems_task_start(task_id[task_count],
70
                              test_task,
71
                              (rtems_task_argument) task_count);
72
 
73
    if (status_code_bad(result))
74
      break;
75
 
76
    /*
77
     *  Update the name.
78
     */
79
 
80
    NEXT_TASK_NAME(c1, c2, c3, c4);
81
 
82
    task_count++;
83
  }
84
 
85
  /*
86
   *  Take out the second and fourth allocation size block of tasks
87
   */
88
 
89
  if (task_count != ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) {
90
    printf( " FAIL2 : not enough tasks created -\n"
91
            "         task created = %i, required number = %i\n",
92
            task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET);
93
    destory_all_tasks("TEST2");
94
    exit( 1 );
95
  }
96
 
97
  task = 0;
98
 
99
  for (block = 1; block < 4; block += 2)
100
  {
101
    for (remove_task = (block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET;
102
         remove_task < (((block + 1) * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
103
         remove_task++)
104
    {
105
      if (!task_id[remove_task])
106
      {
107
        printf( " FAIL2 : remove task has a 0 id -\n"
108
                "         task number = %i\n",
109
                remove_task);
110
        destory_all_tasks("TEST2");
111
        exit( 1 );
112
      }
113
 
114
      /*
115
       * Save the id's to match them against the reallocated ids
116
       */
117
 
118
      removed_ids[task++] = task_id[remove_task];
119
 
120
      printf(" TEST2 : block %i remove, signal task %08x, ", block, task_id[remove_task]);
121
      rtems_event_send(task_id[remove_task], 1);
122
      task_id[remove_task] = 0;
123
    }
124
  }
125
 
126
  for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++)
127
  {
128
    rtems_name       name;
129
    rtems_unsigned32 id_slot;
130
 
131
    /*
132
     *  Find a free slot in the task id table.
133
     */
134
 
135
    for (id_slot = 0; id_slot < MAX_TASKS; id_slot++)
136
      if (!task_id[id_slot])
137
        break;
138
 
139
    if (id_slot == MAX_TASKS)
140
    {
141
      printf( " FAIL2 : no free task id slot.\n");
142
      destory_all_tasks("TEST2");
143
      exit( 1 );
144
    }
145
 
146
    printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
147
 
148
    name = rtems_build_name(c1, c2, c3, c4);
149
 
150
    result = rtems_task_create(name,
151
                               10,
152
                               RTEMS_MINIMUM_STACK_SIZE,
153
                               RTEMS_DEFAULT_ATTRIBUTES,
154
                               RTEMS_LOCAL,
155
                               &task_id[id_slot]);
156
 
157
    if (status_code_bad(result))
158
    {
159
      printf( " FAIL2 : re-creating a task -\n"
160
              "         task number = %i\n",
161
              id_slot);
162
      destory_all_tasks("TEST2");
163
      exit( 1 );
164
    }
165
 
166
    printf("number = %3i, id = %08x, starting, ", task_count, task_id[id_slot]);
167
 
168
    result = rtems_task_start(task_id[id_slot],
169
                              test_task,
170
                              (rtems_task_argument) task_count);
171
 
172
    if (status_code_bad(result))
173
    {
174
      printf( " FAIL : re-starting a task -\n"
175
              "        task number = %i\n",
176
              id_slot);
177
      destory_all_tasks("TEST2");
178
      exit( 1 );
179
    }
180
 
181
    /*
182
     *  Update the name.
183
     */
184
 
185
    NEXT_TASK_NAME(c1, c2, c3, c4);
186
 
187
    /*
188
     *  Search the removed ids to see if it existed, clear the removed id when found
189
     */
190
 
191
    for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++)
192
      if (removed_ids[remove_task] == task_id[id_slot])
193
      {
194
        removed_ids[remove_task] = 0;
195
        break;
196
      }
197
 
198
    /*
199
     *  If not located in the removed id table, check and make sure it is not
200
     *  already allocated
201
     */
202
 
203
    if (remove_task == (TASK_ALLOCATION_SIZE * 2))
204
    {
205
      rtems_unsigned32 allocated_id;
206
 
207
      for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++)
208
        if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id))
209
        {
210
          printf( " FAIL2 : the new id is the same as an id already allocated -\n"
211
                  "         task id = %08x\n",
212
                  task_id[id_slot]);
213
          exit( 1 );
214
        }
215
 
216
      printf( " FAIL2 : could not find the task id in the removed table -\n"
217
              "         task id = %08x\n",
218
              task_id[id_slot]);
219
      exit( 1 );
220
    }
221
 
222
    task_count++;
223
  }
224
 
225
  destory_all_tasks("TEST2");
226
 
227
  printf( " TEST2 : completed\n" );
228
}
229
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.