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 | #include "system.h" |
---|
48 | #include "tmacros.h" |
---|
49 | |
---|
50 | void test3() |
---|
51 | { |
---|
52 | rtems_status_code result; |
---|
53 | uint32_t remove_task; |
---|
54 | uint32_t block; |
---|
55 | uint32_t task_count = 0; |
---|
56 | |
---|
57 | char c1 = 'a'; |
---|
58 | char c2 = 'a'; |
---|
59 | char c3 = '0'; |
---|
60 | char c4 = '0'; |
---|
61 | |
---|
62 | printf( "\n TEST3 : free more than 3 x allocation size, but not the same block,\n" |
---|
63 | " then free a block\n"); |
---|
64 | |
---|
65 | /* |
---|
66 | * Check the value of the allocation unit |
---|
67 | */ |
---|
68 | |
---|
69 | if (TASK_ALLOCATION_SIZE < 4) |
---|
70 | { |
---|
71 | printf( " FAIL3 : task allocation size must be greater than 4.\n"); |
---|
72 | exit( 1 ); |
---|
73 | } |
---|
74 | |
---|
75 | /* |
---|
76 | * Allocate as many tasks as possible. |
---|
77 | */ |
---|
78 | |
---|
79 | while (task_count < MAX_TASKS) |
---|
80 | { |
---|
81 | rtems_name name; |
---|
82 | |
---|
83 | printf(" TEST3 : creating task '%c%c%c%c', ", c1, c2, c3, c4); |
---|
84 | |
---|
85 | name = rtems_build_name(c1, c2, c3, c4); |
---|
86 | |
---|
87 | result = rtems_task_create(name, |
---|
88 | 10, |
---|
89 | RTEMS_MINIMUM_STACK_SIZE, |
---|
90 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
91 | RTEMS_LOCAL, |
---|
92 | &task_id[task_count]); |
---|
93 | |
---|
94 | if (status_code_bad(result)) |
---|
95 | break; |
---|
96 | |
---|
97 | printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]); |
---|
98 | fflush(stdout); |
---|
99 | |
---|
100 | result = rtems_task_start(task_id[task_count], |
---|
101 | test_task, |
---|
102 | (rtems_task_argument) task_count); |
---|
103 | |
---|
104 | if (status_code_bad(result)) |
---|
105 | break; |
---|
106 | |
---|
107 | /* |
---|
108 | * Update the name. |
---|
109 | */ |
---|
110 | |
---|
111 | NEXT_TASK_NAME(c1, c2, c3, c4); |
---|
112 | |
---|
113 | task_count++; |
---|
114 | } |
---|
115 | |
---|
116 | /* |
---|
117 | * Take out 3 tasks from each block of allocated tasks. Do this for |
---|
118 | * allocation size number of blocks. |
---|
119 | */ |
---|
120 | |
---|
121 | if (task_count < (TASK_ALLOCATION_SIZE * 11)) |
---|
122 | { |
---|
123 | printf( " FAIL3 : not enough tasks created -\n" |
---|
124 | " task created = %" PRIi32 ", required number = %i\n", |
---|
125 | task_count, (TASK_ALLOCATION_SIZE * 11)); |
---|
126 | exit( 1 ); |
---|
127 | } |
---|
128 | |
---|
129 | for (block = 0; block < TASK_ALLOCATION_SIZE; block++) |
---|
130 | { |
---|
131 | for (remove_task = ((block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET); |
---|
132 | remove_task < (((block * TASK_ALLOCATION_SIZE) + 3) - TASK_INDEX_OFFSET); |
---|
133 | remove_task++) |
---|
134 | { |
---|
135 | if (!task_id[remove_task]) |
---|
136 | { |
---|
137 | printf( " FAIL3 : remove task has a 0 id -\n" |
---|
138 | " task number = %" PRIi32 "\n", |
---|
139 | remove_task); |
---|
140 | exit( 1 ); |
---|
141 | } |
---|
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 | /* |
---|
150 | * Remove a complete block, not the first, forces a scan of the blocks in the |
---|
151 | * allocator's free routine |
---|
152 | */ |
---|
153 | |
---|
154 | for (remove_task = (TASK_ALLOCATION_SIZE - TASK_INDEX_OFFSET); |
---|
155 | remove_task < ((TASK_ALLOCATION_SIZE * 2) - - TASK_INDEX_OFFSET); |
---|
156 | remove_task++) |
---|
157 | { |
---|
158 | if (task_id[remove_task]) |
---|
159 | { |
---|
160 | printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]); |
---|
161 | rtems_event_send(task_id[remove_task], 1); |
---|
162 | task_id[remove_task] = 0; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | destroy_all_tasks("TEST3"); |
---|
167 | |
---|
168 | printf( " TEST3 : completed\n" ); |
---|
169 | } |
---|