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 | |
---|
32 | void 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 | destroy_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 | destroy_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" |
---|
126 | PRIxrtems_id ", ", block, task_id[remove_task]); |
---|
127 | rtems_event_send(task_id[remove_task], 1); |
---|
128 | task_id[remove_task] = 0; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++) |
---|
133 | { |
---|
134 | rtems_name name; |
---|
135 | uint32_t id_slot; |
---|
136 | |
---|
137 | /* |
---|
138 | * Find a free slot in the task id table. |
---|
139 | */ |
---|
140 | |
---|
141 | for (id_slot = 0; id_slot < MAX_TASKS; id_slot++) |
---|
142 | if (!task_id[id_slot]) |
---|
143 | break; |
---|
144 | |
---|
145 | if (id_slot == MAX_TASKS) |
---|
146 | { |
---|
147 | printf( " FAIL2 : no free task id slot.\n"); |
---|
148 | destroy_all_tasks("TEST2"); |
---|
149 | exit( 1 ); |
---|
150 | } |
---|
151 | |
---|
152 | printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4); |
---|
153 | |
---|
154 | name = rtems_build_name(c1, c2, c3, c4); |
---|
155 | |
---|
156 | result = rtems_task_create(name, |
---|
157 | 10, |
---|
158 | RTEMS_MINIMUM_STACK_SIZE, |
---|
159 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
160 | RTEMS_LOCAL, |
---|
161 | &task_id[id_slot]); |
---|
162 | |
---|
163 | if (status_code_bad(result)) |
---|
164 | { |
---|
165 | printf( " FAIL2 : re-creating a task -\n" |
---|
166 | " task number = %" PRIi32 "\n", |
---|
167 | id_slot); |
---|
168 | destroy_all_tasks("TEST2"); |
---|
169 | exit( 1 ); |
---|
170 | } |
---|
171 | |
---|
172 | printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", |
---|
173 | 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 | destroy_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 |
---|
196 | * when found |
---|
197 | */ |
---|
198 | |
---|
199 | for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++) |
---|
200 | if (removed_ids[remove_task] == task_id[id_slot]) |
---|
201 | { |
---|
202 | removed_ids[remove_task] = 0; |
---|
203 | break; |
---|
204 | } |
---|
205 | |
---|
206 | /* |
---|
207 | * If not located in the removed id table, check and make sure it is not |
---|
208 | * already allocated |
---|
209 | */ |
---|
210 | |
---|
211 | if (remove_task == (TASK_ALLOCATION_SIZE * 2)) |
---|
212 | { |
---|
213 | uint32_t allocated_id; |
---|
214 | |
---|
215 | for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++) |
---|
216 | if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id)) |
---|
217 | { |
---|
218 | printf( |
---|
219 | " FAIL2 : the new id is the same as an id already allocated -\n" |
---|
220 | " task id = %08" PRIxrtems_id "\n", |
---|
221 | task_id[id_slot]); |
---|
222 | exit( 1 ); |
---|
223 | } |
---|
224 | |
---|
225 | printf( " FAIL2 : could not find the task id in the removed table -\n" |
---|
226 | " task id = %08" PRIxrtems_id "\n", |
---|
227 | task_id[id_slot]); |
---|
228 | exit( 1 ); |
---|
229 | } |
---|
230 | |
---|
231 | task_count++; |
---|
232 | } |
---|
233 | |
---|
234 | destroy_all_tasks("TEST2"); |
---|
235 | |
---|
236 | printf( " TEST2 : completed\n" ); |
---|
237 | } |
---|