source: tests/alloc2.cfa @ ebb7b66

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since ebb7b66 was f76ff0b, checked in by m3zulfiq <m3zulfiq@…>, 4 years ago

alloc2.txt: added expected output file for test alloc2.cfa. heap.cfa: removed alignment bugs from realloc and resize with alignment. stdlib.hfa: removed debug prints from alloc interface. alloc2.cfa, malloc.cfa: uncommented tests that were previously commented because of a bug in realloc and resize.

  • Property mode set to 100644
File size: 22.4 KB
Line 
1#include <malloc.h>                                                                             // malloc_usable_size
2#include <stdint.h>                                                                             // uintptr_t
3#include <stdlib.hfa>                                                                   // access C malloc, realloc
4#include <string.h>                                                                             // memcmp
5
6int last_failed;
7int tests_total;
8int tests_failed;
9size_t tAlign = 32;
10struct S1 { int data; } __attribute__((aligned(32)));
11typedef struct S1 T1;
12
13void test_base( void * ip, size_t size, size_t align) {
14        tests_total += 1;
15        bool passed = (malloc_size(ip) == size) && (malloc_usable_size(ip) >= size) && (malloc_alignment(ip) == align) && ((uintptr_t)ip % align  == 0);
16        if (!passed) {
17                printf("failed test %3d: %4lu %4lu but got %4lu ( %3lu ) %4lu\n", tests_total, size, align, malloc_size(ip), malloc_usable_size(ip), malloc_alignment(ip));
18                tests_failed += 1;
19        }
20}
21
22void test_fill( void * ip_, size_t start, size_t end, char fill) {
23        tests_total += 1;
24        bool passed = true;
25        char * ip = (char *) ip_;
26        for (i; start ~ end) passed = passed && (ip[i] == fill);
27        if (!passed) {
28                printf("failed test %3d: fill C\n", tests_total);
29                tests_failed += 1;
30        }
31}
32
33void test_fill( void * ip_, size_t start, size_t end, int fill) {
34        tests_total += 1;
35        bool passed = true;
36        int * ip = (int *) ip_;
37        for (i; start ~ end) passed = passed && (ip[i] == fill);
38        if (!passed) {
39                printf("failed test %3d: fill int\n", tests_total);
40                tests_failed += 1;
41        }
42}
43
44void test_fill( void * ip_, size_t start, size_t end, int * fill) {
45        tests_total += 1;
46        bool passed = (memcmp((void*)((uintptr_t)ip_ + start), (void*)fill, end) == 0);
47        if (!passed) {
48                printf("failed test %3d: fill int A\n", tests_total);
49                tests_failed += 1;
50        }
51}
52
53void test_fill( void * ip_, size_t start, size_t end, T1 fill) {
54        tests_total += 1;
55        bool passed = true;
56        T1 * ip = (T1 *) ip_;
57        for (i; start ~ end) passed = passed && (ip[i].data == fill.data);
58        if (!passed) {
59                printf("failed test %3d: fill T1\n", tests_total);
60                tests_failed += 1;
61        }
62}
63
64void test_fill( void * ip_, size_t start, size_t end, T1 * fill) {
65        tests_total += 1;
66        bool passed = (memcmp((void*)((uintptr_t)ip_ + start), (void*)fill, end) == 0);
67        if (!passed) {
68                printf("failed test %3d: fill T1 A\n", tests_total);
69                tests_failed += 1;
70        }
71}
72
73void test_use( int * ip, size_t dim) {
74        tests_total += 1;
75        bool passed = true;
76        for (i; 0 ~ dim) ip[i] = 0xdeadbeef;
77        for (i; 0 ~ dim) passed = passed &&  (ip[i] == 0xdeadbeef);
78        if (!passed) {
79                printf("failed test %3d: use int\n", tests_total);
80                tests_failed += 1;
81        }
82}
83
84void test_use( T1 * ip, size_t dim) {
85        tests_total += 1;
86        bool passed = true;
87        for (i; 0 ~ dim) ip[i].data = 0xdeadbeef;
88        for (i; 0 ~ dim) passed = passed &&  (ip[i].data == 0xdeadbeef);
89        if (!passed) {
90                printf("failed test %3d: use T1\n", tests_total);
91                tests_failed += 1;
92        }
93}
94
95int main( void ) {
96        size_t elemSize = sizeof(int);
97        size_t dim = 8;
98        size_t size = dim * elemSize;
99        size_t align = 64;
100        const size_t libAlign = libAlign();
101
102        int     FillT = 9;
103        char    FillC = 'a';
104        int   * FillA = calloc(dim / 4);
105        T1          FillT1 = { FillT };
106        T1        * FillT1A = (T1 *)(void *) malloc( (dim / 4) * sizeof(T1) );
107        for (i; 0 ~ (dim / 4) ) FillT1A[i] = FillT1;
108
109        int             * ip;
110        int     * op;
111        double  * dp;
112        T1      * t1p;
113        T1          * t1op;
114
115        // testing alloc
116
117        last_failed = -1;
118        tests_total = 0;
119        tests_failed = 0;
120
121        ip = alloc();
122        test_base(ip, elemSize, libAlign);
123        test_use(ip, elemSize / elemSize);
124        free(ip);
125
126        ip = alloc( dim );
127        test_base(ip, size, libAlign);
128        test_use(ip, size / elemSize);
129        free(ip);
130
131        ip = alloc( 0 );
132        test_base(ip, 0, libAlign);
133        free(ip);
134
135        dp = alloc( dim );
136        ip = alloc( dp`resize );
137        test_base(ip, elemSize, libAlign);
138        test_use(ip, elemSize / elemSize);
139        free(ip);
140
141        ip = alloc( ((double*)0p)`resize );
142        test_base(ip, elemSize, libAlign);
143        test_use(ip, elemSize / elemSize);
144        free(ip);
145
146        dp = alloc( dim );
147        ip = alloc( dim, dp`resize );
148        test_base(ip, size, libAlign);
149        test_use(ip, size / elemSize);
150        free(ip);
151
152        dp = alloc( dim );
153        ip = alloc( 0, dp`resize );
154        test_base(ip, 0, libAlign);
155        free(ip);
156
157        ip = alloc( dim, ((double*)0p)`resize );
158        test_base(ip, size, libAlign);
159        test_use(ip, size / elemSize);
160        free(ip);
161
162        ip = alloc( 0, ((double*)0p)`resize );
163        test_base(ip, 0, libAlign);
164        free(ip);
165
166        op = alloc( dim, ((int)0xdeadbeef)`fill );
167        ip = alloc( dim, op`realloc );
168        test_base(ip, size, libAlign);
169        test_fill(ip, 0, dim, (int)0xdeadbeef);
170        test_use(ip, size / elemSize);
171        free(ip);
172
173        op = alloc( dim, ((int)0xdeadbeef)`fill );
174        ip = alloc( 0, op`realloc );
175        test_base(ip, 0, libAlign);
176        free(ip);
177
178        ip = alloc( dim, ((int*)0p)`realloc );
179        test_base(ip, size, libAlign);
180        test_use(ip, size / elemSize);
181        free(ip);
182
183        ip = alloc( 0, ((int*)0p)`realloc );
184        test_base(ip, 0, libAlign);
185        free(ip);
186
187        op = alloc( dim, ((int)0xdeadbeef)`fill );
188        ip = alloc( dim, op`resize );
189        test_base(ip, size, libAlign);
190        test_use(ip, size / elemSize);
191        free(ip);
192
193        ip = alloc( FillC`fill );
194        test_base(ip, elemSize, libAlign);
195        test_fill(ip, 0, elemSize, FillC);
196        test_use(ip, elemSize / elemSize);
197        free(ip);
198
199        ip = alloc( FillT`fill );
200        test_base(ip, elemSize, libAlign);
201        test_fill(ip, 0, 1, FillT);
202        test_use(ip, elemSize / elemSize);
203        free(ip);
204
205        ip = alloc( dim, FillC`fill );
206        test_base(ip, size, libAlign);
207        test_fill(ip, 0, size, FillC);
208        test_use(ip, size / elemSize);
209        free(ip);
210
211        ip = alloc( 0, FillC`fill );
212        test_base(ip, 0, libAlign);
213        free(ip);
214
215        ip = alloc( dim, FillT`fill );
216        test_base(ip, size, libAlign);
217        test_fill(ip, 0, dim, FillT);
218        test_use(ip, size / elemSize);
219        free(ip);
220
221        ip = alloc( 0, FillT`fill );
222        test_base(ip, 0, libAlign);
223        free(ip);
224
225        ip = alloc( dim, [FillA, dim/4]`fill );
226        test_base(ip, size, libAlign);
227        test_fill(ip, 0, size/4, FillA);
228        test_use(ip, size / elemSize);
229        free(ip);
230
231        ip = alloc( 0, [FillA, dim/4]`fill );
232        test_base(ip, 0, libAlign);
233        free(ip);
234
235        op = alloc( dim, ((int)0xdeadbeef)`fill );
236        ip = alloc( dim, op`realloc, FillC`fill );
237        test_base(ip, size, libAlign);
238        test_fill(ip, 0, dim, (int)0xdeadbeef);
239        test_use(ip, size / elemSize);
240        free(ip);
241
242        op = alloc( dim, ((int)0xdeadbeef)`fill );
243        ip = alloc( dim / 4, op`realloc, FillC`fill );
244        test_base(ip, size / 4, libAlign);
245        test_fill(ip, 0, dim / 4, (int)0xdeadbeef);
246        test_use(ip, size / 4 / elemSize);
247        free(ip);
248
249        op = alloc( dim, ((int)0xdeadbeef)`fill );
250        ip = alloc( dim * 4, op`realloc, FillC`fill );
251        test_base(ip, size * 4, libAlign);
252        test_fill(ip, 0, dim, (int)0xdeadbeef);
253        test_fill(ip, size, size * 4, FillC);
254        test_use(ip, size * 4 / elemSize);
255        free(ip);
256
257        op = alloc( dim, ((int)0xdeadbeef)`fill );
258        ip = alloc( 0, op`realloc, FillC`fill );
259        test_base(ip, 0, libAlign);
260        free(ip);
261
262        ip = alloc( dim, ((int*)0p)`realloc, FillC`fill );
263        test_base(ip, size, libAlign);
264        test_fill(ip, 0, size, FillC);
265        test_use(ip, size / elemSize);
266        free(ip);
267
268        ip = alloc( 0, ((int*)0p)`realloc, FillC`fill );
269        test_base(ip, 0, libAlign);
270        free(ip);
271
272        op = alloc( dim, ((int)0xdeadbeef)`fill );
273        ip = alloc( dim, op`realloc, FillT`fill );
274        test_base(ip, size, libAlign);
275        test_fill(ip, 0, dim, (int)0xdeadbeef);
276        test_use(ip, size / elemSize);
277        free(ip);
278
279        op = alloc( dim, ((int)0xdeadbeef)`fill );
280        ip = alloc( dim / 4, op`realloc, FillT`fill );
281        test_base(ip, size / 4, libAlign);
282        test_fill(ip, 0, dim / 4, (int)0xdeadbeef);
283        test_use(ip, size / 4 / elemSize);
284        free(ip);
285
286        op = alloc( dim, ((int)0xdeadbeef)`fill );
287        ip = alloc( dim * 4, op`realloc, FillT`fill );
288        test_base(ip, size * 4, libAlign);
289        test_fill(ip, 0, dim, (int)0xdeadbeef);
290        test_fill(ip, dim, dim * 4, FillT);
291        test_use(ip, size * 4 / elemSize);
292        free(ip);
293
294        op = alloc( dim, ((int)0xdeadbeef)`fill );
295        ip = alloc( 0, op`realloc, FillT`fill );
296        test_base(ip, 0, libAlign);
297        free(ip);
298
299        ip = alloc( dim, ((int*)0p)`realloc, FillT`fill );
300        test_base(ip, size, libAlign);
301        test_fill(ip, 0, dim, FillT);
302        test_use(ip, size / elemSize);
303        free(ip);
304
305        ip = alloc( 0, ((int*)0p)`realloc, FillT`fill );
306        test_base(ip, 0, libAlign);
307        free(ip);
308
309        ip = alloc( align`align );
310        test_base(ip, elemSize, align);
311        test_use(ip, elemSize / elemSize);
312        free(ip);
313
314        ip = alloc( dim, align`align );
315        test_base(ip, size, align);
316        test_use(ip, size / elemSize);
317        free(ip);
318
319        ip = alloc( 0, align`align );
320        test_base(ip, 0, libAlign);
321        free(ip);
322
323        op = alloc( dim, ((int)0xdeadbeef)`fill );
324        ip = alloc( op`realloc, align`align );
325        test_base(ip, elemSize, align);
326        test_fill(ip, 0, 1, (int)0xdeadbeef);
327        test_use(ip, elemSize / elemSize);
328        free(ip);
329
330        ip = alloc( ((int*)0p)`realloc, align`align );
331        test_base(ip, elemSize, align);
332        test_use(ip, elemSize / elemSize);
333        free(ip);
334
335        dp = alloc( dim );
336        ip = alloc( dp`resize, align`align );
337        test_base(ip, elemSize, align);
338        test_use(ip, elemSize / elemSize);
339        free(ip);
340
341        ip = alloc( ((double*)0p)`resize, align`align );
342        test_base(ip, elemSize, align);
343        test_use(ip, elemSize / elemSize);
344        free(ip);
345
346        op = alloc( dim, ((int)0xdeadbeef)`fill);
347        ip = alloc( dim, op`realloc, align`align );
348        test_base(ip, size, align);
349        test_fill(ip, 0, dim, (int)0xdeadbeef);
350        test_use(ip, size / elemSize);
351        free(ip);
352
353        op = alloc( dim, ((int)0xdeadbeef)`fill );
354        ip = alloc( 0, op`realloc, align`align );
355        test_base(ip, 0, libAlign);
356        free(ip);
357
358        ip = alloc( dim, ((int*)0p)`realloc, align`align );
359        test_base(ip, size, align);
360        test_use(ip, size / elemSize);
361        free(ip);
362
363        ip = alloc( 0, ((int*)0p)`realloc, align`align );
364        test_base(ip, 0, libAlign);
365        free(ip);
366
367        ip = alloc( align`align, FillC`fill );
368        test_base(ip, elemSize, align);
369        test_fill(ip, 0, elemSize, FillC);
370        test_use(ip, elemSize / elemSize);
371        free(ip);
372
373        ip = alloc( align`align, FillT`fill );
374        test_base(ip, elemSize, align);
375        test_fill(ip, 0, 1, FillT);
376        test_use(ip, elemSize / elemSize);
377        free(ip);
378
379        ip = alloc( dim, align`align, FillC`fill );
380        test_base(ip, size, align);
381        test_fill(ip, 0, size, FillC);
382        test_use(ip, size / elemSize);
383        free(ip);
384
385        ip = alloc( 0, align`align, FillC`fill );
386        test_base(ip, 0, libAlign);
387        free(ip);
388
389        ip = alloc( dim, align`align, FillT`fill );
390        test_base(ip, size, align);
391        test_fill(ip, 0, dim, FillT);
392        test_use(ip, size / elemSize);
393        free(ip);
394
395        ip = alloc( 0, align`align, FillT`fill );
396        test_base(ip, 0, libAlign);
397        free(ip);
398
399        ip = alloc( dim, align`align, [FillA, dim/4]`fill );
400        test_base(ip, size, align);
401        test_fill(ip, 0, size/4, FillA);
402        test_use(ip, size / elemSize);
403        free(ip);
404
405        ip = alloc( 0, align`align, [FillA, dim/4]`fill );
406        test_base(ip, 0, libAlign);
407        free(ip);
408
409        op = alloc( dim, ((int)0xdeadbeef)`fill );
410        ip = alloc( dim, op`realloc, align`align, FillC`fill );
411        test_base(ip, size, align);
412        test_fill(ip, 0, dim, (int)0xdeadbeef);
413        test_use(ip, size / elemSize);
414        free(ip);
415
416        op = alloc( dim, ((int)0xdeadbeef)`fill );
417        ip = alloc( dim / 4, op`realloc, align`align, FillC`fill );
418        test_base(ip, size / 4, align);
419        test_fill(ip, 0, dim / 4, (int)0xdeadbeef);
420        test_use(ip, size / 4 / elemSize);
421        free(ip);
422
423        op = alloc( dim, ((int)0xdeadbeef)`fill );
424        ip = alloc( dim * 4, op`realloc, align`align, FillC`fill );
425        test_base(ip, size * 4, align);
426        test_fill(ip, 0, dim, (int)0xdeadbeef);
427        test_fill(ip, size, size * 4, FillC);
428        test_use(ip, size * 4 / elemSize);
429        free(ip);
430
431        op = alloc( dim, ((int)0xdeadbeef)`fill );
432        ip = alloc( 0, op`realloc, align`align, FillC`fill );
433        test_base(ip, 0, libAlign);
434        free(ip);
435
436        ip = alloc( dim, ((int*)0p)`realloc, align`align, FillC`fill );
437        test_base(ip, size, align);
438        test_fill(ip, 0, size, FillC);
439        test_use(ip, size / elemSize);
440        free(ip);
441
442        ip = alloc( 0, ((int*)0p)`realloc, align`align, FillC`fill );
443        test_base(ip, 0, libAlign);
444        free(ip);
445
446        op = alloc( dim, ((int)0xdeadbeef)`fill );
447        ip = alloc( dim, op`realloc, align`align, FillT`fill );
448        test_base(ip, size, align);
449        test_fill(ip, 0, dim, (int)0xdeadbeef);
450        test_use(ip, size / elemSize);
451        free(ip);
452
453        op = alloc( dim, ((int)0xdeadbeef)`fill );
454        ip = alloc( dim / 4, op`realloc, align`align, FillT`fill );
455        test_base(ip, size / 4, align);
456        test_fill(ip, 0, dim / 4, (int)0xdeadbeef);
457        test_use(ip, size / 4 / elemSize);
458        free(ip);
459
460        op = alloc( dim, ((int)0xdeadbeef)`fill );
461        ip = alloc( dim * 4, op`realloc, align`align, FillT`fill );
462        test_base(ip, size * 4, align);
463        test_fill(ip, 0, dim, (int)0xdeadbeef);
464        test_fill(ip, dim, dim * 4, FillT);
465        test_use(ip, size * 4 / elemSize);
466        free(ip);
467
468        op = alloc( dim, ((int)0xdeadbeef)`fill );
469        ip = alloc( 0, op`realloc, align`align, FillT`fill );
470        test_base(ip, 0, libAlign);
471        free(ip);
472
473        ip = alloc( dim, ((int*)0p)`realloc, align`align, FillT`fill );
474        test_base(ip, size, align);
475        test_fill(ip, 0, dim, FillT);
476        test_use(ip, size / elemSize);
477        free(ip);
478
479        ip = alloc( 0, ((int*)0p)`realloc, align`align, FillT`fill );
480        test_base(ip, 0, libAlign);
481        free(ip);
482
483        if (tests_failed == 0) printf("PASSED alloc tests\n\n");
484        else printf("failed alloc tests : %d/%d\n\n", tests_failed, tests_total);
485
486        // testing alloc (aligned struct)
487
488        elemSize = sizeof(T1);
489        size = dim * elemSize;
490        last_failed = -1;
491        tests_total = 0;
492        tests_failed = 0;
493
494        t1p = alloc();
495        test_base(t1p, elemSize, tAlign);
496        test_use(t1p, elemSize / elemSize);
497        free(t1p);
498
499        t1p = alloc( dim );
500        test_base(t1p, size, tAlign);
501        test_use(t1p, size / elemSize);
502        free(t1p);
503
504        t1p = alloc( 0 );
505        test_base(t1p, 0, libAlign);
506        free(t1p);
507
508        dp = alloc( dim );
509        t1p = alloc( dp`resize );
510        test_base(t1p, elemSize, tAlign);
511        test_use(t1p, elemSize / elemSize);
512        free(t1p);
513
514        t1p = alloc( ((double*)0p)`resize );
515        test_base(t1p, elemSize, tAlign);
516        test_use(t1p, elemSize / elemSize);
517        free(t1p);
518
519        dp = alloc( dim );
520        t1p = alloc( dim, dp`resize );
521        test_base(t1p, size, tAlign);
522        test_use(t1p, size / elemSize);
523        free(t1p);
524
525        dp = alloc( dim );
526        t1p = alloc( 0, dp`resize );
527        test_base(t1p, 0, libAlign);
528        free(t1p);
529
530        t1p = alloc( dim, ((double*)0p)`resize );
531        test_base(t1p, size, tAlign);
532        test_use(t1p, size / elemSize);
533        free(t1p);
534
535        t1p = alloc( 0, ((double*)0p)`resize );
536        test_base(t1p, 0, libAlign);
537        free(t1p);
538
539        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
540        t1p = alloc( dim, t1op`realloc );
541        test_base(t1p, size, tAlign);
542        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
543        test_use(t1p, size / elemSize);
544        free(t1p);
545
546        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
547        t1p = alloc( 0, t1op`realloc );
548        test_base(t1p, 0, libAlign);
549        free(t1p);
550
551        t1p = alloc( dim, ((T1*)0p)`realloc );
552        test_base(t1p, size, tAlign);
553        test_use(t1p, size / elemSize);
554        free(t1p);
555
556        t1p = alloc( 0, ((T1*)0p)`realloc );
557        test_base(t1p, 0, libAlign);
558        free(t1p);
559
560        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
561        t1p = alloc( dim, t1op`resize );
562        test_base(t1p, size, tAlign);
563        test_use(t1p, size / elemSize);
564        free(t1p);
565
566        t1p = alloc( FillC`fill );
567        test_base(t1p, elemSize, tAlign);
568        test_fill(t1p, 0, elemSize, FillC);
569        test_use(t1p, elemSize / elemSize);
570        free(t1p);
571
572        t1p = alloc( FillT1`fill );
573        test_base(t1p, elemSize, tAlign);
574        test_fill(t1p, 0, 1, FillT1);
575        test_use(t1p, elemSize / elemSize);
576        free(t1p);
577
578        t1p = alloc( dim, FillC`fill );
579        test_base(t1p, size, tAlign);
580        test_fill(t1p, 0, size, FillC);
581        test_use(t1p, size / elemSize);
582        free(t1p);
583
584        t1p = alloc( 0, FillC`fill );
585        test_base(t1p, 0, libAlign);
586        free(t1p);
587
588        t1p = alloc( dim, FillT1`fill );
589        test_base(t1p, size, tAlign);
590        test_fill(t1p, 0, dim, FillT1);
591        test_use(t1p, size / elemSize);
592        free(t1p);
593
594        t1p = alloc( 0, FillT1`fill );
595        test_base(t1p, 0, libAlign);
596        free(t1p);
597
598        t1p = alloc( dim, [FillT1A, dim / 4]`fill );
599        test_base(t1p, size, tAlign);
600        test_fill(t1p, 0, size/4, FillT1A);
601        test_use(t1p, size / elemSize);
602        free(t1p);
603
604        t1p = alloc( 0, [FillT1A, dim / 4]`fill );
605        test_base(t1p, 0, libAlign);
606        free(t1p);
607
608        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
609        t1p = alloc( dim, t1op`realloc, FillC`fill );
610        test_base(t1p, size, tAlign);
611        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
612        test_use(t1p, size / elemSize);
613        free(t1p);
614
615        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
616        t1p = alloc( dim / 4, t1op`realloc, FillC`fill );
617        test_base(t1p, size / 4, tAlign);
618        test_fill(t1p, 0, dim / 4, (T1){0xdeadbeef});
619        test_use(t1p, size / 4 / elemSize);
620        free(t1p);
621
622        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
623        t1p = alloc( dim * 4, t1op`realloc, FillC`fill );
624        test_base(t1p, size * 4, tAlign);
625        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
626        test_fill(t1p, size, size * 4, FillC);
627        test_use(t1p, size * 4 / elemSize);
628        free(t1p);
629
630        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
631        t1p = alloc( 0, t1op`realloc, FillC`fill );
632        test_base(t1p, 0, libAlign);
633        free(t1p);
634
635        t1p = alloc( dim, ((T1*)0p)`realloc, FillC`fill );
636        test_base(t1p, size, tAlign);
637        test_fill(t1p, 0, size, FillC);
638        test_use(t1p, size / elemSize);
639        free(t1p);
640
641        t1p = alloc( 0, ((T1*)0p)`realloc, FillC`fill );
642        test_base(t1p, 0, libAlign);
643        free(t1p);
644
645        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
646        t1p = alloc( dim, t1op`realloc, FillT1`fill );
647        test_base(t1p, size, tAlign);
648        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
649        test_use(t1p, size / elemSize);
650        free(t1p);
651
652        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
653        t1p = alloc( dim / 4, t1op`realloc, FillT1`fill );
654        test_base(t1p, size / 4, tAlign);
655        test_fill(t1p, 0, dim / 4, (T1){0xdeadbeef});
656        test_use(t1p, size / 4 / elemSize);
657        free(t1p);
658
659        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
660        t1p = alloc( dim * 4, t1op`realloc, FillT1`fill );
661        test_base(t1p, size * 4, tAlign);
662        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
663        test_fill(t1p, dim, dim * 4, FillT1);
664        test_use(t1p, size * 4 / elemSize);
665        free(t1p);
666
667        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
668        t1p = alloc( 0, t1op`realloc, FillT1`fill );
669        test_base(t1p, 0, libAlign);
670        free(t1p);
671
672        t1p = alloc( dim, ((T1*)0p)`realloc, FillT1`fill );
673        test_base(t1p, size, tAlign);
674        test_fill(t1p, 0, dim, FillT1);
675        test_use(t1p, size / elemSize);
676        free(t1p);
677
678        t1p = alloc( 0, ((T1*)0p)`realloc, FillT1`fill );
679        test_base(t1p, 0, libAlign);
680        free(t1p);
681
682        t1p = alloc( align`align );
683        test_base(t1p, elemSize, align);
684        test_use(t1p, elemSize / elemSize);
685        free(t1p);
686
687        t1p = alloc( dim, align`align );
688        test_base(t1p, size, align);
689        test_use(t1p, size / elemSize);
690        free(t1p);
691
692        t1p = alloc( 0, align`align );
693        test_base(t1p, 0, libAlign);
694        free(t1p);
695
696        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
697        t1p = alloc( t1op`realloc, align`align );
698        test_base(t1p, elemSize, align);
699        test_fill(t1p, 0, 1, (T1){0xdeadbeef});
700        test_use(t1p, elemSize / elemSize);
701        free(t1p);
702
703        t1p = alloc( ((T1*)0p)`realloc, align`align );
704        test_base(t1p, elemSize, align);
705        test_use(t1p, elemSize / elemSize);
706        free(t1p);
707
708        dp = alloc( dim );
709        t1p = alloc( dp`resize, align`align );
710        test_base(t1p, elemSize, align);
711        test_use(t1p, elemSize / elemSize);
712        free(t1p);
713
714        t1p = alloc( ((double*)0p)`resize, align`align );
715        test_base(t1p, elemSize, align);
716        test_use(t1p, elemSize / elemSize);
717        free(t1p);
718
719        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
720        t1p = alloc( dim, t1op`realloc, align`align );
721        test_base(t1p, size, align);
722        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
723        test_use(t1p, size / elemSize);
724        free(t1p);
725
726        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
727        t1p = alloc( 0, t1op`realloc, align`align );
728        test_base(t1p, 0, libAlign);
729        free(t1p);
730
731        t1p = alloc( dim, ((T1*)0p)`realloc, align`align );
732        test_base(t1p, size, align);
733        test_use(t1p, size / elemSize);
734        free(t1p);
735
736        t1p = alloc( 0, ((T1*)0p)`realloc, align`align );
737        test_base(t1p, 0, libAlign);
738        free(t1p);
739
740        t1p = alloc( align`align, FillC`fill );
741        test_base(t1p, elemSize, align);
742        test_fill(t1p, 0, elemSize, FillC);
743        test_use(t1p, elemSize / elemSize);
744        free(t1p);
745
746        t1p = alloc( align`align, FillT1`fill );
747        test_base(t1p, elemSize, align);
748        test_fill(t1p, 0, 1, FillT1);
749        test_use(t1p, elemSize / elemSize);
750        free(t1p);
751
752        t1p = alloc( dim, align`align, FillC`fill );
753        test_base(t1p, size, align);
754        test_fill(t1p, 0, size, FillC);
755        test_use(t1p, size / elemSize);
756        free(t1p);
757
758        t1p = alloc( 0, align`align, FillC`fill );
759        test_base(t1p, 0, libAlign);
760        free(t1p);
761
762        t1p = alloc( dim, align`align, FillT1`fill );
763        test_base(t1p, size, align);
764        test_fill(t1p, 0, dim, FillT1);
765        test_use(t1p, size / elemSize);
766        free(t1p);
767
768        t1p = alloc( 0, align`align, FillT1`fill );
769        test_base(t1p, 0, libAlign);
770        free(t1p);
771
772        t1p = alloc( dim, align`align, [FillT1A, dim / 4]`fill );
773        test_base(t1p, size, align);
774        test_fill(t1p, 0, size/4, FillT1A);
775        test_use(t1p, size / elemSize);
776        free(t1p);
777
778        t1p = alloc( 0, align`align, [FillT1A, dim / 4]`fill );
779        test_base(t1p, 0, libAlign);
780        free(t1p);
781
782        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
783        t1p = alloc( dim, t1op`realloc, align`align, FillC`fill );
784        test_base(t1p, size, align);
785        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
786        test_use(t1p, size / elemSize);
787        free(t1p);
788
789        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
790        t1p = alloc( dim / 4, t1op`realloc, align`align, FillC`fill );
791        test_base(t1p, size / 4, align);
792        test_fill(t1p, 0, dim / 4, (T1){0xdeadbeef});
793        test_use(t1p, size / 4 / elemSize);
794        free(t1p);
795
796        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
797        t1p = alloc( dim * 4, t1op`realloc, align`align, FillC`fill );
798        test_base(t1p, size * 4, align);
799        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
800        test_fill(t1p, size, size * 4, FillC);
801        test_use(t1p, size * 4 / elemSize);
802        free(t1p);
803
804        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
805        t1p = alloc( 0, t1op`realloc, align`align, FillC`fill );
806        test_base(t1p, 0, libAlign);
807        free(t1p);
808
809        t1p = alloc( dim, ((T1*)0p)`realloc, align`align, FillC`fill );
810        test_base(t1p, size, align);
811        test_fill(t1p, 0, size, FillC);
812        test_use(t1p, size / elemSize);
813        free(t1p);
814
815        t1p = alloc( 0, ((T1*)0p)`realloc, align`align, FillC`fill );
816        test_base(t1p, 0, libAlign);
817        free(t1p);
818
819        t1op = alloc( dim, ((T1){0xdeadbeef})`fill);
820        t1p = alloc( dim, t1op`realloc, align`align, FillT1`fill );
821        test_base(t1p, size, align);
822        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
823        test_use(t1p, size / elemSize);
824        free(t1p);
825
826        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
827        t1p = alloc( dim / 4, t1op`realloc, align`align, FillT1`fill );
828        test_base(t1p, size / 4, align);
829        test_fill(t1p, 0, dim / 4, (T1){0xdeadbeef});
830        test_use(t1p, size / 4 / elemSize);
831        free(t1p);
832
833        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
834        t1p = alloc( dim * 4, t1op`realloc, align`align, FillT1`fill );
835        test_base(t1p, size * 4, align);
836        test_fill(t1p, 0, dim, (T1){0xdeadbeef});
837        test_fill(t1p, dim, dim * 4, FillT1);
838        test_use(t1p, size * 4 / elemSize);
839        free(t1p);
840
841        t1op = alloc( dim, ((T1){0xdeadbeef})`fill );
842        t1p = alloc( 0, t1op`realloc, align`align, FillT1`fill );
843        test_base(t1p, 0, libAlign);
844        free(t1p);
845
846        t1p = alloc( dim, ((T1*)0p)`realloc, align`align, FillT1`fill );
847        test_base(t1p, size, align);
848        test_fill(t1p, 0, dim, FillT1);
849        test_use(t1p, size / elemSize);
850        free(t1p);
851
852        t1p = alloc( 0, ((T1*)0p)`realloc, align`align, FillT1`fill );
853        test_base(t1p, 0, libAlign);
854        free(t1p);
855
856        if (tests_failed == 0) printf("PASSED alloc tests (aligned struct)\n\n");
857        else printf("failed alloc tests (aligned struct) : %d/%d\n\n", tests_failed, tests_total);
858
859        printf("(if applicable) alignment error below indicates memory trashing caused by test_use.\n\n");
860        free(FillA);
861        free(FillT1A);
862        return 0;
863} // main
Note: See TracBrowser for help on using the repository browser.