source: tests/alloc2.cfa @ 191a190

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

Removed a fill bug from alloc interface, changed pervious alloc tests (alloc.cfa) to comply with new alloc interface, added new tests for memory allocation (malloc.cfa and alloc2.cfa).

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