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

4.11
Last change on this file since 51a95ff9 was 51a95ff9, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 7, 2014 at 10:43:18 PM

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

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