Changeset c2b3243 for tests/alloc2.cfa


Ignore:
Timestamp:
Oct 18, 2022, 9:13:33 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
9511841
Parents:
5408b59 (diff), ce7d197 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/alloc2.cfa

    r5408b59 rc2b3243  
     1#include <fstream.hfa>                                                                  // sout
    12#include <malloc.h>                                                                             // malloc_usable_size
    23#include <stdint.h>                                                                             // uintptr_t
     
    45#include <string.h>                                                                             // memcmp
    56
    6 int last_failed;
    77int tests_total;
    88int tests_failed;
     
    1313void test_base( void * ip, size_t size, size_t align ) {
    1414        tests_total += 1;
    15 //      printf( "DEBUG: starting test %d\n", tests_total);
     15        // sout | "DEBUG: starting test" | 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                 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 ) );
     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 );
    1919                tests_failed += 1;
    2020        } // if
    21 //      printf( "DEBUG: done test %d\n", tests_total);
     21        // sout | "DEBUG: done test" | tests_total;
    2222}
    2323
    2424void test_fill( void * ip_, size_t start, size_t end, char fill ) {
    2525        tests_total += 1;
    26 //      printf( "DEBUG: starting test %d\n", tests_total );
     26        // sout | "DEBUG: starting test" | 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                 printf( "failed test %3d: fill C\n", tests_total );
     31                sout | "fill1 failed test" | tests_total | "fill C";
    3232                tests_failed += 1;
    3333        } // if
    34 //      printf( "DEBUG: done test %d\n", tests_total );
     34        // sout | "DEBUG: done test" | tests_total;
    3535}
    3636
    3737void test_fill( void * ip_, size_t start, size_t end, int fill ) {
    3838        tests_total += 1;
    39 //      printf( "DEBUG: starting test %d\n", tests_total );
     39        // sout | "DEBUG: starting test" 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                 printf( "failed test %3d: fill int\n", tests_total );
     44                sout | "fill2 failed test" | tests_total | "fill int";
    4545                tests_failed += 1;
    4646        } // if
    47 //      printf( "DEBUG: done test %d\n", tests_total );
     47        // sout | "DEBUG: done test" | tests_total;
    4848}
    4949
    5050void test_fill( void * ip_, size_t start, size_t end, int * fill ) {
    5151        tests_total += 1;
    52 //      printf( "DEBUG: starting test %d\n", tests_total );
     52        // sout | "DEBUG: starting test" | tests_total;
    5353        bool passed = memcmp((void*)((uintptr_t )ip_ + start ), (void*)fill, end ) == 0;
    5454        if ( ! passed ) {
    55                 printf( "failed test %3d: fill int A\n", tests_total );
     55                sout | "fill3 failed test" | tests_total | "fill int A";
    5656                tests_failed += 1;
    5757        } // if
    58 //      printf( "DEBUG: done test %d\n", tests_total );
     58        // sout | "DEBUG: done test" | tests_total;
    5959}
    6060
    6161void test_fill( void * ip_, size_t start, size_t end, T1 fill ) {
    6262        tests_total += 1;
    63 //      printf( "DEBUG: starting test %d\n", tests_total );
     63        // sout | "DEBUG: starting test" | 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                 printf( "failed test %3d: fill T1\n", tests_total );
     68                sout | "fill4 failed test" | tests_total | "fill T1";
    6969                tests_failed += 1;
    7070        } // if
    71 //      printf( "DEBUG: done test %d\n", tests_total );
     71        // sout | "DEBUG: done test" | tests_total;
    7272}
    7373
    7474void test_fill( void * ip_, size_t start, size_t end, T1 * fill ) {
    7575        tests_total += 1;
    76 //      printf( "DEBUG: starting test %d\n", tests_total );
     76        // sout | "DEBUG: starting test" | tests_total;
    7777        bool passed = memcmp( (void*)((uintptr_t )ip_ + start ), (void*)fill, end ) == 0;
    7878        if ( ! passed ) {
    79                 printf( "failed test %3d: fill T1 A\n", tests_total );
     79                sout | "fill5 failed test" | tests_total | "fill T1 A";
    8080                tests_failed += 1;
    8181        } // if
    82 //      printf( "DEBUG: done test %d\n", tests_total );
     82        // sout | "DEBUG: done test" | tests_total;
    8383}
    8484
    8585void test_use( int * ip, size_t dim ) {
    8686        tests_total += 1;
    87 //      printf( "DEBUG: starting test %d\n", tests_total );
     87        // sout | "DEBUG: starting test" | 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                 printf( "failed test %3d: use int\n", tests_total );
     92                sout | "use1 failed test" | tests_total | "use int";
    9393                tests_failed += 1;
    9494        } // if
    95 //      printf( "DEBUG: done test %d\n", tests_total );
     95        // sout | "DEBUG: done test" | tests_total;
    9696}
    9797
    9898void test_use( T1 * ip, size_t dim ) {
    9999        tests_total += 1;
    100 //      printf( "DEBUG: starting test %d\n", tests_total );
     100        // sout | "DEBUG: starting test" | 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                 printf( "failed test %3d: use T1\n", tests_total );
     105                sout | "use2 failed test" | tests_total | "use T1";
    106106                tests_failed += 1;
    107107        } // if
    108 //      printf( "DEBUG: done test %d\n", tests_total );
     108        // sout | "DEBUG: done test" | tests_total;
    109109}
    110110
     
    117117        char FillC = 'a';
    118118        int * FillA = calloc( dim / 4 );
     119
    119120        T1 FillT1 = { FillT };
    120121        T1 * FillT1A = (T1 *)(void *) malloc( (dim / 4) * sizeof(T1) );
     
    129130        // testing alloc
    130131
    131         last_failed = -1;
    132132        tests_total = 0;
    133133        tests_failed = 0;
     
    153153        free( ip );
    154154
    155         ip = alloc( ((double *)0p)`resize );
     155        ip = alloc( 0p`resize );
    156156        test_base( ip, elemSize, libAlign );
    157157        test_use( ip, elemSize / elemSize );
     
    495495        free( ip );
    496496
    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 )
     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)
    501501
    502502        elemSize = sizeof(T1);
    503503        size = dim * elemSize;
    504         last_failed = -1;
    505504        tests_total = 0;
    506505        tests_failed = 0;
     
    868867        free( t1p );
    869868
    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");
     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;
    874873        free( FillA );
    875874        free( FillT1A );
Note: See TracChangeset for help on using the changeset viewer.