1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2013. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #define CONFIGURE_INIT |
---|
15 | #include "system.h" |
---|
16 | |
---|
17 | const char rtems_test_name[] = "SPREGION_ERR 1"; |
---|
18 | |
---|
19 | rtems_name Region_name[ 2 ]; /* array of region names */ |
---|
20 | rtems_id Region_id[ 2 ]; /* array of region ids */ |
---|
21 | |
---|
22 | uint32_t Region_good_area[4096] CPU_STRUCTURE_ALIGNMENT; |
---|
23 | #define Region_bad_area (void *) 0x00000005 |
---|
24 | #define REGION_START_OFFSET 1024 |
---|
25 | #define REGION_LENGTH 512 |
---|
26 | |
---|
27 | /* to avoid warnings */ |
---|
28 | void region_error_tests(void); |
---|
29 | |
---|
30 | void region_error_tests(void) |
---|
31 | { |
---|
32 | void *segment_address_1; |
---|
33 | void *segment_address_2; |
---|
34 | void *segment_address_3; |
---|
35 | uintptr_t segment_size; |
---|
36 | rtems_status_code status; |
---|
37 | Heap_Information_block the_info; |
---|
38 | rtems_id junk_id; |
---|
39 | |
---|
40 | Region_name[ 1 ] = rtems_build_name( 'R', 'N', '1', ' ' ); |
---|
41 | |
---|
42 | /* Check invalid name error case */ |
---|
43 | status = rtems_region_create( |
---|
44 | 0, |
---|
45 | Region_good_area, |
---|
46 | 0x40, |
---|
47 | 32, |
---|
48 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
49 | &junk_id |
---|
50 | ); |
---|
51 | fatal_directive_status( |
---|
52 | status, |
---|
53 | RTEMS_INVALID_NAME, |
---|
54 | "rtems_region_create with illegal name" |
---|
55 | ); |
---|
56 | puts( "TA1 - rtems_region_create - RTEMS_INVALID_NAME" ); |
---|
57 | |
---|
58 | /* Check NULL starting address error case */ |
---|
59 | status = rtems_region_create( |
---|
60 | Region_name[ 1 ], |
---|
61 | NULL, |
---|
62 | 0x40, |
---|
63 | 32, |
---|
64 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
65 | &junk_id |
---|
66 | ); |
---|
67 | fatal_directive_status( |
---|
68 | status, |
---|
69 | RTEMS_INVALID_ADDRESS, |
---|
70 | "rtems_region_create with NULL address" |
---|
71 | ); |
---|
72 | puts( "TA1 - rtems_region_create - RTEMS_INVALID_ADDRESS" ); |
---|
73 | |
---|
74 | /* Invalid size */ |
---|
75 | status = rtems_region_create( |
---|
76 | Region_name[ 1 ], |
---|
77 | Region_good_area, |
---|
78 | 0, |
---|
79 | 0, |
---|
80 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
81 | &junk_id |
---|
82 | ); |
---|
83 | fatal_directive_status( |
---|
84 | status, |
---|
85 | RTEMS_INVALID_SIZE, |
---|
86 | "rtems_region_create with illegal size" |
---|
87 | ); |
---|
88 | puts( "TA1 - rtems_region_create - RTEMS_INVALID_SIZE" ); |
---|
89 | |
---|
90 | /* Check NULL id error case */ |
---|
91 | status = rtems_region_create( |
---|
92 | Region_name[ 1 ], |
---|
93 | Region_good_area, |
---|
94 | REGION_LENGTH, |
---|
95 | 0x40, |
---|
96 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
97 | NULL |
---|
98 | ); |
---|
99 | fatal_directive_status( |
---|
100 | status, |
---|
101 | RTEMS_INVALID_ADDRESS, |
---|
102 | "rtems_region_create with NULL id" |
---|
103 | ); |
---|
104 | puts( "TA1 - rtems_region_create - RTEMS_INVALID_ADDRESS" ); |
---|
105 | |
---|
106 | status = rtems_region_create( |
---|
107 | Region_name[ 1 ], |
---|
108 | &Region_good_area[ REGION_START_OFFSET ], |
---|
109 | REGION_LENGTH, |
---|
110 | 0x40, |
---|
111 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
112 | &Region_id[ 1 ] |
---|
113 | ); |
---|
114 | directive_failed( status, "rtems_region_create" ); |
---|
115 | puts( "TA1 - rtems_region_create - RTEMS_SUCCESSFUL" ); |
---|
116 | |
---|
117 | /* extend NULL address */ |
---|
118 | status = rtems_region_extend( |
---|
119 | Region_id[ 1 ], |
---|
120 | NULL, |
---|
121 | REGION_LENGTH - 1 |
---|
122 | ); |
---|
123 | fatal_directive_status( |
---|
124 | status, |
---|
125 | RTEMS_INVALID_ADDRESS, |
---|
126 | "rtems_region_extend with NULL" |
---|
127 | ); |
---|
128 | puts( "TA1 - rtems_region_extend - NULL address - RTEMS_INVALID_ADDRESS" ); |
---|
129 | |
---|
130 | /* extend within heap */ |
---|
131 | status = rtems_region_extend( |
---|
132 | Region_id[ 1 ], |
---|
133 | &Region_good_area[ REGION_START_OFFSET ], |
---|
134 | REGION_LENGTH - 1 |
---|
135 | ); |
---|
136 | fatal_directive_status( |
---|
137 | status, |
---|
138 | RTEMS_INVALID_ADDRESS, |
---|
139 | "rtems_region_extend with address in heap" |
---|
140 | ); |
---|
141 | puts( "TA1 - rtems_region_extend - address within - RTEMS_INVALID_ADDRESS" ); |
---|
142 | |
---|
143 | status = rtems_region_create( |
---|
144 | Region_name[ 1 ], |
---|
145 | Region_good_area, |
---|
146 | REGION_LENGTH, |
---|
147 | 0x40, |
---|
148 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
149 | &junk_id |
---|
150 | ); |
---|
151 | fatal_directive_status( |
---|
152 | status, |
---|
153 | RTEMS_TOO_MANY, |
---|
154 | "rtems_region_create of too many" |
---|
155 | ); |
---|
156 | puts( "TA1 - rtems_region_create - RTEMS_TOO_MANY" ); |
---|
157 | |
---|
158 | status = rtems_region_delete( 100 ); |
---|
159 | fatal_directive_status( |
---|
160 | status, |
---|
161 | RTEMS_INVALID_ID, |
---|
162 | "rtems_region_delete with illegal id" |
---|
163 | ); |
---|
164 | puts( "TA1 - rtems_region_delete - unknown RTEMS_INVALID_ID" ); |
---|
165 | |
---|
166 | status = rtems_region_delete( rtems_build_id( 1, 1, 1, 256 ) ); |
---|
167 | fatal_directive_status( |
---|
168 | status, |
---|
169 | RTEMS_INVALID_ID, |
---|
170 | "rtems_region_delete with illegal id" |
---|
171 | ); |
---|
172 | puts( "TA1 - rtems_region_delete - local RTEMS_INVALID_ID" ); |
---|
173 | |
---|
174 | status = rtems_region_ident( 0, &junk_id ); |
---|
175 | fatal_directive_status( |
---|
176 | status, |
---|
177 | RTEMS_INVALID_NAME, |
---|
178 | "rtems_region_ident with illegal name" |
---|
179 | ); |
---|
180 | puts( "TA1 - rtems_region_ident - RTEMS_INVALID_NAME" ); |
---|
181 | |
---|
182 | /* Check get_information errors */ |
---|
183 | status = rtems_region_get_information( Region_id[ 1 ], NULL ); |
---|
184 | fatal_directive_status( |
---|
185 | status, |
---|
186 | RTEMS_INVALID_ADDRESS, |
---|
187 | "rtems_region_get_information with NULL information" |
---|
188 | ); |
---|
189 | puts( "TA1 - rtems_region_get_information - RTEMS_INVALID_ADDRESS" ); |
---|
190 | |
---|
191 | status = rtems_region_get_information( 100, &the_info ); |
---|
192 | fatal_directive_status( |
---|
193 | status, |
---|
194 | RTEMS_INVALID_ID, |
---|
195 | "rtems_region_get_information with illegal id" |
---|
196 | ); |
---|
197 | puts( "TA1 - rtems_region_get_information - unknown RTEMS_INVALID_ID" ); |
---|
198 | |
---|
199 | /* Check get_free_information errors */ |
---|
200 | status = rtems_region_get_free_information( Region_id[ 1 ], NULL ); |
---|
201 | fatal_directive_status( |
---|
202 | status, |
---|
203 | RTEMS_INVALID_ADDRESS, |
---|
204 | "rtems_region_get_free_information with NULL information" |
---|
205 | ); |
---|
206 | puts( "TA1 - rtems_region_get_free_information - RTEMS_INVALID_ADDRESS" ); |
---|
207 | |
---|
208 | status = rtems_region_get_free_information( 100, &the_info ); |
---|
209 | fatal_directive_status( |
---|
210 | status, |
---|
211 | RTEMS_INVALID_ID, |
---|
212 | "rtems_region_get_free_information with illegal id" |
---|
213 | ); |
---|
214 | puts( "TA1 - rtems_region_get_free_information - unknown RTEMS_INVALID_ID" ); |
---|
215 | |
---|
216 | /* get segment illegal id */ |
---|
217 | status = rtems_region_get_segment( |
---|
218 | 100, |
---|
219 | 0x40, |
---|
220 | RTEMS_DEFAULT_OPTIONS, |
---|
221 | RTEMS_NO_TIMEOUT, |
---|
222 | &segment_address_1 |
---|
223 | ); |
---|
224 | fatal_directive_status( |
---|
225 | status, |
---|
226 | RTEMS_INVALID_ID, |
---|
227 | "rtems_region_get_segment with illegal id" |
---|
228 | ); |
---|
229 | puts( "TA1 - rtems_region_get_segment - RTEMS_INVALID_ID" ); |
---|
230 | |
---|
231 | /* get_segment with NULL param */ |
---|
232 | status = rtems_region_get_segment( |
---|
233 | Region_id[ 1 ], |
---|
234 | 2, |
---|
235 | RTEMS_DEFAULT_OPTIONS, |
---|
236 | RTEMS_NO_TIMEOUT, |
---|
237 | NULL |
---|
238 | ); |
---|
239 | fatal_directive_status( |
---|
240 | status, |
---|
241 | RTEMS_INVALID_ADDRESS, |
---|
242 | "rtems_region_get_segment with NULL param" |
---|
243 | ); |
---|
244 | puts( "TA1 - rtems_region_get_segment - RTEMS_INVALID_ADDRESS" ); |
---|
245 | |
---|
246 | /* get_segment with illegal 0 size */ |
---|
247 | status = rtems_region_get_segment( |
---|
248 | Region_id[ 1 ], |
---|
249 | 0, |
---|
250 | RTEMS_DEFAULT_OPTIONS, |
---|
251 | RTEMS_NO_TIMEOUT, |
---|
252 | &segment_address_1 |
---|
253 | ); |
---|
254 | fatal_directive_status( |
---|
255 | status, |
---|
256 | RTEMS_INVALID_SIZE, |
---|
257 | "rtems_region_get_segment with 0 size" |
---|
258 | ); |
---|
259 | puts( "TA1 - rtems_region_get_segment - 0 size - RTEMS_INVALID_SIZE" ); |
---|
260 | |
---|
261 | /* get_segment with illegal big size */ |
---|
262 | status = rtems_region_get_segment( |
---|
263 | Region_id[ 1 ], |
---|
264 | sizeof( Region_good_area ) * 2, |
---|
265 | RTEMS_DEFAULT_OPTIONS, |
---|
266 | RTEMS_NO_TIMEOUT, |
---|
267 | &segment_address_1 |
---|
268 | ); |
---|
269 | fatal_directive_status( |
---|
270 | status, |
---|
271 | RTEMS_INVALID_SIZE, |
---|
272 | "rtems_region_get_segment with big size" |
---|
273 | ); |
---|
274 | puts( "TA1 - rtems_region_get_segment - too big - RTEMS_INVALID_SIZE" ); |
---|
275 | |
---|
276 | status = rtems_region_get_segment( |
---|
277 | Region_id[ 1 ], |
---|
278 | REGION_LENGTH / 2, |
---|
279 | RTEMS_DEFAULT_OPTIONS, |
---|
280 | RTEMS_NO_TIMEOUT, |
---|
281 | &segment_address_1 |
---|
282 | ); |
---|
283 | directive_failed( status, "rtems_region_get_segment" ); |
---|
284 | puts( "TA1 - rtems_region_get_segment - RTEMS_SUCCESSFUL" ); |
---|
285 | |
---|
286 | status = rtems_region_get_segment( |
---|
287 | Region_id[ 1 ], |
---|
288 | REGION_LENGTH / 2, |
---|
289 | RTEMS_NO_WAIT, |
---|
290 | RTEMS_NO_TIMEOUT, |
---|
291 | &segment_address_2 |
---|
292 | ); |
---|
293 | fatal_directive_status( |
---|
294 | status, |
---|
295 | RTEMS_UNSATISFIED, |
---|
296 | "rtems_region_get_segment unsatisfied" |
---|
297 | ); |
---|
298 | puts( "TA1 - rtems_region_get_segment - RTEMS_UNSATISFIED" ); |
---|
299 | |
---|
300 | puts( "TA1 - rtems_region_get_segment - timeout in 3 seconds" ); |
---|
301 | status = rtems_region_get_segment( |
---|
302 | Region_id[ 1 ], |
---|
303 | REGION_LENGTH / 2, |
---|
304 | RTEMS_DEFAULT_OPTIONS, |
---|
305 | 3 * rtems_clock_get_ticks_per_second(), |
---|
306 | &segment_address_3 |
---|
307 | ); |
---|
308 | fatal_directive_status( |
---|
309 | status, |
---|
310 | RTEMS_TIMEOUT, |
---|
311 | "rtems_region_get_segment timeout" |
---|
312 | ); |
---|
313 | puts( "TA1 - rtems_region_get_segment - woke up with RTEMS_TIMEOUT" ); |
---|
314 | |
---|
315 | /* Check get_segment_size errors */ |
---|
316 | status = rtems_region_get_segment_size( Region_id[ 1 ], NULL, &segment_size ); |
---|
317 | fatal_directive_status( |
---|
318 | status, |
---|
319 | RTEMS_INVALID_ADDRESS, |
---|
320 | "rtems_region_get_segment_size with NULL segment" |
---|
321 | ); |
---|
322 | puts( "TA1 - rtems_region_get_segment_size - RTEMS_INVALID_ADDRESS" ); |
---|
323 | |
---|
324 | status = rtems_region_get_segment_size( |
---|
325 | Region_id[ 1 ], segment_address_1, NULL |
---|
326 | ); |
---|
327 | fatal_directive_status( |
---|
328 | status, |
---|
329 | RTEMS_INVALID_ADDRESS, |
---|
330 | "rtems_region_get_segment_size with NULL size" |
---|
331 | ); |
---|
332 | puts( "TA1 - rtems_region_get_segment_size - RTEMS_INVALID_ADDRESS" ); |
---|
333 | |
---|
334 | status = rtems_region_get_segment_size( |
---|
335 | 100, segment_address_1, &segment_size |
---|
336 | ); |
---|
337 | fatal_directive_status( |
---|
338 | status, |
---|
339 | RTEMS_INVALID_ID, |
---|
340 | "rtems_region_get_segment_size with illegal id" |
---|
341 | ); |
---|
342 | puts( "TA1 - rtems_region_get_segment_size - unknown RTEMS_INVALID_ID" ); |
---|
343 | |
---|
344 | status = rtems_region_delete( Region_id[ 1 ] ); |
---|
345 | fatal_directive_status( |
---|
346 | status, |
---|
347 | RTEMS_RESOURCE_IN_USE, |
---|
348 | "rtems_region_delete with buffers in use" |
---|
349 | ); |
---|
350 | puts( "TA1 - rtems_region_delete - RTEMS_RESOURCE_IN_USE" ); |
---|
351 | |
---|
352 | /* Check resize_segment errors */ |
---|
353 | status = rtems_region_resize_segment( |
---|
354 | Region_id[ 1 ], segment_address_3, 256, NULL |
---|
355 | ); |
---|
356 | fatal_directive_status( |
---|
357 | status, |
---|
358 | RTEMS_INVALID_ADDRESS, |
---|
359 | "rtems_region_resize_segment with NULL old size" |
---|
360 | ); |
---|
361 | puts( "TA1 - rtems_region_resize_segment - RTEMS_INVALID_ADDRESS" ); |
---|
362 | |
---|
363 | status = rtems_region_resize_segment( |
---|
364 | Region_id[ 1 ], NULL, 256, &segment_size |
---|
365 | ); |
---|
366 | fatal_directive_status( |
---|
367 | status, |
---|
368 | RTEMS_INVALID_ADDRESS, |
---|
369 | "rtems_region_resize_segment with NULL segment" |
---|
370 | ); |
---|
371 | puts( "TA1 - rtems_region_resize_segment - RTEMS_INVALID_ADDRESS" ); |
---|
372 | |
---|
373 | status = rtems_region_resize_segment( |
---|
374 | 100, segment_address_3, 256, &segment_size |
---|
375 | ); |
---|
376 | fatal_directive_status( |
---|
377 | status, |
---|
378 | RTEMS_INVALID_ID, |
---|
379 | "rtems_region_resize_segment with illegal id" |
---|
380 | ); |
---|
381 | puts( "TA1 - rtems_region_resize_segment - RTEMS_INVALID_ID" ); |
---|
382 | |
---|
383 | /* Check return_segment errors */ |
---|
384 | status = rtems_region_return_segment( 100, segment_address_1 ); |
---|
385 | fatal_directive_status( |
---|
386 | status, |
---|
387 | RTEMS_INVALID_ID, |
---|
388 | "rtems_region_return_segment with illegal id" |
---|
389 | ); |
---|
390 | puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ID" ); |
---|
391 | |
---|
392 | status = rtems_region_return_segment( Region_id[ 1 ], Region_good_area ); |
---|
393 | fatal_directive_status( |
---|
394 | status, |
---|
395 | RTEMS_INVALID_ADDRESS, |
---|
396 | "rtems_region_return_segment with illegal segment" |
---|
397 | ); |
---|
398 | puts( "TA1 - rtems_region_return_segment - RTEMS_INVALID_ADDRESS" ); |
---|
399 | |
---|
400 | /* |
---|
401 | * The following generate internal heap errors. Thus this code |
---|
402 | * is subject to change if the heap code changes. |
---|
403 | */ |
---|
404 | |
---|
405 | status = rtems_region_extend( |
---|
406 | 100, |
---|
407 | Region_good_area, |
---|
408 | 128 |
---|
409 | ); |
---|
410 | fatal_directive_status( |
---|
411 | status, |
---|
412 | RTEMS_INVALID_ID, |
---|
413 | "rtems_region_extend with illegal id" |
---|
414 | ); |
---|
415 | puts( "TA1 - rtems_region_extend - RTEMS_INVALID_ID" ); |
---|
416 | |
---|
417 | status = rtems_region_extend( |
---|
418 | Region_id[ 1 ], |
---|
419 | &Region_good_area[ REGION_START_OFFSET + 16 ], |
---|
420 | 128 |
---|
421 | ); |
---|
422 | fatal_directive_status( |
---|
423 | status, |
---|
424 | RTEMS_INVALID_ADDRESS, |
---|
425 | "rtems_region_extend with illegal starting address" |
---|
426 | ); |
---|
427 | puts( "TA1 - rtems_region_extend - within heap - RTEMS_INVALID_ADDRESS" ); |
---|
428 | } |
---|
429 | |
---|
430 | rtems_task Init( |
---|
431 | rtems_task_argument argument |
---|
432 | ) |
---|
433 | { |
---|
434 | TEST_BEGIN(); |
---|
435 | |
---|
436 | region_error_tests(); |
---|
437 | |
---|
438 | TEST_END(); |
---|
439 | rtems_test_exit( 0 ); |
---|
440 | } |
---|