6
* $Id: testc.c,v 1.5 1999-05-27 16:31:16 d3h325 Exp $
10
* Test harness for portable dynamic memory allocator.
14
#include "string-util.h"
26
#define NUM_COMMANDS (int)(sizeof(commands) / sizeof(char *))
39
C_MA_get_next_memhandle,
42
C_MA_init_memhandle_iterator,
55
C_MA_summarize_allocated_blocks,
56
C_MA_verify_allocator_stuff,
68
static char *commands[] =
75
"MA_get_next_memhandle",
78
"MA_init_memhandle_iterator",
91
"MA_summarize_allocated_blocks",
92
"MA_verify_allocator_stuff",
100
static char *help[] =
102
"MA_alloc_get(datatype, nelem, name, memhandle, index)",
103
"MA_allocate_heap(datatype, nelem, name, memhandle)",
104
"MA_chop_stack(memhandle)",
105
"MA_free_heap(memhandle)",
106
"MA_get_index(memhandle, index)",
107
"MA_get_next_memhandle(ithandle, memhandle)",
108
"MA_get_pointer(memhandle, pointer)",
109
"MA_init(datatype, nominal_stack, nominal_heap)",
110
"MA_init_memhandle_iterator(ithandle)",
111
"MA_inquire_avail(datatype)",
112
"MA_inquire_heap(datatype)",
113
"MA_inquire_stack(datatype)",
114
"MA_pop_stack(memhandle)",
116
"MA_push_get(datatype, nelem, name, memhandle, index)",
117
"MA_push_stack(datatype, nelem, name, memhandle)",
118
"MA_set_auto_verify(value)",
119
"MA_set_error_print(value)",
120
"MA_set_hard_fail(value)",
121
"MA_sizeof(datatype1, nelem1, datatype2)",
122
"MA_sizeof_overhead(datatype)",
123
"MA_summarize_allocated_blocks()",
124
"MA_verify_allocator_stuff()",
136
/* ------------------------------------------------------------------------- */
138
* Interactive interface to MA routines.
140
/* ------------------------------------------------------------------------- */
146
char s[81]; /* string buffer */
147
int c; /* index of command */
148
int ii1; /* in int buffer */
149
int ii2; /* in int buffer */
150
int ii3; /* in int buffer */
151
Integer oi1; /* out int buffer */
152
MA_AccessIndex oi2; /* out int buffer */
153
Pointer op; /* out Pointer buffer */
154
int value; /* return value buffer */
160
if (scanf("%80s", s) != 1)
162
printf("*** Input read failed; exiting.\n");
166
c = str_match(s, commands, NUM_COMMANDS);
169
printf("*** '%s' is ambiguous\n", s);
172
else if (c == SM_NONE)
174
printf("*** Unrecognized command '%s'\n", s);
181
if (scanf("%d %d %80s", &ii1, &ii2, s) != 3)
182
printf("*** Input read failed for %s\n", commands[c]);
185
value = MA_alloc_get(ii1, ii2, s, &oi1, &oi2);
186
printf("%s=%d memhandle=%ld index=%ld\n",
187
commands[c], value, (long)oi1, (long)oi2);
190
case C_MA_allocate_heap:
191
if (scanf("%d %d %80s", &ii1, &ii2, s) != 3)
192
printf("*** Input read failed for %s\n", commands[c]);
195
value = MA_allocate_heap(ii1, ii2, s, &oi1);
196
printf("%s=%d memhandle=%ld\n",
197
commands[c], value, (long)oi1);
200
case C_MA_chop_stack:
201
if (scanf("%d", &ii1) != 1)
202
printf("*** Input read failed for %s\n", commands[c]);
205
value = MA_chop_stack(ii1);
206
printf("%s=%d\n", commands[c], value);
210
if (scanf("%d", &ii1) != 1)
211
printf("*** Input read failed for %s\n", commands[c]);
214
value = MA_free_heap(ii1);
215
printf("%s=%d\n", commands[c], value);
219
if (scanf("%d", &ii1) != 1)
220
printf("*** Input read failed for %s\n", commands[c]);
223
value = MA_get_index(ii1, &oi2);
224
printf("%s=%d index=%ld\n", commands[c], value, (long)oi2);
227
case C_MA_get_next_memhandle:
228
if (scanf("%d", &ii1) != 1)
229
printf("*** Input read failed for %s\n", commands[c]);
233
value = MA_get_next_memhandle(&tmp, &oi1);
234
printf("%s=%d ithandle=%ld memhandle=%ld\n",
235
commands[c], value, (long)tmp, (long)oi1);
238
case C_MA_get_pointer:
239
if (scanf("%d", &ii1) != 1)
240
printf("*** Input read failed for %s\n", commands[c]);
243
value = MA_get_pointer(ii1, &op);
244
printf("%s=%d pointer=%lu\n", commands[c], value,
249
if (scanf("%d %d %d", &ii1, &ii2, &ii3) != 3)
250
printf("*** Input read failed for %s\n", commands[c]);
253
value = MA_init(ii1, ii2, ii3);
254
printf("%s=%d\n", commands[c], value);
257
case C_MA_init_memhandle_iterator:
258
value = MA_init_memhandle_iterator(&oi1);
259
printf("%s=%d ithandle=%ld\n", commands[c], value, (long)oi1);
261
case C_MA_inquire_avail:
262
if (scanf("%d", &ii1) != 1)
263
printf("*** Input read failed for %s\n", commands[c]);
266
oi1 = MA_inquire_avail(ii1);
267
printf("%s=%ld\n", commands[c], (long)oi1);
270
case C_MA_inquire_heap:
271
if (scanf("%d", &ii1) != 1)
272
printf("*** Input read failed for %s\n", commands[c]);
275
oi1 = MA_inquire_heap(ii1);
276
printf("%s=%ld\n", commands[c], (long)oi1);
279
case C_MA_inquire_stack:
280
if (scanf("%d", &ii1) != 1)
281
printf("*** Input read failed for %s\n", commands[c]);
284
oi1 = MA_inquire_stack(ii1);
285
printf("%s=%ld\n", commands[c], (long)oi1);
289
if (scanf("%d", &ii1) != 1)
290
printf("*** Input read failed for %s\n", commands[c]);
293
value = MA_pop_stack(ii1);
294
printf("%s=%d\n", commands[c], value);
297
case C_MA_print_stats:
301
if (scanf("%d %d %80s", &ii1, &ii2, s) != 3)
302
printf("*** Input read failed for %s\n", commands[c]);
305
value = MA_push_get(ii1, ii2, s, &oi1, &oi2);
306
printf("%s=%d memhandle=%ld index=%ld\n",
307
commands[c], value, (long)oi1, (long)oi2);
310
case C_MA_push_stack:
311
if (scanf("%d %d %80s", &ii1, &ii2, s) != 3)
312
printf("*** Input read failed for %s\n", commands[c]);
315
value = MA_push_stack(ii1, ii2, s, &oi1);
316
printf("%s=%d memhandle=%ld\n",
317
commands[c], value, (long)oi1);
320
case C_MA_set_auto_verify:
321
if (scanf("%d", &ii1) != 1)
322
printf("*** Input read failed for %s\n", commands[c]);
325
value = MA_set_auto_verify(ii1);
326
printf("%s=%d\n", commands[c], value);
329
case C_MA_set_error_print:
330
if (scanf("%d", &ii1) != 1)
331
printf("*** Input read failed for %s\n", commands[c]);
334
value = MA_set_error_print(ii1);
335
printf("%s=%d\n", commands[c], value);
338
case C_MA_set_hard_fail:
339
if (scanf("%d", &ii1) != 1)
340
printf("*** Input read failed for %s\n", commands[c]);
343
value = MA_set_hard_fail(ii1);
344
printf("%s=%d\n", commands[c], value);
348
if (scanf("%d %d %d", &ii1, &ii2, &ii3) != 3)
349
printf("*** Input read failed for %s\n", commands[c]);
352
oi1 = MA_sizeof(ii1, ii2, ii3);
353
printf("%s=%ld\n", commands[c], (long)oi1);
356
case C_MA_sizeof_overhead:
357
if (scanf("%d", &ii1) != 1)
358
printf("*** Input read failed for %s\n", commands[c]);
361
oi1 = MA_sizeof_overhead(ii1);
362
printf("%s=%ld\n", commands[c], (long)oi1);
365
case C_MA_summarize_allocated_blocks:
366
MA_summarize_allocated_blocks();
368
case C_MA_verify_allocator_stuff:
369
value = MA_verify_allocator_stuff();
370
printf("%s=%d\n", commands[c], value);
381
for (ii1 = 0; ii1 < NUM_COMMANDS; ii1++)
382
printf(" %s\n", help[ii1]);
385
printf("*** Unrecognized case '%d' in switch\n", c);