1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup sptests |
---|
5 | * |
---|
6 | * @brief Test that the task stack allocator works. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2011 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <tmacros.h> |
---|
28 | |
---|
29 | const char rtems_test_name[] = "SPSTKALLOC 2"; |
---|
30 | |
---|
31 | #if !BSP_SMALL_MEMORY |
---|
32 | |
---|
33 | #include <stdio.h> |
---|
34 | #include <inttypes.h> |
---|
35 | |
---|
36 | #include <rtems/score/heapimpl.h> |
---|
37 | |
---|
38 | #define TASK_COUNT 5 |
---|
39 | |
---|
40 | #define PAGE_SIZE 1024 |
---|
41 | |
---|
42 | static Heap_Control task_stack_heap; |
---|
43 | |
---|
44 | static void task_stack_init(size_t stack_space_size); |
---|
45 | |
---|
46 | static void *task_stack_allocate(size_t stack_size); |
---|
47 | |
---|
48 | static void task_stack_free(void *addr); |
---|
49 | |
---|
50 | static void print_info(void) |
---|
51 | { |
---|
52 | Heap_Information_block info; |
---|
53 | |
---|
54 | _Heap_Get_information(&task_stack_heap, &info); |
---|
55 | |
---|
56 | printf( |
---|
57 | "used blocks = %" PRIu32 ", " |
---|
58 | "largest used block = %" PRIu32 ", " |
---|
59 | "used space = %" PRIu32 "\n" |
---|
60 | "free blocks = %" PRIu32 ", " |
---|
61 | "largest free block = %" PRIu32 ", " |
---|
62 | "free space = %" PRIu32 "\n", |
---|
63 | info.Used.number, |
---|
64 | info.Used.largest, |
---|
65 | info.Used.total, |
---|
66 | info.Free.number, |
---|
67 | info.Free.largest, |
---|
68 | info.Free.total |
---|
69 | ); |
---|
70 | } |
---|
71 | |
---|
72 | static rtems_task Init(rtems_task_argument argument) |
---|
73 | { |
---|
74 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
75 | rtems_name name = rtems_build_name('S', 'T', 'K', 'A'); |
---|
76 | rtems_id id = RTEMS_ID_NONE; |
---|
77 | int i = 0; |
---|
78 | |
---|
79 | TEST_BEGIN(); |
---|
80 | |
---|
81 | print_info(); |
---|
82 | |
---|
83 | for (i = 2; i < TASK_COUNT; ++i) { |
---|
84 | sc = rtems_task_create( |
---|
85 | name, |
---|
86 | RTEMS_MINIMUM_PRIORITY, |
---|
87 | RTEMS_MINIMUM_STACK_SIZE, |
---|
88 | RTEMS_DEFAULT_MODES, |
---|
89 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
90 | &id |
---|
91 | ); |
---|
92 | directive_failed(sc, "rtems_task_create"); |
---|
93 | } |
---|
94 | |
---|
95 | sc = rtems_task_create( |
---|
96 | name, |
---|
97 | RTEMS_MINIMUM_PRIORITY, |
---|
98 | 2 * RTEMS_MINIMUM_STACK_SIZE, |
---|
99 | RTEMS_DEFAULT_MODES, |
---|
100 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
101 | &id |
---|
102 | ); |
---|
103 | fatal_directive_status(sc, RTEMS_UNSATISFIED, "rtems_task_create"); |
---|
104 | |
---|
105 | sc = rtems_task_create( |
---|
106 | name, |
---|
107 | RTEMS_MINIMUM_PRIORITY, |
---|
108 | RTEMS_MINIMUM_STACK_SIZE, |
---|
109 | RTEMS_DEFAULT_MODES, |
---|
110 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
111 | &id |
---|
112 | ); |
---|
113 | directive_failed(sc, "rtems_task_create"); |
---|
114 | |
---|
115 | print_info(); |
---|
116 | |
---|
117 | TEST_END(); |
---|
118 | |
---|
119 | rtems_test_exit(0); |
---|
120 | } |
---|
121 | |
---|
122 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
123 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
124 | |
---|
125 | #define CONFIGURE_MAXIMUM_TASKS TASK_COUNT |
---|
126 | |
---|
127 | #define CONFIGURE_TASK_STACK_ALLOCATOR_INIT task_stack_init |
---|
128 | #define CONFIGURE_TASK_STACK_ALLOCATOR task_stack_allocate |
---|
129 | #define CONFIGURE_TASK_STACK_DEALLOCATOR task_stack_free |
---|
130 | #define CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE |
---|
131 | #define CONFIGURE_TASK_STACK_FROM_ALLOCATOR(stack_size) \ |
---|
132 | ((stack_size) + HEAP_BLOCK_HEADER_SIZE + PAGE_SIZE - 1) |
---|
133 | |
---|
134 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
135 | |
---|
136 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
137 | |
---|
138 | #define CONFIGURE_INIT |
---|
139 | |
---|
140 | #include <rtems/confdefs.h> |
---|
141 | |
---|
142 | static char task_stack_space |
---|
143 | [CONFIGURE_TASK_STACK_FROM_ALLOCATOR(CONFIGURE_STACK_SPACE_SIZE)]; |
---|
144 | |
---|
145 | static void task_stack_init(size_t stack_space_size) |
---|
146 | { |
---|
147 | bool ok = _Heap_Initialize( |
---|
148 | &task_stack_heap, |
---|
149 | task_stack_space, |
---|
150 | sizeof(task_stack_space), |
---|
151 | PAGE_SIZE |
---|
152 | ); |
---|
153 | |
---|
154 | rtems_test_assert(stack_space_size == CONFIGURE_STACK_SPACE_SIZE); |
---|
155 | rtems_test_assert(ok); |
---|
156 | } |
---|
157 | |
---|
158 | static void *task_stack_allocate(size_t stack_size) |
---|
159 | { |
---|
160 | return _Heap_Allocate(&task_stack_heap, stack_size); |
---|
161 | } |
---|
162 | |
---|
163 | static void task_stack_free(void *addr) |
---|
164 | { |
---|
165 | _Heap_Free(&task_stack_heap, addr); |
---|
166 | } |
---|
167 | |
---|
168 | #else /* BSP_SMALL_MEMORY */ |
---|
169 | |
---|
170 | static void Init(rtems_task_argument arg) |
---|
171 | { |
---|
172 | TEST_BEGIN(); |
---|
173 | puts("NOT ENOUGH MEMORY TO RUN TEST"); |
---|
174 | |
---|
175 | rtems_test_exit(0); |
---|
176 | } |
---|
177 | |
---|
178 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
179 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
180 | |
---|
181 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
182 | |
---|
183 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
184 | |
---|
185 | #define CONFIGURE_INIT |
---|
186 | |
---|
187 | #include <rtems/confdefs.h> |
---|
188 | |
---|
189 | #endif /* BSP_SMALL_MEMORY */ |
---|