1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
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 | #include <rtems/libcsupport.h> |
---|
15 | |
---|
16 | #include "tmacros.h" |
---|
17 | |
---|
18 | const char rtems_test_name[] = "SP 64"; |
---|
19 | |
---|
20 | /* forward declarations to avoid warnings */ |
---|
21 | rtems_task Init(rtems_task_argument argument); |
---|
22 | |
---|
23 | uint32_t Area1[50] CPU_STRUCTURE_ALIGNMENT; |
---|
24 | uint32_t Area2[50] CPU_STRUCTURE_ALIGNMENT; |
---|
25 | |
---|
26 | rtems_task Init( |
---|
27 | rtems_task_argument ignored |
---|
28 | ) |
---|
29 | { |
---|
30 | rtems_id region1; |
---|
31 | rtems_id region2; |
---|
32 | rtems_status_code sc; |
---|
33 | bool ok; |
---|
34 | uintptr_t to_alloc; |
---|
35 | void *alloced; |
---|
36 | rtems_resource_snapshot snapshot; |
---|
37 | void *greedy; |
---|
38 | |
---|
39 | TEST_BEGIN(); |
---|
40 | |
---|
41 | puts( "Allocate one region -- so second auto extends" ); |
---|
42 | sc = rtems_region_create( |
---|
43 | rtems_build_name( 'R', 'N', '1', ' ' ), |
---|
44 | Area1, |
---|
45 | sizeof(Area1), |
---|
46 | 8, |
---|
47 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
48 | ®ion1 |
---|
49 | ); |
---|
50 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
51 | |
---|
52 | greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc ); |
---|
53 | rtems_resource_snapshot_take( &snapshot ); |
---|
54 | |
---|
55 | puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" ); |
---|
56 | while ( to_alloc > 8 ) { |
---|
57 | ok = rtems_workspace_allocate( to_alloc, &alloced ); |
---|
58 | rtems_test_assert( ok ); |
---|
59 | |
---|
60 | sc = rtems_region_create( |
---|
61 | rtems_build_name( 'R', 'N', '2', ' ' ), |
---|
62 | Area2, |
---|
63 | sizeof(Area2), |
---|
64 | 8, |
---|
65 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
66 | ®ion2 |
---|
67 | ); |
---|
68 | |
---|
69 | rtems_workspace_free( alloced ); |
---|
70 | |
---|
71 | if ( sc == RTEMS_SUCCESSFUL ) |
---|
72 | break; |
---|
73 | |
---|
74 | rtems_test_assert( sc == RTEMS_TOO_MANY ); |
---|
75 | |
---|
76 | /* |
---|
77 | * Verify heap is still in same shape if we couldn't allocate a region |
---|
78 | */ |
---|
79 | ok = rtems_resource_snapshot_check( &snapshot ); |
---|
80 | rtems_test_assert( ok ); |
---|
81 | |
---|
82 | to_alloc -= 8; |
---|
83 | } |
---|
84 | |
---|
85 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
86 | |
---|
87 | /* |
---|
88 | * Verify heap is still in same shape after we free the region |
---|
89 | */ |
---|
90 | puts( "Init - rtems_region_delete - OK" ); |
---|
91 | sc = rtems_region_delete( region2 ); |
---|
92 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
93 | |
---|
94 | puts( "Init - verify workspace has same memory" ); |
---|
95 | ok = rtems_resource_snapshot_check( &snapshot ); |
---|
96 | rtems_test_assert( ok ); |
---|
97 | rtems_workspace_greedy_free( greedy ); |
---|
98 | |
---|
99 | TEST_END(); |
---|
100 | rtems_test_exit(0); |
---|
101 | } |
---|
102 | |
---|
103 | /* configuration information */ |
---|
104 | |
---|
105 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
106 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
107 | |
---|
108 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
109 | #define CONFIGURE_MAXIMUM_REGIONS rtems_resource_unlimited( 2 ) |
---|
110 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
111 | |
---|
112 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
113 | |
---|
114 | #define CONFIGURE_MEMORY_OVERHEAD 1 |
---|
115 | |
---|
116 | #define CONFIGURE_INIT |
---|
117 | #include <rtems/confdefs.h> |
---|
118 | |
---|
119 | /* global variables */ |
---|