source: rtems/testsuites/samples/unlimited/test3.c @ 732276e

4.104.115
Last change on this file since 732276e was 732276e, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/26/09 at 11:34:27

Include "tmacros.h". Use PRIxrtems_id to print rtems_ids.

  • Property mode set to 100644
File size: 3.8 KB
Line 
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.com/license/LICENSE.
19 *
20 *  $Id$
21 */
22
23#include <inttypes.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include "system.h"
27#include "tmacros.h"
28
29void test3()
30{
31  rtems_status_code   result;
32  uint32_t      remove_task;
33  uint32_t      block;
34  uint32_t      task_count = 0;
35
36  char               c1 = 'a';
37  char               c2 = 'a';
38  char               c3 = '0';
39  char               c4 = '0';
40
41  printf( "\n TEST3 : free more than 3 x allocation size, but not the same block,\n"
42            "         then free a block\n");
43
44  /*
45   *  Check the value of the allocation unit
46   */
47
48  if (TASK_ALLOCATION_SIZE < 4)
49  {
50    printf( " FAIL3 : task allocation size must be greater than 4.\n");
51    exit( 1 );
52  }
53
54   /*
55   *  Allocate as many tasks as possible.
56   */
57
58  while (task_count < MAX_TASKS)
59  {
60    rtems_name name;
61
62    printf(" TEST3 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
63
64    name = rtems_build_name(c1, c2, c3, c4);
65
66    result = rtems_task_create(name,
67                               10,
68                               RTEMS_MINIMUM_STACK_SIZE,
69                               RTEMS_DEFAULT_ATTRIBUTES,
70                               RTEMS_LOCAL,
71                               &task_id[task_count]);
72
73    if (status_code_bad(result))
74      break;
75
76    printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
77    fflush(stdout);
78
79    result = rtems_task_start(task_id[task_count],
80                              test_task,
81                              (rtems_task_argument) task_count);
82
83    if (status_code_bad(result))
84      break;
85
86    /*
87     *  Update the name.
88     */
89
90    NEXT_TASK_NAME(c1, c2, c3, c4);
91
92    task_count++;
93  }
94
95  /*
96   *  Take out 3 tasks from each block of allocated tasks. Do this for
97   *  allocation size number of blocks.
98   */
99
100  if (task_count < (TASK_ALLOCATION_SIZE * 11))
101  {
102    printf( " FAIL3 : not enough tasks created -\n"
103            "         task created = %" PRIi32 ", required number = %i\n",
104            task_count, (TASK_ALLOCATION_SIZE * 11));
105    exit( 1 );
106  }
107
108  for (block = 0; block < TASK_ALLOCATION_SIZE; block++)
109  {
110    for (remove_task = ((block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
111         remove_task < (((block * TASK_ALLOCATION_SIZE) + 3) - TASK_INDEX_OFFSET);
112         remove_task++)
113    {
114      if (!task_id[remove_task])
115      {
116        printf( " FAIL3 : remove task has a 0 id -\n"
117                "         task number = %" PRIi32 "\n",
118                remove_task);
119        exit( 1 );
120      }
121
122      printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]);
123      rtems_event_send(task_id[remove_task], 1);
124      task_id[remove_task] = 0;
125    }
126  }
127
128  /*
129   *  Remove a complete block, not the first, forces a scan of the blocks in the
130   *  allocator's free routine
131   */
132
133  for (remove_task = (TASK_ALLOCATION_SIZE - TASK_INDEX_OFFSET);
134       remove_task < ((TASK_ALLOCATION_SIZE * 2) - - TASK_INDEX_OFFSET);
135       remove_task++)
136  {
137    if (task_id[remove_task])
138    {
139      printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]);
140      rtems_event_send(task_id[remove_task], 1);
141      task_id[remove_task] = 0;
142    }
143  }
144
145  destory_all_tasks("TEST3");
146
147  printf( " TEST3 : completed\n" );
148}
Note: See TracBrowser for help on using the repository browser.