File indexing completed on 2025-05-11 08:24:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043
0044 #include <inttypes.h>
0045 #include <stdio.h>
0046 #include <stdlib.h>
0047
0048 #include "system.h"
0049 #include "tmacros.h"
0050
0051 void test2()
0052 {
0053 rtems_status_code result;
0054 uint32_t remove_task;
0055 uint32_t task;
0056 uint32_t block;
0057 uint32_t task_count = 0;
0058 rtems_id removed_ids[TASK_ALLOCATION_SIZE * 2];
0059
0060 char c1 = 'a';
0061 char c2 = 'a';
0062 char c3 = '0';
0063 char c4 = '0';
0064
0065 printf( "\n TEST2 : re-allocate of index numbers, and a block free'ed and one inactive\n" );
0066
0067
0068
0069
0070
0071
0072 while (task_count < ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET))
0073 {
0074 rtems_name name;
0075
0076 printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
0077
0078 name = rtems_build_name(c1, c2, c3, c4);
0079
0080 result = rtems_task_create(name,
0081 10,
0082 RTEMS_MINIMUM_STACK_SIZE,
0083 RTEMS_DEFAULT_ATTRIBUTES,
0084 RTEMS_LOCAL,
0085 &task_id[task_count]);
0086
0087 if (status_code_bad(result))
0088 break;
0089
0090 printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
0091 fflush(stdout);
0092
0093 result = rtems_task_start(task_id[task_count],
0094 test_task,
0095 (rtems_task_argument) task_count);
0096
0097 if (status_code_bad(result))
0098 break;
0099
0100
0101
0102
0103
0104 NEXT_TASK_NAME(c1, c2, c3, c4);
0105
0106 task_count++;
0107 }
0108
0109
0110
0111
0112
0113 if (task_count != ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) {
0114 printf( " FAIL2 : not enough tasks created -\n"
0115 " task created = %" PRIi32 ", required number = %i\n",
0116 task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET);
0117 destroy_all_tasks("TEST2");
0118 exit( 1 );
0119 }
0120
0121 task = 0;
0122
0123 for (block = 1; block < 4; block += 2)
0124 {
0125 for (remove_task = (block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET;
0126 remove_task < (((block + 1) * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
0127 remove_task++)
0128 {
0129 if (!task_id[remove_task])
0130 {
0131 printf( " FAIL2 : remove task has a 0 id -\n"
0132 " task number = %" PRIi32 "\n",
0133 remove_task);
0134 destroy_all_tasks("TEST2");
0135 exit( 1 );
0136 }
0137
0138
0139
0140
0141
0142 removed_ids[task++] = task_id[remove_task];
0143
0144 printf(" TEST2 : block %" PRIi32 " remove, signal task %08"
0145 PRIxrtems_id ", ", block, task_id[remove_task]);
0146 rtems_event_send(task_id[remove_task], 1);
0147 task_id[remove_task] = 0;
0148 }
0149 }
0150
0151 for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++)
0152 {
0153 rtems_name name;
0154 uint32_t id_slot;
0155
0156
0157
0158
0159
0160 for (id_slot = 0; id_slot < MAX_TASKS; id_slot++)
0161 if (!task_id[id_slot])
0162 break;
0163
0164 if (id_slot == MAX_TASKS)
0165 {
0166 printf( " FAIL2 : no free task id slot.\n");
0167 destroy_all_tasks("TEST2");
0168 exit( 1 );
0169 }
0170
0171 printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
0172
0173 name = rtems_build_name(c1, c2, c3, c4);
0174
0175 result = rtems_task_create(name,
0176 10,
0177 RTEMS_MINIMUM_STACK_SIZE,
0178 RTEMS_DEFAULT_ATTRIBUTES,
0179 RTEMS_LOCAL,
0180 &task_id[id_slot]);
0181
0182 if (status_code_bad(result))
0183 {
0184 printf( " FAIL2 : re-creating a task -\n"
0185 " task number = %" PRIi32 "\n",
0186 id_slot);
0187 destroy_all_tasks("TEST2");
0188 exit( 1 );
0189 }
0190
0191 printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ",
0192 task_count, task_id[id_slot]);
0193
0194 result = rtems_task_start(task_id[id_slot],
0195 test_task,
0196 (rtems_task_argument) task_count);
0197
0198 if (status_code_bad(result))
0199 {
0200 printf( " FAIL : re-starting a task -\n"
0201 " task number = %" PRIi32 "\n",
0202 id_slot);
0203 destroy_all_tasks("TEST2");
0204 exit( 1 );
0205 }
0206
0207
0208
0209
0210
0211 NEXT_TASK_NAME(c1, c2, c3, c4);
0212
0213
0214
0215
0216
0217
0218 for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++)
0219 if (removed_ids[remove_task] == task_id[id_slot])
0220 {
0221 removed_ids[remove_task] = 0;
0222 break;
0223 }
0224
0225
0226
0227
0228
0229
0230 if (remove_task == (TASK_ALLOCATION_SIZE * 2))
0231 {
0232 uint32_t allocated_id;
0233
0234 for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++)
0235 if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id))
0236 {
0237 printf(
0238 " FAIL2 : the new id is the same as an id already allocated -\n"
0239 " task id = %08" PRIxrtems_id "\n",
0240 task_id[id_slot]);
0241 exit( 1 );
0242 }
0243
0244 printf( " FAIL2 : could not find the task id in the removed table -\n"
0245 " task id = %08" PRIxrtems_id "\n",
0246 task_id[id_slot]);
0247 exit( 1 );
0248 }
0249
0250 task_count++;
0251 }
0252
0253 destroy_all_tasks("TEST2");
0254
0255 printf( " TEST2 : completed\n" );
0256 }