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

Last change on this file was e71f0909, checked in by Joel Sherrill <joel@…>, on 04/07/22 at 16:13:34

testsuites/samples: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*  Init
4 *
5 *  This routine is the initialization task for this test program.
6 *  It is called from init_exec and has the responsibility for creating
7 *  and starting the tasks that make up the test.  If the time of day
8 *  clock is required for the test, it should also be set to a known
9 *  value by this function.
10 *
11 *  Input parameters:  NONE
12 *
13 *  Output parameters:  NONE
14 *
15 *  COPYRIGHT (c) 1989-1997.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 *    notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 *    notice, this list of conditions and the following disclaimer in the
25 *    documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#endif
43
44#include <inttypes.h>
45#include <stdio.h>
46#include <stdlib.h>
47
48#include "system.h"
49#include "tmacros.h"
50
51void test2()
52{
53  rtems_status_code   result;
54  uint32_t      remove_task;
55  uint32_t      task;
56  uint32_t      block;
57  uint32_t      task_count = 0;
58  rtems_id      removed_ids[TASK_ALLOCATION_SIZE * 2];
59
60  char               c1 = 'a';
61  char               c2 = 'a';
62  char               c3 = '0';
63  char               c4 = '0';
64
65  printf( "\n TEST2 : re-allocate of index numbers, and a block free'ed and one inactive\n" );
66
67  /*
68   *  Allocate enought tasks so the Inactive list is empty. Remember
69   *  to count the Init task, ie ... - 1.
70   */
71
72  while (task_count < ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET))
73  {
74    rtems_name name;
75
76    printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
77
78    name = rtems_build_name(c1, c2, c3, c4);
79
80    result = rtems_task_create(name,
81                               10,
82                               RTEMS_MINIMUM_STACK_SIZE,
83                               RTEMS_DEFAULT_ATTRIBUTES,
84                               RTEMS_LOCAL,
85                               &task_id[task_count]);
86
87    if (status_code_bad(result))
88      break;
89
90    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
91    fflush(stdout);
92
93    result = rtems_task_start(task_id[task_count],
94                              test_task,
95                              (rtems_task_argument) task_count);
96
97    if (status_code_bad(result))
98      break;
99
100    /*
101     *  Update the name.
102     */
103
104    NEXT_TASK_NAME(c1, c2, c3, c4);
105
106    task_count++;
107  }
108
109  /*
110   *  Take out the second and fourth allocation size block of tasks
111   */
112
113  if (task_count != ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) {
114    printf( " FAIL2 : not enough tasks created -\n"
115            "         task created = %" PRIi32 ", required number = %i\n",
116            task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET);
117    destroy_all_tasks("TEST2");
118    exit( 1 );
119  }
120
121  task = 0;
122
123  for (block = 1; block < 4; block += 2)
124  {
125    for (remove_task = (block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET;
126         remove_task < (((block + 1) * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
127         remove_task++)
128    {
129      if (!task_id[remove_task])
130      {
131        printf( " FAIL2 : remove task has a 0 id -\n"
132                "         task number = %" PRIi32 "\n",
133                remove_task);
134        destroy_all_tasks("TEST2");
135        exit( 1 );
136      }
137
138      /*
139       * Save the id's to match them against the reallocated ids
140       */
141
142      removed_ids[task++] = task_id[remove_task];
143
144      printf(" TEST2 : block %" PRIi32 " remove, signal task %08"
145               PRIxrtems_id ", ", block, task_id[remove_task]);
146      rtems_event_send(task_id[remove_task], 1);
147      task_id[remove_task] = 0;
148    }
149  }
150
151  for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++)
152  {
153    rtems_name       name;
154    uint32_t   id_slot;
155
156    /*
157     *  Find a free slot in the task id table.
158     */
159
160    for (id_slot = 0; id_slot < MAX_TASKS; id_slot++)
161      if (!task_id[id_slot])
162        break;
163
164    if (id_slot == MAX_TASKS)
165    {
166      printf( " FAIL2 : no free task id slot.\n");
167      destroy_all_tasks("TEST2");
168      exit( 1 );
169    }
170
171    printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
172
173    name = rtems_build_name(c1, c2, c3, c4);
174
175    result = rtems_task_create(name,
176                               10,
177                               RTEMS_MINIMUM_STACK_SIZE,
178                               RTEMS_DEFAULT_ATTRIBUTES,
179                               RTEMS_LOCAL,
180                               &task_id[id_slot]);
181
182    if (status_code_bad(result))
183    {
184      printf( " FAIL2 : re-creating a task -\n"
185              "         task number = %" PRIi32 "\n",
186              id_slot);
187      destroy_all_tasks("TEST2");
188      exit( 1 );
189    }
190
191    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ",
192           task_count, task_id[id_slot]);
193
194    result = rtems_task_start(task_id[id_slot],
195                              test_task,
196                              (rtems_task_argument) task_count);
197
198    if (status_code_bad(result))
199    {
200      printf( " FAIL : re-starting a task -\n"
201              "        task number = %" PRIi32 "\n",
202              id_slot);
203      destroy_all_tasks("TEST2");
204      exit( 1 );
205    }
206
207    /*
208     *  Update the name.
209     */
210
211    NEXT_TASK_NAME(c1, c2, c3, c4);
212
213    /*
214     *  Search the removed ids to see if it existed, clear the removed id
215     *  when found
216     */
217
218    for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++)
219      if (removed_ids[remove_task] == task_id[id_slot])
220      {
221        removed_ids[remove_task] = 0;
222        break;
223      }
224
225    /*
226     *  If not located in the removed id table, check and make sure it is not
227     *  already allocated
228     */
229
230    if (remove_task == (TASK_ALLOCATION_SIZE * 2))
231    {
232      uint32_t   allocated_id;
233
234      for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++)
235        if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id))
236        {
237          printf(
238            " FAIL2 : the new id is the same as an id already allocated -\n"
239            "         task id = %08" PRIxrtems_id "\n",
240            task_id[id_slot]);
241          exit( 1 );
242        }
243
244      printf( " FAIL2 : could not find the task id in the removed table -\n"
245              "         task id = %08" PRIxrtems_id "\n",
246              task_id[id_slot]);
247      exit( 1 );
248    }
249
250    task_count++;
251  }
252
253  destroy_all_tasks("TEST2");
254
255  printf( " TEST2 : completed\n" );
256}
Note: See TracBrowser for help on using the repository browser.