3 #include "silcruntime.h"
7 int main(int argc, char **argv)
9 SilcBool success = FALSE;
10 SilcStack stack, child, child2;
14 if (argc > 1 && !strcmp(argv[1], "-d")) {
16 silc_log_debug_hexdump(TRUE);
18 silc_log_set_debug_string("*stack*,*errno*");
21 SILC_LOG_DEBUG(("Allocating stack of default size (1024 bytes)"));
22 stack = silc_stack_alloc(0, NULL);
25 #ifdef SILC_DIST_INPLACE
26 silc_stack_stats(stack);
27 #endif /* SILC_DIST_INPLACE */
29 SILC_LOG_DEBUG(("Allocating 2048 bytes from stack"));
30 ptr = silc_smalloc(stack, 2048);
33 #ifdef SILC_DIST_INPLACE
34 silc_stack_stats(stack);
35 #endif /* SILC_DIST_INPLACE */
37 SILC_LOG_DEBUG(("Freeing the stack"));
38 silc_stack_free(stack);
40 SILC_LOG_DEBUG(("Allocating stack of default size (1024 bytes)"));
41 stack = silc_stack_alloc(0, NULL);
44 #ifdef SILC_DIST_INPLACE
45 silc_stack_stats(stack);
46 #endif /* SILC_DIST_INPLACE */
48 SILC_LOG_DEBUG(("Pushing and allocating %d times", NUM_ALLS));
49 if (!silc_stack_push(stack, NULL))
51 for (i = 0; i < NUM_ALLS; i++) {
52 ptr2 = silc_smalloc(stack, (i + 1) * 7);
56 #ifdef SILC_DIST_INPLACE
57 silc_stack_stats(stack);
58 #endif /* SILC_DIST_INPLACE */
59 silc_stack_pop(stack);
60 SILC_LOG_DEBUG(("Popping"));
61 #ifdef SILC_DIST_INPLACE
62 silc_stack_stats(stack);
63 #endif /* SILC_DIST_INPLACE */
65 SILC_LOG_DEBUG(("Pushing and allocating %d times", NUM_ALLS));
66 if (!silc_stack_push(stack, NULL))
68 for (i = 0; i < NUM_ALLS; i++) {
69 ptr2 = silc_smalloc(stack, (i + 1) * 7);
73 #ifdef SILC_DIST_INPLACE
74 silc_stack_stats(stack);
75 #endif /* SILC_DIST_INPLACE */
76 silc_stack_pop(stack);
77 SILC_LOG_DEBUG(("Popping"));
78 #ifdef SILC_DIST_INPLACE
79 silc_stack_stats(stack);
80 #endif /* SILC_DIST_INPLACE */
82 SILC_LOG_DEBUG(("Pushing %d times", NUM_ALLS / 2));
83 for (i = 0; i < NUM_ALLS / 2; i++) {
84 if (!silc_stack_push(stack, NULL))
86 ptr2 = silc_smalloc(stack, (i + 1) * 7);
90 #ifdef SILC_DIST_INPLACE
91 silc_stack_stats(stack);
92 #endif /* SILC_DIST_INPLACE */
93 SILC_LOG_DEBUG(("Popping %d times", NUM_ALLS / 2));
94 for (i = 0; i < NUM_ALLS / 2; i++)
95 silc_stack_pop(stack);
96 #ifdef SILC_DIST_INPLACE
97 silc_stack_stats(stack);
98 #endif /* SILC_DIST_INPLACE */
100 SILC_LOG_DEBUG(("Pushing and reallocating %d times", NUM_ALLS / 10));
102 if (!silc_stack_push(stack, NULL))
104 for (i = 0; i < NUM_ALLS / 10; i++) {
105 ptr2 = silc_srealloc(stack, (i * 7), ptr2, (i + 1) * 7);
109 #ifdef SILC_DIST_INPLACE
110 silc_stack_stats(stack);
111 #endif /* SILC_DIST_INPLACE */
112 silc_stack_pop(stack);
113 SILC_LOG_DEBUG(("Popping"));
114 #ifdef SILC_DIST_INPLACE
115 silc_stack_stats(stack);
116 #endif /* SILC_DIST_INPLACE */
118 SILC_LOG_DEBUG(("Creating child stack"));
119 child = silc_stack_alloc(8190, stack);
122 SILC_LOG_DEBUG(("Pushing %d times", NUM_ALLS / 2));
123 for (i = 0; i < NUM_ALLS / 2; i++) {
124 if (!silc_stack_push(child, NULL))
126 ptr2 = silc_smalloc(child, (i + 1) * 7);
130 #ifdef SILC_DIST_INPLACE
131 silc_stack_stats(child);
132 #endif /* SILC_DIST_INPLACE */
133 SILC_LOG_DEBUG(("Popping %d times", NUM_ALLS / 2));
134 for (i = 0; i < NUM_ALLS / 2; i++)
135 silc_stack_pop(child);
136 #ifdef SILC_DIST_INPLACE
137 silc_stack_stats(child);
138 #endif /* SILC_DIST_INPLACE */
140 SILC_LOG_DEBUG(("Pushing and reallocating %d times", NUM_ALLS / 10));
142 if (!silc_stack_push(child, NULL))
144 for (i = 0; i < NUM_ALLS / 10; i++) {
145 ptr2 = silc_srealloc(child, (i * 7), ptr2, (i + 1) * 7);
149 ptr = silc_smalloc(child, 100000);
150 #ifdef SILC_DIST_INPLACE
151 silc_stack_stats(child);
152 #endif /* SILC_DIST_INPLACE */
153 silc_stack_pop(child);
154 SILC_LOG_DEBUG(("Popping"));
155 #ifdef SILC_DIST_INPLACE
156 silc_stack_stats(child);
157 #endif /* SILC_DIST_INPLACE */
158 #ifdef SILC_DIST_INPLACE
159 silc_stack_stats(stack);
160 #endif /* SILC_DIST_INPLACE */
161 silc_stack_free(child);
162 #ifdef SILC_DIST_INPLACE
163 silc_stack_stats(stack);
164 #endif /* SILC_DIST_INPLACE */
166 SILC_LOG_DEBUG(("Creating child stack"));
167 child = silc_stack_alloc(8192, stack);
170 SILC_LOG_DEBUG(("Pushing %d times", NUM_ALLS / 10));
171 for (i = 0; i < NUM_ALLS / 10; i++) {
172 if (!silc_stack_push(child, NULL))
174 ptr2 = silc_smalloc(child, (i + 1) * 7);
178 #ifdef SILC_DIST_INPLACE
179 silc_stack_stats(child);
180 #endif /* SILC_DIST_INPLACE */
181 SILC_LOG_DEBUG(("Popping %d times", NUM_ALLS / 10));
182 for (i = 0; i < NUM_ALLS / 10; i++)
183 silc_stack_pop(child);
184 #ifdef SILC_DIST_INPLACE
185 silc_stack_stats(child);
186 #endif /* SILC_DIST_INPLACE */
188 SILC_LOG_DEBUG(("Pushing and reallocating %d times", NUM_ALLS / 10));
190 if (!silc_stack_push(child, NULL))
192 for (i = 0; i < NUM_ALLS / 10; i++) {
193 ptr2 = silc_srealloc(child, (i * 7), ptr2, (i + 1) * 7);
197 SILC_LOG_DEBUG(("Allocate child from child"));
198 child2 = silc_stack_alloc(0, child);
199 ptr = silc_smalloc(child2, 500000);
200 #ifdef SILC_DIST_INPLACE
201 silc_stack_stats(child2);
202 #endif /* SILC_DIST_INPLACE */
203 silc_stack_free(child2);
204 #ifdef SILC_DIST_INPLACE
205 silc_stack_stats(child2);
206 #endif /* SILC_DIST_INPLACE */
207 silc_stack_pop(child);
208 SILC_LOG_DEBUG(("Popping"));
209 #ifdef SILC_DIST_INPLACE
210 silc_stack_stats(child);
211 #endif /* SILC_DIST_INPLACE */
212 #ifdef SILC_DIST_INPLACE
213 silc_stack_stats(stack);
214 #endif /* SILC_DIST_INPLACE */
215 silc_stack_free(child);
216 #ifdef SILC_DIST_INPLACE
217 silc_stack_stats(stack);
218 #endif /* SILC_DIST_INPLACE */
220 SILC_LOG_DEBUG(("Purge stack"));
221 silc_stack_purge(stack);
222 #ifdef SILC_DIST_INPLACE
223 silc_stack_stats(stack);
224 #endif /* SILC_DIST_INPLACE */
226 SILC_LOG_DEBUG(("Current alignment: %d", silc_stack_get_alignment(stack)));
227 SILC_LOG_DEBUG(("Set alignemtn to 16"));
228 silc_stack_set_alignment(stack, 16);
229 SILC_LOG_DEBUG(("Current alignment: %d", silc_stack_get_alignment(stack)));
230 SILC_LOG_DEBUG(("Allocate 1 byte"));
231 ptr = silc_smalloc(stack, 1);
232 SILC_LOG_DEBUG(("Allocate 1 byte, check alignment"));
233 ptr2 = silc_smalloc(stack, 1);
234 if (ptr2 - ptr < 16) {
235 SILC_LOG_DEBUG(("Bad alignment"));
238 SILC_LOG_DEBUG(("Alignment (ptr, ptr2) is %d", ptr2 - ptr));
239 SILC_LOG_DEBUG(("Allocate 1 byte, check alignment"));
240 ptr2 = silc_smalloc(stack, 1);
241 if (ptr2 - ptr < 32) {
242 SILC_LOG_DEBUG(("Bad alignment"));
245 SILC_LOG_DEBUG(("Alignment (ptr, ptr2) is %d", ptr2 - ptr));
247 SILC_LOG_DEBUG(("Freeing the stack"));
248 silc_stack_free(stack);
253 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
254 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");