Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/alloc2.cfa

    r116a2ea r1988572  
    1 #include <fstream.hfa>                                                                  // sout
    21#include <malloc.h>                                                                             // malloc_usable_size
    32#include <stdint.h>                                                                             // uintptr_t
     
    54#include <string.h>                                                                             // memcmp
    65
     6int last_failed;
    77int tests_total;
    88int tests_failed;
     
    1313void test_base( void * ip, size_t size, size_t align ) {
    1414        tests_total += 1;
    15         // sout | "DEBUG: starting test" | tests_total;
     15//      printf( "DEBUG: starting test %d\n", tests_total);
    1616        bool passed = (malloc_size( ip ) == size) && (malloc_usable_size( ip ) >= size) && (malloc_alignment( ip ) == align) && ((uintptr_t)ip % align  == 0);
    1717        if ( ! passed ) {
    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 );
     18                printf( "failed test %3d: %4zu %4zu but got %4zu ( %3zu ) %4zu\n", tests_total, size, align, malloc_size( ip ), malloc_usable_size( ip ), malloc_alignment( ip ) );
    1919                tests_failed += 1;
    2020        } // if
    21         // sout | "DEBUG: done test" | tests_total;
     21//      printf( "DEBUG: done test %d\n", tests_total);
    2222}
    2323
    2424void test_fill( void * ip_, size_t start, size_t end, char fill ) {
    2525        tests_total += 1;
    26         // sout | "DEBUG: starting test" | tests_total;
     26//      printf( "DEBUG: starting test %d\n", tests_total );
    2727        bool passed = true;
    2828        char * ip = (char *) ip_;
    2929        for ( i; start ~ end ) passed = passed && (ip[i] == fill);
    3030        if ( ! passed ) {
    31                 sout | "fill1 failed test" | tests_total | "fill C";
     31                printf( "failed test %3d: fill C\n", tests_total );
    3232                tests_failed += 1;
    3333        } // if
    34         // sout | "DEBUG: done test" | tests_total;
     34//      printf( "DEBUG: done test %d\n", tests_total );
    3535}
    3636
    3737void test_fill( void * ip_, size_t start, size_t end, int fill ) {
    3838        tests_total += 1;
    39         // sout | "DEBUG: starting test" tests_total;
     39//      printf( "DEBUG: starting test %d\n", tests_total );
    4040        bool passed = true;
    4141        int * ip = (int *)ip_;
    42         for ( i; start ~ end ) passed = passed && (ip[i] == fill);
     42        for (i; start ~ end ) passed = passed && (ip[i] == fill);
    4343        if ( ! passed ) {
    44                 sout | "fill2 failed test" | tests_total | "fill int";
     44                printf( "failed test %3d: fill int\n", tests_total );
    4545                tests_failed += 1;
    4646        } // if
    47         // sout | "DEBUG: done test" | tests_total;
     47//      printf( "DEBUG: done test %d\n", tests_total );
    4848}
    4949
    5050void test_fill( void * ip_, size_t start, size_t end, int * fill ) {
    5151        tests_total += 1;
    52         // sout | "DEBUG: starting test" | tests_total;
     52//      printf( "DEBUG: starting test %d\n", tests_total );
    5353        bool passed = memcmp((void*)((uintptr_t )ip_ + start ), (void*)fill, end ) == 0;
    5454        if ( ! passed ) {
    55                 sout | "fill3 failed test" | tests_total | "fill int A";
     55                printf( "failed test %3d: fill int A\n", tests_total );
    5656                tests_failed += 1;
    5757        } // if
    58         // sout | "DEBUG: done test" | tests_total;
     58//      printf( "DEBUG: done test %d\n", tests_total );
    5959}
    6060
    6161void test_fill( void * ip_, size_t start, size_t end, T1 fill ) {
    6262        tests_total += 1;
    63         // sout | "DEBUG: starting test" | tests_total;
     63//      printf( "DEBUG: starting test %d\n", tests_total );
    6464        bool passed = true;
    6565        T1 * ip = (T1 *) ip_;
    6666        for ( i; start ~ end ) passed = passed && (ip[i].data == fill.data );
    6767        if ( ! passed ) {
    68                 sout | "fill4 failed test" | tests_total | "fill T1";
     68                printf( "failed test %3d: fill T1\n", tests_total );
    6969                tests_failed += 1;
    7070        } // if
    71         // sout | "DEBUG: done test" | tests_total;
     71//      printf( "DEBUG: done test %d\n", tests_total );
    7272}
    7373
    7474void test_fill( void * ip_, size_t start, size_t end, T1 * fill ) {
    7575        tests_total += 1;
    76         // sout | "DEBUG: starting test" | tests_total;
     76//      printf( "DEBUG: starting test %d\n", tests_total );
    7777        bool passed = memcmp( (void*)((uintptr_t )ip_ + start ), (void*)fill, end ) == 0;
    7878        if ( ! passed ) {
    79                 sout | "fill5 failed test" | tests_total | "fill T1 A";
     79                printf( "failed test %3d: fill T1 A\n", tests_total );
    8080                tests_failed += 1;
    8181        } // if
    82         // sout | "DEBUG: done test" | tests_total;
     82//      printf( "DEBUG: done test %d\n", tests_total );
    8383}
    8484
    8585void test_use( int * ip, size_t dim ) {
    8686        tests_total += 1;
    87         // sout | "DEBUG: starting test" | tests_total;
     87//      printf( "DEBUG: starting test %d\n", tests_total );
    8888        bool passed = true;
    8989        for ( i; 0 ~ dim ) ip[i] = 0xdeadbeef;
    9090        for ( i; 0 ~ dim ) passed = passed &&  (ip[i] == 0xdeadbeef);
    9191        if ( ! passed ) {
    92                 sout | "use1 failed test" | tests_total | "use int";
     92                printf( "failed test %3d: use int\n", tests_total );
    9393                tests_failed += 1;
    9494        } // if
    95         // sout | "DEBUG: done test" | tests_total;
     95//      printf( "DEBUG: done test %d\n", tests_total );
    9696}
    9797
    9898void test_use( T1 * ip, size_t dim ) {
    9999        tests_total += 1;
    100         // sout | "DEBUG: starting test" | tests_total;
     100//      printf( "DEBUG: starting test %d\n", tests_total );
    101101        bool passed = true;
    102102        for ( i; 0 ~ dim ) ip[i].data = 0xdeadbeef;
    103103        for ( i; 0 ~ dim ) passed = passed &&  (ip[i].data == 0xdeadbeef);
    104104        if ( ! passed ) {
    105                 sout | "use2 failed test" | tests_total | "use T1";
     105                printf( "failed test %3d: use T1\n", tests_total );
    106106                tests_failed += 1;
    107107        } // if
    108         // sout | "DEBUG: done test" | tests_total;
     108//      printf( "DEBUG: done test %d\n", tests_total );
    109109}
    110110
     
    117117        char FillC = 'a';
    118118        int * FillA = calloc( dim / 4 );
    119 
    120119        T1 FillT1 = { FillT };
    121120        T1 * FillT1A = (T1 *)(void *) malloc( (dim / 4) * sizeof(T1) );
     
    130129        // testing alloc
    131130
     131        last_failed = -1;
    132132        tests_total = 0;
    133133        tests_failed = 0;
     
    153153        free( ip );
    154154
    155         ip = alloc( 0p`resize );
     155        ip = alloc( ((double *)0p)`resize );
    156156        test_base( ip, elemSize, libAlign );
    157157        test_use( ip, elemSize / elemSize );
     
    495495        free( ip );
    496496
    497         if ( tests_failed == 0 ) sout | "PASSED alloc tests" | nl | nl;
    498         else sout | "failed alloc tests :" | tests_failed | tests_total | nl | nl;
    499 
    500         // testing alloc (aligned struct)
     497        if ( tests_failed == 0 ) printf( "PASSED alloc tests\n\n" );
     498        else printf( "failed alloc tests : %d/%d\n\n", tests_failed, tests_total );
     499
     500        // testing alloc ( aligned struct )
    501501
    502502        elemSize = sizeof(T1);
    503503        size = dim * elemSize;
     504        last_failed = -1;
    504505        tests_total = 0;
    505506        tests_failed = 0;
     
    867868        free( t1p );
    868869
    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;
    871 
    872         sout | "(if applicable) alignment error below indicates memory trashing caused by test_use." | nl | nl;
     870        if ( tests_failed == 0) printf( "PASSED alloc tests (aligned struct)\n\n");
     871        else printf( "failed alloc tests ( aligned struct ) : %d/%d\n\n", tests_failed, tests_total );
     872
     873        printf( "(if applicable) alignment error below indicates memory trashing caused by test_use.\n\n");
    873874        free( FillA );
    874875        free( FillT1A );
Note: See TracChangeset for help on using the changeset viewer.