source: tests/alloc2.cfa@ bada452

Last change on this file since bada452 was 116a2ea, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

new heap and associated tests updated

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