source: rtems/testsuites/samples/unlimited/test3.c @ e313551

4.115
Last change on this file since e313551 was e313551, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 10:58:44

Add HAVE_CONFIG_H.

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