1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #include <tmacros.h> |
---|
13 | |
---|
14 | #define MAX 256 |
---|
15 | uint32_t Memory[MAX]; |
---|
16 | Heap_Control Heap; |
---|
17 | |
---|
18 | /* |
---|
19 | * Exercise case in heapresize.c around line 125 when new_block_size |
---|
20 | * < min_block_size |
---|
21 | */ |
---|
22 | void test_case_one(void) |
---|
23 | { |
---|
24 | uint32_t heap_size; |
---|
25 | void *ptr1; |
---|
26 | uintptr_t old; |
---|
27 | uintptr_t avail; |
---|
28 | Heap_Resize_status hc; |
---|
29 | |
---|
30 | puts( "Init - _Heap_Initialize (for test one) - OK" ); |
---|
31 | heap_size = _Heap_Initialize( &Heap, Memory, sizeof(Memory), 8 ); |
---|
32 | printf( "Init - Heap size=%" PRIu32 "\n", heap_size ); |
---|
33 | assert( heap_size ); |
---|
34 | |
---|
35 | puts( "Init - _Heap_Allocate - too large size (overflow)- not OK"); |
---|
36 | ptr1 = _Heap_Allocate( &Heap, 0xffffffff ); |
---|
37 | assert( !ptr1 ); |
---|
38 | |
---|
39 | puts( "Init - _Heap_Allocate_aligned - OK"); |
---|
40 | ptr1 = _Heap_Allocate_aligned( &Heap, 64, 32 ); |
---|
41 | assert( ptr1 ); |
---|
42 | |
---|
43 | puts( "Init - _Heap_Resize_block - OK"); |
---|
44 | hc = _Heap_Resize_block( &Heap, ptr1, 4, &old, &avail ); |
---|
45 | assert( !hc ); |
---|
46 | } |
---|
47 | |
---|
48 | /* |
---|
49 | * Exercise case in heapresize.c around line 140 when next_is_used AND |
---|
50 | * free_block_size < min_block_size. |
---|
51 | */ |
---|
52 | void test_case_two(void) |
---|
53 | { |
---|
54 | uint32_t heap_size; |
---|
55 | void *ptr1; |
---|
56 | uintptr_t old; |
---|
57 | uintptr_t avail; |
---|
58 | Heap_Resize_status hc; |
---|
59 | |
---|
60 | puts( "\nInit - _Heap_Initialize (for test two) - OK" ); |
---|
61 | heap_size = _Heap_Initialize( &Heap, Memory, sizeof(Memory), 8 ); |
---|
62 | printf( "Init - Heap size=%" PRIu32 "\n", heap_size ); |
---|
63 | assert( heap_size ); |
---|
64 | |
---|
65 | puts( "Init - _Heap_Allocate_aligned - OK"); |
---|
66 | ptr1 = _Heap_Allocate_aligned( &Heap, 64, 4 ); |
---|
67 | assert( ptr1 ); |
---|
68 | |
---|
69 | puts( "Init - _Heap_Resize_block - OK"); |
---|
70 | hc = _Heap_Resize_block( &Heap, ptr1, 56, &old, &avail ); |
---|
71 | assert( !hc ); |
---|
72 | } |
---|
73 | |
---|
74 | /* |
---|
75 | * Exercise case in heapallocatealigned.c around line 223 when ... |
---|
76 | */ |
---|
77 | void test_case_three(void) |
---|
78 | { |
---|
79 | uint32_t heap_size; |
---|
80 | void *ptr1; |
---|
81 | #if 0 |
---|
82 | Heap_Resize_status hc; |
---|
83 | #endif |
---|
84 | int pg, al, alloc, sz; |
---|
85 | |
---|
86 | puts( "Init - _Heap_Allocate_aligned - request impossible - not OK"); |
---|
87 | |
---|
88 | #if 0 |
---|
89 | heap_size = |
---|
90 | _Heap_Initialize( &Heap, Memory[32], sizeof(Memory), 1 << 16 ); |
---|
91 | ptr1 = _Heap_Allocate_aligned( &Heap, 4, 1 << 16 ); |
---|
92 | ptr1 = _Heap_Allocate_aligned( &Heap, 256, 1 << 16 ); |
---|
93 | #endif |
---|
94 | #if 1 |
---|
95 | for ( sz=32 ; sz <= 80 ; sz+=4 ) { |
---|
96 | for ( pg=2 ; pg < 12 ; pg++ ) { |
---|
97 | |
---|
98 | for ( al=16 ; al >=4 ; al-- ) { |
---|
99 | for ( alloc=4 ; alloc < sizeof(Memory)/2 ; alloc+=4 ) { |
---|
100 | heap_size = |
---|
101 | _Heap_Initialize( &Heap, &Memory[sz], sizeof(Memory)/2, 1 << pg ); |
---|
102 | if ( heap_size != 0 ) { |
---|
103 | do { |
---|
104 | ptr1 = _Heap_Allocate_aligned( &Heap, alloc, 1 <<al ); |
---|
105 | } while ( ptr1 ); |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | #endif |
---|
112 | } |
---|
113 | |
---|
114 | rtems_task Init( |
---|
115 | rtems_task_argument ignored |
---|
116 | ) |
---|
117 | { |
---|
118 | puts( "\n\n*** TEST 63 ***" ); |
---|
119 | |
---|
120 | test_case_one(); |
---|
121 | |
---|
122 | test_case_two(); |
---|
123 | |
---|
124 | test_case_three(); |
---|
125 | |
---|
126 | puts( "*** END OF TEST 63 ***" ); |
---|
127 | |
---|
128 | rtems_test_exit(0); |
---|
129 | } |
---|
130 | |
---|
131 | /* configuration information */ |
---|
132 | |
---|
133 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
134 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
135 | |
---|
136 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
137 | #define CONFIGURE_MAXIMUM_REGIONS 1 |
---|
138 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
139 | |
---|
140 | #define CONFIGURE_INIT |
---|
141 | #include <rtems/confdefs.h> |
---|
142 | |
---|
143 | /* global variables */ |
---|