source: rtems/testsuites/samples/unlimited/test2.c @ 51a95ff9

4.115
Last change on this file since 51a95ff9 was 51a95ff9, checked in by Joel Sherrill <joel.sherrill@…>, on 10/07/14 at 22:43:18

samples/unlimited: Fix printf() warning and clean up

  • Property mode set to 100644
File size: 6.2 KB
RevLine 
[f4a8ee1]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
[c499856]18 *  http://www.rtems.org/license/LICENSE.
[f4a8ee1]19 */
20
[e313551]21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
[9b86291b]25#include <inttypes.h>
[f4a8ee1]26#include <stdio.h>
[d25d17b]27#include <stdlib.h>
[f4a8ee1]28
[9b86291b]29#include "system.h"
[732276e]30#include "tmacros.h"
[9b86291b]31
[f4a8ee1]32void test2()
33{
34  rtems_status_code   result;
[4c84d7b]35  uint32_t      remove_task;
36  uint32_t      task;
37  uint32_t      block;
38  uint32_t      task_count = 0;
[c39d81bc]39  rtems_id      removed_ids[TASK_ALLOCATION_SIZE * 2];
[8f71a36]40
[f4a8ee1]41  char               c1 = 'a';
42  char               c2 = 'a';
43  char               c3 = '0';
44  char               c4 = '0';
[8f71a36]45
[f4a8ee1]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   */
[8f71a36]52
[f4a8ee1]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);
[8f71a36]58
[f4a8ee1]59    name = rtems_build_name(c1, c2, c3, c4);
60
61    result = rtems_task_create(name,
62                               10,
[f59df6b2]63                               RTEMS_MINIMUM_STACK_SIZE,
[f4a8ee1]64                               RTEMS_DEFAULT_ATTRIBUTES,
65                               RTEMS_LOCAL,
66                               &task_id[task_count]);
67
68    if (status_code_bad(result))
69      break;
[8f71a36]70
[732276e]71    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
[f59df6b2]72    fflush(stdout);
[8f71a36]73
[f4a8ee1]74    result = rtems_task_start(task_id[task_count],
75                              test_task,
76                              (rtems_task_argument) task_count);
[8f71a36]77
[f4a8ee1]78    if (status_code_bad(result))
79      break;
[8f71a36]80
[f4a8ee1]81    /*
82     *  Update the name.
83     */
[8f71a36]84
[f4a8ee1]85    NEXT_TASK_NAME(c1, c2, c3, c4);
[8f71a36]86
[f4a8ee1]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"
[9b86291b]96            "         task created = %" PRIi32 ", required number = %i\n",
[f4a8ee1]97            task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET);
[51a95ff9]98    destroy_all_tasks("TEST2");
[f4a8ee1]99    exit( 1 );
100  }
101
102  task = 0;
[8f71a36]103
[f4a8ee1]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"
[9b86291b]113                "         task number = %" PRIi32 "\n",
[f4a8ee1]114                remove_task);
[51a95ff9]115        destroy_all_tasks("TEST2");
[f4a8ee1]116        exit( 1 );
117      }
118
119      /*
120       * Save the id's to match them against the reallocated ids
121       */
[8f71a36]122
[f4a8ee1]123      removed_ids[task++] = task_id[remove_task];
[8f71a36]124
[51a95ff9]125      printf(" TEST2 : block %" PRIi32 " remove, signal task %08"
126               PRIxrtems_id ", ", block, task_id[remove_task]);
[f4a8ee1]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;
[4c84d7b]135    uint32_t   id_slot;
[f4a8ee1]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;
[8f71a36]144
[f4a8ee1]145    if (id_slot == MAX_TASKS)
146    {
147      printf( " FAIL2 : no free task id slot.\n");
[51a95ff9]148      destroy_all_tasks("TEST2");
[f4a8ee1]149      exit( 1 );
150    }
151
152    printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
[8f71a36]153
[f4a8ee1]154    name = rtems_build_name(c1, c2, c3, c4);
155
156    result = rtems_task_create(name,
157                               10,
[f59df6b2]158                               RTEMS_MINIMUM_STACK_SIZE,
[f4a8ee1]159                               RTEMS_DEFAULT_ATTRIBUTES,
160                               RTEMS_LOCAL,
161                               &task_id[id_slot]);
[8f71a36]162
[f4a8ee1]163    if (status_code_bad(result))
164    {
165      printf( " FAIL2 : re-creating a task -\n"
[9b86291b]166              "         task number = %" PRIi32 "\n",
[f4a8ee1]167              id_slot);
[51a95ff9]168      destroy_all_tasks("TEST2");
[f4a8ee1]169      exit( 1 );
170    }
[8f71a36]171
[51a95ff9]172    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ",
173           task_count, task_id[id_slot]);
[8f71a36]174
[f4a8ee1]175    result = rtems_task_start(task_id[id_slot],
176                              test_task,
177                              (rtems_task_argument) task_count);
[8f71a36]178
[f4a8ee1]179    if (status_code_bad(result))
180    {
181      printf( " FAIL : re-starting a task -\n"
[9b86291b]182              "        task number = %" PRIi32 "\n",
[f4a8ee1]183              id_slot);
[51a95ff9]184      destroy_all_tasks("TEST2");
[f4a8ee1]185      exit( 1 );
186    }
[8f71a36]187
[f4a8ee1]188    /*
189     *  Update the name.
190     */
[8f71a36]191
[f4a8ee1]192    NEXT_TASK_NAME(c1, c2, c3, c4);
[8f71a36]193
[f4a8ee1]194    /*
[51a95ff9]195     *  Search the removed ids to see if it existed, clear the removed id
196     *  when found
[f4a8ee1]197     */
[8f71a36]198
[f4a8ee1]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     */
[8f71a36]210
[f4a8ee1]211    if (remove_task == (TASK_ALLOCATION_SIZE * 2))
212    {
[4c84d7b]213      uint32_t   allocated_id;
[8f71a36]214
[f4a8ee1]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        {
[51a95ff9]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]);
[f4a8ee1]222          exit( 1 );
223        }
[8f71a36]224
[f4a8ee1]225      printf( " FAIL2 : could not find the task id in the removed table -\n"
[732276e]226              "         task id = %08" PRIxrtems_id "\n",
[f4a8ee1]227              task_id[id_slot]);
228      exit( 1 );
229    }
230
231    task_count++;
232  }
[8f71a36]233
[51a95ff9]234  destroy_all_tasks("TEST2");
[8f71a36]235
[f4a8ee1]236  printf( " TEST2 : completed\n" );
237}
Note: See TracBrowser for help on using the repository browser.