Changeset df6cc9d for tests


Ignore:
Timestamp:
Oct 19, 2022, 4:43:26 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
1a45263
Parents:
9cd5bd2 (diff), 135143ba (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' into pthread-emulation

Location:
tests
Files:
12 added
8 edited
5 moved

Legend:

Unmodified
Added
Removed
  • tests/.expect/alloc.txt

    r9cd5bd2 rdf6cc9d  
    3535CFA realloc array alloc, fill
    36360xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede
     37CFA realloc array alloc, 5
     380xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5
     39CFA realloc array alloc, 5
     400xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
     41CFA realloc array alloc, 5
     420xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5 0x5
    3743
    3844C   memalign 42 42.5
  • tests/Makefile.am

    r9cd5bd2 rdf6cc9d  
    7676        pybin/tools.py \
    7777        long_tests.hfa \
    78         .in/parseconfig-all.txt \
    79         .in/parseconfig-errors.txt \
    80         .in/parseconfig-missing.txt \
     78        avltree/avl-private.h \
     79        avltree/avl.h \
     80        concurrent/clib_tls.c \
     81        concurrent/clib.c \
     82        configs/.in/parseconfig-all.txt \
     83        configs/.in/parseconfig-errors.txt \
     84        configs/.in/parseconfig-missing.txt \
     85        exceptions/except-io.hfa \
     86        exceptions/with-threads.hfa \
    8187        io/.in/io.data \
    8288        io/.in/many_read.data \
    83         avltree/avl.h \
    84         avltree/avl-private.h \
    85         concurrent/clib.c \
    86         concurrent/clib_tls.c \
    87         exceptions/with-threads.hfa \
    88         exceptions/except-io.hfa \
     89        meta/fork+exec.hfa \
    8990        unified_locking/mutex_test.hfa
    9091
  • tests/alloc.cfa

    r9cd5bd2 rdf6cc9d  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 18 17:13:52 2022
    13 // Update Count     : 433
     12// Last Modified On : Fri Oct 14 09:31:39 2022
     13// Update Count     : 491
    1414//
    1515
     
    3434        ip = (int *)malloc( sizeof(*ip) );                                      // C malloc, type unsafe
    3535        *ip = 0xdeadbeef;
    36         printf( "C   malloc %#x\n", *ip );
     36        sout | "C   malloc" | hex(*ip);
    3737        free( ip );
    3838
    3939        ip = malloc();                                                                          // CFA malloc, type safe
    4040        *ip = 0xdeadbeef;
    41         printf( "CFA malloc %#x\n", *ip );
     41        sout | "CFA malloc" | hex(*ip);
    4242        free( ip );
    4343
    4444        ip = alloc();                                                                           // CFA alloc, type safe
    4545        *ip = 0xdeadbeef;
    46         printf( "CFA alloc %#x\n", *ip );
     46        sout | "CFA alloc" | hex(*ip);
    4747        free( ip );
    4848
    4949        ip = alloc( fill`fill );                                                        // CFA alloc, fill
    50         printf( "CFA alloc, fill %08x\n", *ip );
     50        sout | "CFA alloc, fill" | wd(8, nobase(hex(*ip)));
    5151        free( ip );
    5252
    5353        ip = alloc( 3`fill );                                                           // CFA alloc, fill
    54         printf( "CFA alloc, fill %d\n", *ip );
     54        sout | "CFA alloc, fill" | *ip;
    5555        free( ip );
    5656
    5757
    5858        // allocation, array types
    59         printf( "\n" );
     59        sout | nl;
    6060
    6161        ip = (int *)calloc( dim, sizeof( *ip ) );                       // C array calloc, type unsafe
    62         printf( "C   array calloc, fill 0\n" );
    63         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    64         printf( "\n" );
     62        sout | "C   array calloc, fill 0";
     63        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     64        sout | nl;
    6565        free( ip );
    6666
    6767        ip = calloc( dim );                                                                     // CFA array calloc, type safe
    68         printf( "CFA array calloc, fill 0\n" );
    69         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    70         printf( "\n" );
     68        sout | "CFA array calloc, fill 0";
     69        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     70        sout | nl;
    7171        free( ip );
    7272
    7373        ip = alloc( dim );                                                                      // CFA array alloc, type safe
    7474        for ( i; dim ) { ip[i] = 0xdeadbeef; }
    75         printf( "CFA array alloc, no fill\n" );
    76         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    77         printf( "\n" );
     75        sout | "CFA array alloc, no fill";
     76        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     77        sout | nl;
    7878        free( ip );
    7979
    8080        ip = alloc( 2 * dim, fill`fill );                                       // CFA array alloc, fill
    81         printf( "CFA array alloc, fill %#hhx\n", fill );
    82         for ( i; 2 * dim ) { printf( "%#x ", ip[i] ); }
    83         printf( "\n" );
     81        sout | "CFA array alloc, fill" | hex(fill);
     82        for ( i; 2 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     83        sout | nl;
    8484        free( ip );
    8585
    8686        ip = alloc( 2 * dim, ((int)0xdeadbeef)`fill );          // CFA array alloc, fill
    87         printf( "CFA array alloc, fill %#hhx\n", 0xdeadbeef );
    88         for ( i; 2 * dim ) { printf( "%#x ", ip[i] ); }
    89         printf( "\n" );
     87        sout | "CFA array alloc, fill" | hex((char)0xdeadbeef);
     88        for ( i; 2 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     89        sout | nl;
    9090        // do not free
    9191
    9292        ip1 = alloc( 2 * dim, [ip, 2 * dim]`fill );                     // CFA array alloc, fill
    93         printf( "CFA array alloc, fill from array\n" );
    94         for ( i; 2 * dim ) { printf( "%#x %#x, ", ip[i], ip1[i] ); }
     93        sout | "CFA array alloc, fill from array";
     94        for ( i; 2 * dim ) { sout | hex(ip[i]) | hex(ip1[i]) | ", " | nonl; }
    9595        free( ip1 );
    96         printf( "\n" );
     96        sout | nl;
    9797
    9898
    9999        // realloc, non-array types
    100         printf( "\n" );
     100        sout | nl;
    101101
    102102        ip = (int *)realloc( ip, dim * sizeof(*ip) );           // C realloc
    103         printf( "C realloc\n" );
    104         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    105         printf( "\n" );
     103        sout | "C realloc";
     104        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     105        sout | nl;
    106106        // do not free
    107107
    108108        ip = realloc( ip, 2 * dim * sizeof(*ip) );                      // CFA realloc
    109109        for ( i; dim ~ 2 * dim ) { ip[i] = 0x1010101; }
    110         printf( "CFA realloc\n" );
    111         for ( i; 2 * dim ) { printf( "%#x ", ip[i] ); }
    112         printf( "\n" );
     110        sout | "CFA realloc";
     111        for ( i; 2 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     112        sout | nl;
    113113        // do not free
    114114
    115115
    116116        // realloc, array types
    117         printf( "\n" );
     117        sout | nl;
    118118
    119119        ip = alloc( dim, ip`realloc );                                          // CFA realloc array alloc
    120120        for ( i; dim ) { ip[i] = 0xdeadbeef; }
    121         printf( "CFA realloc array alloc\n" );
    122         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    123         printf( "\n" );
     121        sout | "CFA realloc array alloc";
     122        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     123        sout | nl;
    124124        // do not free
    125125
    126126        ip = alloc( 2 * dim, ip`realloc );                                      // CFA realloc array alloc
    127127        for ( i; dim ~ 2 * dim ) { ip[i] = 0x1010101; }         // fill upper part
    128         printf( "CFA realloc array alloc\n" );
    129         for ( i; 2 * dim ) { printf( "%#x ", ip[i] ); }
    130         printf( "\n" );
     128        sout | "CFA realloc array alloc";
     129        for ( i; 2 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     130        sout | nl;
    131131        // do not free
    132132
    133133        ip = alloc( dim, ip`realloc );                                          // CFA realloc array alloc
    134         printf( "CFA realloc array alloc\n" );
    135         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    136         printf( "\n" );
     134        sout | "CFA realloc array alloc";
     135        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     136        sout | nl;
    137137        // do not free
    138138
    139139        ip = alloc( 3 * dim, ip`realloc, fill`fill );           // CFA realloc array alloc, fill
    140         printf( "CFA realloc array alloc, fill\n" );
    141         for ( i; 3 * dim ) { printf( "%#x ", ip[i] ); }
    142         printf( "\n" );
     140        sout | "CFA realloc array alloc, fill";
     141        for ( i; 3 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     142        sout | nl;
    143143        // do not free
    144144
    145145        ip = alloc( dim, ip`realloc, fill`fill );                       // CFA realloc array alloc, fill
    146         printf( "CFA realloc array alloc, fill\n" );
    147         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    148         printf( "\n" );
     146        sout | "CFA realloc array alloc, fill";
     147        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     148        sout | nl;
    149149        // do not free
    150150
    151151        ip = alloc( 3 * dim, ip`realloc, fill`fill );           // CFA realloc array alloc, fill
    152         printf( "CFA realloc array alloc, fill\n" );
    153         for ( i; 3 * dim ) { printf( "%#x ", ip[i] ); }
    154         printf( "\n" );
    155         // do not free
    156 #if 0 // FIX ME
     152        sout | "CFA realloc array alloc, fill";
     153        for ( i; 3 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     154        sout | nl;
     155        // do not free
     156
    157157        ip = alloc( 5 * dim, ip`realloc, 5`fill );                      // CFA realloc array alloc, 5
    158         printf( "CFA realloc array alloc, 5\n" );
    159         for ( i; 5 * dim ) { printf( "%#x ", ip[i] ); }
    160         printf( "\n" );
     158        sout | "CFA realloc array alloc, 5";
     159        for ( i; 5 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     160        sout | nl;
    161161        // do not free
    162162
    163163        ip = alloc( dim, ip`realloc, 5`fill );                          // CFA realloc array alloc, 5
    164         printf( "CFA realloc array alloc, 5\n" );
    165         for ( i; dim ) { printf( "%#x ", ip[i] ); }
    166         printf( "\n" );
     164        sout | "CFA realloc array alloc, 5";
     165        for ( i; dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     166        sout | nl;
    167167        // do not free
    168168
    169169        ip = alloc( 5 * dim, ip`realloc, 5`fill );                      // CFA realloc array alloc, 5
    170         printf( "CFA realloc array alloc, 5\n" );
    171         for ( i; 5 * dim ) { printf( "%#x ", ip[i] ); }
    172         printf( "\n" );
    173 #endif // 0
     170        sout | "CFA realloc array alloc, 5";
     171        for ( i; 5 * dim ) { sout | hex(ip[i]) | ' ' | nonl; }
     172        sout | nl;
     173
    174174        free( ip );
    175175
     
    180180        };
    181181
    182     ip = alloc();
     182        ip = alloc();
    183183        *ip = 5;
    184     double * dp = alloc( ip`resize );
     184        double * dp = alloc( ip`resize );
    185185        *dp = 5.5;
    186     S * sp = alloc( dp`resize );
     186        S * sp = alloc( dp`resize );
    187187        *sp = (S){ {0, 1, 2, 3, 4} };
    188     ip = alloc( sp`resize );
     188        ip = alloc( sp`resize );
    189189        *ip = 3;
    190     free( ip );
     190        free( ip );
    191191
    192192
    193193        // resize, array types
    194194
    195     ip = alloc( 5 );
     195        ip = alloc( 5 );
    196196        for ( i; 5 ) { ip[i] = 5; }
    197     dp = alloc( 5, ip`resize );
     197        dp = alloc( 5, ip`resize );
    198198        for ( i; 5 ) { dp[i] = 5.5; }
    199     sp = alloc( 5, dp`resize );
     199        sp = alloc( 5, dp`resize );
    200200        for ( i; 5 ) { sp[i] = (S){ {0, 1, 2, 3, 4} }; }
    201     ip = alloc( 3, sp`resize );
     201        ip = alloc( 3, sp`resize );
    202202        for ( i; 3 ) { ip[i] = 3; }
    203     ip = alloc( 7, ip`realloc );
     203        ip = alloc( 7, ip`realloc );
    204204        for ( i; 7 ) { ip[i] = 7; }
    205     ip = alloc( 7, ip`resize );
     205        ip = alloc( 7, ip`resize );
    206206        for ( i; 7 ) { ip[i] = 7; }
    207     free( ip );
     207        free( ip );
    208208
    209209
     
    217217                const_count++;
    218218        }
    219         void ^?{}( Struct & a ) {  dest_count++; }                      // destruct
     219        void ^?{}( Struct & a ) { dest_count++; }                       // destruct
    220220        Struct st, st1, sta[dim], sta1[dim], * stp, * stp1;
    221221
    222222        // alignment, non-array types
    223         printf( "\n" );
     223        sout | nl;
    224224        enum { Alignment = 128 };
    225225
    226226        stp = &(*(Struct*)memalign( Alignment, sizeof( *stp ) ) ){ 42, 42.5 }; // C memalign
    227227        assert( (uintptr_t)stp % Alignment == 0 );
    228         printf( "C   memalign %d %g\n", stp->x, stp->y );
     228        sout | "C   memalign " | stp->x | stp->y;
    229229        free( stp );
    230230
    231231        stp = &(*memalign( Alignment )){ 42, 42.5 };            // CFA memalign
    232232        assert( (uintptr_t)stp % Alignment == 0 );
    233         printf( "CFA memalign %d %g\n", stp->x, stp->y );
     233        sout | "CFA memalign" | stp->x | stp->y;
    234234        free( stp );
    235235
     
    237237        *stp = (Struct){ 42, 42.5 };
    238238        assert( (uintptr_t)stp % Alignment == 0 );
    239         printf( "CFA posix_memalign %d %g\n", stp->x, stp->y );
     239        sout | "CFA posix_memalign" | stp->x | stp->y;
    240240        free( stp );
    241241
     
    243243        *stp = (Struct){ 42, 42.5 };
    244244        assert( (uintptr_t)stp % Alignment == 0 );
    245         printf( "CFA posix_memalign %d %g\n", stp->x, stp->y );
     245        sout | "CFA posix_memalign" | stp->x | stp->y;
    246246        free( stp );
    247247
    248248        stp = &(*alloc( Alignment`align)){ 42, 42.5 };          // CFA alloc_align
    249249        assert( (uintptr_t)stp % Alignment == 0 );
    250         printf( "CFA alloc_align %d %g\n", stp->x, stp->y );
     250        sout | "CFA alloc_align" | stp->x | stp->y;
    251251        free( stp );
    252252
    253253        stp = &(*alloc( Alignment`align )){ 42, 42.5 };         // CFA alloc_align
    254254        assert( (uintptr_t)stp % Alignment == 0 );
    255         printf( "CFA alloc_align %d %g\n", stp->x, stp->y );
     255        sout | "CFA alloc_align" | stp->x | stp->y;
    256256        free( stp );
    257257
    258258        stp = alloc( Alignment`align, fill`fill );                      // CFA memalign, fill
    259259        assert( (uintptr_t)stp % Alignment == 0 );
    260         printf( "CFA alloc_align fill %#x %a\n", stp->x, stp->y );
     260        sout | "CFA alloc_align fill" | hex(stp->x) | hex(stp->y);
    261261        free( stp );
    262262
    263263        stp = alloc( Alignment`align, (Struct){ 42, 42.5 }`fill ); // CFA memalign, fill
    264264        assert( (uintptr_t)stp % Alignment == 0 );
    265         printf( "CFA alloc_align fill %d %g\n", stp->x, stp->y );
     265        sout | "CFA alloc_align fill" | stp->x | stp->y;
    266266        // do not free
    267267
    268268        stp = &(*alloc( stp`realloc, 4096`align )){ 42, 42.5 }; // CFA realign
    269269        assert( (uintptr_t)stp % 4096 == 0 );
    270         printf( "CFA alloc_align %d %g\n", stp->x, stp->y );
     270        sout | "CFA alloc_align" | stp->x | stp->y;
    271271        free( stp );
    272272
    273273
    274274        // alignment, array types
    275         printf( "\n" );
     275        sout | nl;
    276276
    277277        stp = alloc( dim, Alignment`align );                // CFA array memalign
    278278        assert( (uintptr_t)stp % Alignment == 0 );
    279279        for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; }
    280         printf( "CFA array alloc_align\n" );
    281         for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    282         printf( "\n" );
     280        sout | "CFA array alloc_align";
     281        for ( i; dim ) { sout | stp[i].x | stp[i].y | ", " | nonl; }
     282        sout | nl;
    283283        free( stp );
    284284
    285285        stp = alloc( dim, Alignment`align, fill`fill );         // CFA array memalign, fill
    286286        assert( (uintptr_t)stp % Alignment == 0 );
    287         printf( "CFA array alloc_align, fill\n" );
    288         for ( i; dim ) { printf( "%#x %a, ", stp[i].x, stp[i].y ); }
    289         printf( "\n" );
     287        sout | "CFA array alloc_align, fill";
     288        for ( i; dim ) { sout | hex(stp[i].x) | hex(stp[i].y) | ", " | nonl; }
     289        sout | nl;
    290290        free( stp );
    291291
    292292        stp = alloc( dim, Alignment`align, ((Struct){ 42, 42.5 })`fill ); // CFA array memalign, fill
    293293        assert( (uintptr_t)stp % Alignment == 0 );
    294         printf( "CFA array alloc_align, fill\n" );
    295         for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    296         printf( "\n" );
     294        sout | "CFA array alloc_align, fill";
     295        for ( i; dim ) { sout | stp[i].x | stp[i].y | ", " | nonl; }
     296        sout | nl;
    297297        // do not free
    298298
    299299        stp1 = alloc( dim, Alignment`align, [stp, dim]`fill );  // CFA array memalign, fill
    300300        assert( (uintptr_t)stp % Alignment == 0 );
    301         printf( "CFA array alloc_align, fill array\n" );
    302         for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); }
    303         printf( "\n" );
     301        sout | "CFA array alloc_align, fill array";
     302        for ( i; dim ) { sout | stp1[i].x | stp1[i].y | ", " | nonl; }
     303        sout | nl;
    304304        free( stp1 );
    305305
     
    307307        assert( (uintptr_t)stp % 4096 == 0 );
    308308        for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; }
    309         printf( "CFA realloc array alloc_align\n" );
    310         for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    311         printf( "\n" );
     309        sout | "CFA realloc array alloc_align";
     310        for ( i; dim ) { sout | stp[i].x | stp[i].y | ", " | nonl; }
     311        sout | nl;
    312312        free( stp );
    313313
    314314
    315315        // data, non-array types
    316         printf( "\n" );
     316        sout | nl;
    317317
    318318        memset( &st, fill );                                // CFA memset, type safe
    319         printf( "CFA memset %#x %a\n", st.x, st.y );
     319        sout | "CFA memset" | hex(st.x) | hex(st.y);
    320320        memcpy( &st1, &st );                                // CFA memcpy, type safe
    321         printf( "CFA memcpy %#x %a\n", st1.x, st1.y );
     321        sout | "CFA memcpy" | hex(st1.x) | hex(st1.y);
    322322
    323323
    324324        // data, array types
    325         printf( "\n" );
     325        sout | nl;
    326326
    327327        amemset( sta, fill, dim );                                                      // CFA array memset, type safe
    328         printf( "CFA array memset\n" );
    329         for ( i; dim ) { printf( "%#x %a, ", sta[i].x, sta[i].y ); }
    330         printf( "\n" );
     328        sout | "CFA array memset";
     329        for ( i; dim ) { sout | hex(sta[i].x) | hex(sta[i].y) | ", " | nonl; }
     330        sout | nl;
    331331
    332332        amemcpy( sta1, sta, dim );                                                      // CFA array memcpy, type safe
    333         printf( "CFA array memcpy\n" );
    334         for ( i; dim ) { printf( "%#x %a, ", sta1[i].x, sta1[i].y ); }
    335         printf( "\n" );
     333        sout | "CFA array memcpy";
     334        for ( i; dim ) { sout | hex(sta1[i].x) | hex(sta1[i].y) | ", " | nonl; }
     335        sout | nl;
    336336
    337337        // new, non-array types
    338         printf( "\n" );
     338        sout | nl;
    339339
    340340        const_count = dest_count = 0;
     
    344344        assert( const_count == 2 && dest_count == 0 );          // assertion for testing
    345345
    346         printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y );
     346        sout | "CFA new initialize" | nl | stp->x | stp->y | stp1->x | stp1->y;
    347347        delete( stp, stp1 );
    348348        assert( const_count == 2 && dest_count == 2 );          // assertion for testing
     
    351351        stp = anew( dim, 42, 42.5 );
    352352        assert( const_count == 2 + dim && dest_count == 2 ); // assertion for testing
    353         printf( "CFA array new initialize\n" );
    354         for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    355         printf( "\n" );
     353        sout | "CFA array new initialize";
     354        for ( i; dim ) { sout | stp[i].x | stp[i].y | ", " | nonl; }
     355        sout | nl;
    356356
    357357        stp1 = anew( dim, 42, 42.5 );
    358358        assert( const_count == 2 + 2 * dim && dest_count == 2 ); // assertion for testing
    359         for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); }
    360         printf( "\n" );
     359        for ( i; dim ) { sout | stp1[i].x | stp1[i].y | ", " | nonl; }
     360        sout | nl;
    361361        adelete( stp, stp1 );
    362362        assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); // assertion for testing
    363363
    364364        // extras
    365         printf( "\n" );
     365        sout | nl;
    366366
    367367        float * fp = malloc() + 1;
    368         printf( "pointer arithmetic %d\n", fp == fp - 1 );
     368        sout | "pointer arithmetic" | fp == fp - 1;
    369369        free( fp - 1 );
    370370
    371371        ip = foo( bar( baz( malloc(), 0 ), 0 ), 0 );
    372372        *ip = 0xdeadbeef;
    373         printf( "CFA deep malloc %#x\n", *ip );
     373        sout | "CFA deep malloc" | hex(*ip);
    374374
    375375        dp = alloc(5.0`fill);                                                           // just for testing multiple free
     
    379379#ifdef ERR1
    380380        stp = malloc();
    381         printf( "\nSHOULD FAIL\n" );
     381        sout | "\nSHOULD FAIL";
    382382        ip = realloc( stp, dim * sizeof( *stp ) );
    383383        ip = memset( stp, 10 );
  • tests/alloc2.cfa

    r9cd5bd2 rdf6cc9d  
     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 );
  • tests/device/cpu.cfa

    r9cd5bd2 rdf6cc9d  
    117117unsigned find_idx() {
    118118        int idxs = count_cache_indexes();
     119        if( 0 == idxs ) return 0;
    119120
    120121        unsigned found_level = 0;
     
    179180        unsigned idx = find_idx();
    180181        // For all procs check mapping is consistent
    181         for(cpu_me; cpu_info.hthrd_count) {
     182        if( idx > 0 ) for(cpu_me; cpu_info.hthrd_count) {
    182183                char buf_me[32];
    183184                size_t len_me = read_cpuidxinfo_into(cpu_me, idx, "shared_cpu_list", buf_me, 32);
  • tests/malloc.cfa

    r9cd5bd2 rdf6cc9d  
    1 #include <assert.h>
     1#include <fstream.hfa>                                                                  // sout
    22#include <malloc.h>                                                                             // malloc_usable_size
    33#include <stdint.h>                                                                             // uintptr_t
    4 #include <stdlib.h>                                                                             // posix_memalign
    5 #include <fstream.hfa>
    64#include <stdlib.hfa>                                                                   // access C malloc, realloc
    75#include <unistd.h>                                                                             // getpagesize
     
    108int tests_failed;
    119size_t tAlign = 32;
    12 struct S1 { int d1; } __attribute__((aligned(32)));
     10struct S1 { int data; } __attribute__(( aligned(32)));
    1311typedef struct S1 T1;
    1412
    15 void test_base( void * ip, size_t size, size_t align) {
     13void test_base( void * ip, size_t size, size_t align ) {
    1614        tests_total += 1;
    17         bool passed = (malloc_size(ip) == size) && (malloc_usable_size(ip) >= size) && (malloc_alignment(ip) == align) && ((uintptr_t)ip % align  == 0);
    18         if (!passed) {
    19                 printf("failed test %2d: %4lu %4lu but got %4lu ( %3lu ) %4lu\n", tests_total, size, align, malloc_size(ip), malloc_usable_size(ip), malloc_alignment(ip));
     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                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                tests_failed += 1;
     19        } // if
     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                sout | "fill1 failed test" | tests_total | "fill C";
     29                tests_failed += 1;
     30        } // if
     31}
     32
     33void test_use( void * ip_ ) {
     34        tests_total += 1;
     35        bool passed = true;
     36        int * ip = (int *) ip_;
     37        size_t size = malloc_size( ip );
     38        for ( i; 0 ~ size ~ sizeof(int)) ip[i/sizeof(int)] = 0xdeadbeef;
     39        for ( i; 0 ~ size ~ sizeof(int)) passed = passed && (ip[i / sizeof(int)] == 0xdeadbeef);
     40        size_t usize = malloc_usable_size( ip );
     41        for ( i; size ~ usize ~ sizeof(int)) ip[i / sizeof(int)] = -1;
     42        for ( i; size ~ usize ~ sizeof(int)) passed = passed &&  (ip[i / sizeof(int)] == -1);
     43        if ( ! passed ) {
     44                sout | "failed test" | tests_total | "use";
    2045                tests_failed += 1;
    2146        }
    2247}
    2348
    24 void test_fill( void * ip_, size_t start, size_t end, char fill) {
    25         tests_total += 1;
    26         bool passed = true;
    27         char * ip = (char *) ip_;
    28         for (i; start ~ end) passed = passed && (ip[i] == fill);
    29         if (!passed) {
    30                 printf("failed test %2d: fill\n", tests_total);
    31                 tests_failed += 1;
    32         }
    33 }
    34 
    35 void test_use( void * ip_) {
    36         tests_total += 1;
    37         bool passed = true;
    38         int * ip = (int *) ip_;
    39         size_t size = malloc_size(ip);
    40         for (i; 0 ~ size ~ sizeof(int)) ip[i/sizeof(int)] = 0xdeadbeef;
    41         for (i; 0 ~ size ~ sizeof(int)) passed = passed &&  (ip[i/sizeof(int)] == 0xdeadbeef);
    42         size_t usize = malloc_usable_size(ip);
    43         for (i; size ~ usize ~ sizeof(int)) ip[i/sizeof(int)] = -1;
    44         for (i; size ~ usize ~ sizeof(int)) passed = passed &&  (ip[i/sizeof(int)] == -1);
    45         if (!passed) {
    46                 printf("failed test %2d: use\n", tests_total);
    47                 tests_failed += 1;
    48         }
    49 }
    50 
    5149int main( void ) {
     50        enum { dim = 8, align = 64, libAlign = libAlign() };
    5251        size_t elemSize = sizeof(int);
    53         size_t dim = 8;
    5452        size_t size = dim * elemSize;
    55         size_t align = 64;
    56         const size_t libAlign = libAlign();
    5753        char fill = '\xde';
    5854        int * ip;
    5955        T1 * tp;
    6056
    61         // testing C   malloc
     57        // testing C malloc
    6258
    6359        tests_total = 0;
    6460        tests_failed = 0;
    6561
    66         ip = (int *) (void *) malloc( size );
    67         test_base(ip, size, libAlign);
    68         test_use(ip);
    69         free(ip);
    70 
    71         ip = (int *) (void *) malloc( 0 );
    72         test_base(ip, 0, libAlign);
    73         test_use(ip);
    74         free(ip);
    75 
    76         ip = (int *) (void *) aalloc( dim, elemSize );
    77         test_base(ip, size, libAlign);
    78         test_use(ip);
    79         free(ip);
    80 
    81         ip = (int *) (void *) aalloc( 0, elemSize );
    82         test_base(ip, 0, libAlign);
    83         test_use(ip);
    84         free(ip);
    85 
    86         ip = (int *) (void *) aalloc( dim, 0 );
    87         test_base(ip, 0, libAlign);
    88         test_use(ip);
    89         free(ip);
    90 
    91         ip = (int *) (void *) aalloc( 0, 0 );
    92         test_base(ip, 0, libAlign);
    93         test_use(ip);
    94         free(ip);
    95 
    96         ip = (int *) (void *) calloc( dim, elemSize );
    97         test_base(ip, size, libAlign);
    98         test_fill(ip, 0, size, '\0');
    99         test_use(ip);
    100         free(ip);
    101 
    102         ip = (int *) (void *) calloc( 0, elemSize );
    103         test_base(ip, 0, libAlign);
    104         test_fill(ip, 0, 0, '\0');
    105         test_use(ip);
    106         free(ip);
    107 
    108         ip = (int *) (void *) calloc( dim, 0 );
    109         test_base(ip, 0, libAlign);
    110         test_fill(ip, 0, 0, '\0');
    111         test_use(ip);
    112         free(ip);
    113 
    114         ip = (int *) (void *) malloc( size );
    115         ip = (int *) (void *) resize( (void *) ip, size / 4 );
    116         test_base(ip, size / 4, libAlign);
    117         test_use(ip);
    118         free(ip);
    119 
    120         ip = (int *) (void *) malloc( size );
    121         ip = (int *) (void *) resize( (void *) ip, size * 4 );
    122         test_base(ip, size * 4, libAlign);
    123         test_use(ip);
    124         free(ip);
    125 
    126         ip = (int *) (void *) malloc( size );
    127         ip = (int *) (void *) resize( (void *) ip, 0 );
    128         test_base(ip, 0, libAlign);
    129         test_use(ip);
    130         free(ip);
    131 
    132         ip = (int *) (void *) resize( NULL, size );
    133         test_base(ip, size, libAlign);
    134         test_use(ip);
    135         free(ip);
    136 
    137         ip = (int *) (void *) resize( 0p, size );
    138         test_base(ip, size, libAlign);
    139         test_use(ip);
    140         free(ip);
    141 
    142         ip = (int *) (void *) calloc( dim, elemSize );
    143         ip = (int *) (void *) realloc( (void *) ip, size / 4 );
    144         test_base(ip, size / 4, libAlign);
    145         test_fill(ip, 0, size / 4, '\0');
    146         test_use(ip);
    147         free(ip);
    148 
    149         ip = (int *) (void *) calloc( dim, elemSize );
    150         ip = (int *) (void *) realloc( (void *) ip, size * 4 );
    151         test_base(ip, size * 4, libAlign);
    152         test_fill(ip, 0, size * 4, '\0');
    153         test_use(ip);
    154         free(ip);
    155 
    156         ip = (int *) (void *) calloc( dim, elemSize );
    157         ip = (int *) (void *) realloc( (void *) ip, 0 );
    158         test_base(ip, 0, libAlign);
    159         test_use(ip);
    160         free(ip);
    161 
    162         ip = (int *) (void *) realloc( NULL, size  );
    163         test_base(ip, size , libAlign);
    164         test_use(ip);
    165         free(ip);
    166 
    167         ip = (int *) (void *) realloc( 0p, size );
    168         test_base(ip, size, libAlign);
    169         test_use(ip);
    170         free(ip);
    171 
    172         ip = (int *) (void *) memalign( align, size );
    173         test_base(ip, size, align);
    174         test_use(ip);
    175         free(ip);
    176 
    177         ip = (int *) (void *) memalign( align, 0 );
    178         test_base(ip, 0, libAlign);
    179         test_use(ip);
    180         free(ip);
    181 
    182         ip = (int *) (void *) amemalign( align, dim, elemSize );
    183         test_base(ip, size, align);
    184         test_use(ip);
    185         free(ip);
    186 
    187         ip = (int *) (void *) amemalign( align, 0, elemSize );
    188         test_base(ip, 0, libAlign);
    189         test_use(ip);
    190         free(ip);
    191 
    192         ip = (int *) (void *) amemalign( align, dim, 0 );
    193         test_base(ip, 0, libAlign);
    194         test_use(ip);
    195         free(ip);
    196 
    197         ip = (int *) (void *) cmemalign( align, dim, elemSize );
    198         test_base(ip, size, align);
    199         test_fill(ip, 0, size, '\0');
    200         test_use(ip);
    201         free(ip);
    202 
    203         ip = (int *) (void *) cmemalign( align, 0, elemSize );
    204         test_base(ip, 0, libAlign);
    205         test_use(ip);
    206         free(ip);
    207 
    208         ip = (int *) (void *) cmemalign( align, dim, 0 );
    209         test_base(ip, 0, libAlign);
    210         test_use(ip);
    211         free(ip);
    212 
    213         ip = (int *) (void *) aligned_alloc( align, size );
    214         test_base(ip, size, align);
    215         test_use(ip);
    216         free(ip);
    217 
    218         ip = (int *) (void *) aligned_alloc( align, 0 );
    219         test_base(ip, 0, libAlign);
    220         test_use(ip);
    221         free(ip);
    222 
    223         (int) posix_memalign( (void **) &ip, align, size );
    224         test_base(ip, size, align);
    225         test_use(ip);
    226         free(ip);
    227 
    228         (int) posix_memalign( (void **) &ip, align, 0 );
    229         test_base(ip, 0, libAlign);
    230         test_use(ip);
    231         free(ip);
    232 
    233         ip = (int *) (void *) valloc( size );
    234         test_base(ip, size, getpagesize());
    235         test_use(ip);
    236         free(ip);
    237 
    238         ip = (int *) (void *) valloc( 0 );
    239         test_base(ip, 0, libAlign);
    240         test_use(ip);
    241         free(ip);
    242 
    243         ip = (int *) (void *) pvalloc( getpagesize() * 3 / 2 );
    244         test_base(ip, getpagesize() * 2, getpagesize());
    245         test_use(ip);
    246         free(ip);
    247 
    248         ip = (int *) (void *) pvalloc( 0 );
    249         test_base(ip, 0, libAlign);
    250         test_use(ip);
    251         free(ip);
    252 
    253         ip = (int *) (void *) malloc( size );
    254         ip = (int *) (void *) resize( (void *) ip, libAlign, size / 2 );
    255         test_base(ip, size / 2, libAlign);
    256         test_use(ip);
    257         free(ip);
    258 
    259         ip = (int *) (void *) aligned_alloc( align, size );
    260         ip = (int *) (void *) resize( (void *) ip, align, size / 2 );
    261         test_base(ip, size / 2, align);
    262         test_use(ip);
    263         free(ip);
    264 
    265         ip = (int *) (void *) malloc( size );
    266         ip = (int *) (void *) resize( (void *) ip, align, size / 4 );
    267         test_base(ip, size / 4, align);
    268         test_use(ip);
    269         free(ip);
    270 
    271         ip = (int *) (void *) malloc( size );
    272         ip = (int *) (void *) resize( (void *) ip, align, 0 );
    273         test_base(ip, 0, libAlign);
    274         test_use(ip);
    275         free(ip);
    276 
    277         ip = (int *) (void *) resize( NULL, align, size );
    278         test_base(ip, size, align);
    279         test_use(ip);
    280         free(ip);
    281 
    282         ip = (int *) (void *) resize( 0p, align, size );
    283         test_base(ip, size, align);
    284         test_use(ip);
    285         free(ip);
    286 
    287         ip = (int *) (void *) calloc( dim, elemSize );
    288         ip = (int *) (void *) realloc( (void *) ip, libAlign, size / 2 );
    289         test_base(ip, size / 2, libAlign);
    290         test_fill(ip, 0, size / 2, '\0');
    291         test_use(ip);
    292         free(ip);
    293 
    294         ip = (int *) (void *) cmemalign( align, dim, elemSize );
    295         ip = (int *) (void *) realloc( (void *) ip, align, size / 2 );
    296         test_base(ip, size / 2, align);
    297         test_fill(ip, 0, size / 2, '\0');
    298         test_use(ip);
    299         free(ip);
    300 
    301         ip = (int *) (void *) calloc( dim, elemSize );
    302         ip = (int *) (void *) realloc( (void *) ip, align, size / 4 );
    303         test_base(ip, size / 4, align);
    304         test_fill(ip, 0, size / 4, '\0');
    305         test_use(ip);
    306         free(ip);
    307 
    308         ip = (int *) (void *) calloc( dim, elemSize );
    309         ip = (int *) (void *) realloc( (void *) ip, 0, size * 4 );
    310         test_base(ip, size * 4, libAlign);
    311         test_fill(ip, 0, size * 4, '\0');
    312         test_use(ip);
    313         free(ip);
    314 
    315         ip = (int *) (void *) calloc( dim, elemSize );
    316         ip = (int *) (void *) realloc( (void *) ip, align, 0 );
    317         test_base(ip, 0, libAlign);
    318         test_use(ip);
    319         free(ip);
    320 
    321         free( 0p ); // sanity check
    322         free( NULL ); // sanity check
    323 
    324         if (tests_failed == 0) printf("PASSED C malloc tests\n\n");
    325         else printf("failed C malloc tests : %d/%d\n\n", tests_failed, tests_total);
     62        ip = (int *)malloc( size );
     63        test_base( ip, size, libAlign );
     64        test_use( ip );
     65        free( ip );
     66
     67        ip = (int *)malloc( 0 );
     68        test_base( ip, 0, libAlign );
     69        test_use( ip );
     70        free( ip );
     71
     72        ip = (int *)aalloc( dim, elemSize );
     73        test_base( ip, size, libAlign );
     74        test_use( ip );
     75        free( ip );
     76
     77        ip = (int *)aalloc( 0, elemSize );
     78        test_base( ip, 0, libAlign );
     79        test_use( ip );
     80        free( ip );
     81
     82        ip = (int *)aalloc( dim, 0 );
     83        test_base( ip, 0, libAlign );
     84        test_use( ip );
     85        free( ip );
     86
     87        ip = (int *)aalloc( 0, 0 );
     88        test_base( ip, 0, libAlign );
     89        test_use( ip );
     90        free( ip );
     91
     92        ip = (int *)calloc( dim, elemSize );
     93        test_base( ip, size, libAlign );
     94        test_fill( ip, 0, size, '\0' );
     95        test_use( ip );
     96        free( ip );
     97
     98        ip = (int *)calloc( 0, elemSize );
     99        test_base( ip, 0, libAlign );
     100        test_fill( ip, 0, 0, '\0' );
     101        test_use( ip );
     102        free( ip );
     103
     104        ip = (int *)calloc( dim, 0 );
     105        test_base( ip, 0, libAlign );
     106        test_fill( ip, 0, 0, '\0' );
     107        test_use( ip );
     108        free( ip );
     109
     110        ip = (int *)malloc( size );
     111        ip = (int *)resize( ip, size / 4 );
     112        test_base( ip, size / 4, libAlign );
     113        test_use( ip );
     114        free( ip );
     115
     116        ip = (int *)malloc( size );
     117        ip = (int *)resize( ip, size * 4 );
     118        test_base( ip, size * 4, libAlign );
     119        test_use( ip );
     120        free( ip );
     121
     122        ip = (int *)malloc( size );
     123        ip = (int *)resize( ip, 0 );
     124        test_base( ip, 0, libAlign );
     125        test_use( ip );
     126        free( ip );
     127
     128        ip = (int *)resize( NULL, size );
     129        test_base( ip, size, libAlign );
     130        test_use( ip );
     131        free( ip );
     132
     133        ip = (int *)resize( 0p, size );
     134        test_base( ip, size, libAlign );
     135        test_use( ip );
     136        free( ip );
     137
     138        ip = (int *)calloc( dim, elemSize );
     139        ip = (int *)realloc( ip, size / 4 );
     140        test_base( ip, size / 4, libAlign );
     141        test_fill( ip, 0, size / 4, '\0' );
     142        test_use( ip );
     143        free( ip );
     144
     145        ip = (int *)calloc( dim, elemSize );
     146        ip = (int *)realloc( ip, size * 4 );
     147        test_base( ip, size * 4, libAlign );
     148        test_fill( ip, 0, size * 4, '\0' );
     149        test_use( ip );
     150        free( ip );
     151
     152        ip = (int *)calloc( dim, elemSize );
     153        ip = (int *)realloc( ip, 0 );
     154        test_base( ip, 0, libAlign );
     155        test_use( ip );
     156        free( ip );
     157
     158        ip = (int *)realloc( NULL, size  );
     159        test_base( ip, size , libAlign );
     160        test_use( ip );
     161        free( ip );
     162
     163        ip = (int *)realloc( 0p, size );
     164        test_base( ip, size, libAlign );
     165        test_use( ip );
     166        free( ip );
     167
     168        ip = (int *)memalign( align, size );
     169        test_base( ip, size, align );
     170        test_use( ip );
     171        free( ip );
     172
     173        ip = (int *)memalign( align, 0 );
     174        test_base( ip, 0, libAlign );
     175        test_use( ip );
     176        free( ip );
     177
     178        ip = (int *)amemalign( align, dim, elemSize );
     179        test_base( ip, size, align );
     180        test_use( ip );
     181        free( ip );
     182
     183        ip = (int *)amemalign( align, 0, elemSize );
     184        test_base( ip, 0, libAlign );
     185        test_use( ip );
     186        free( ip );
     187
     188        ip = (int *)amemalign( align, dim, 0 );
     189        test_base( ip, 0, libAlign );
     190        test_use( ip );
     191        free( ip );
     192
     193        ip = (int *)cmemalign( align, dim, elemSize );
     194        test_base( ip, size, align );
     195        test_fill( ip, 0, size, '\0' );
     196        test_use( ip );
     197        free( ip );
     198
     199        ip = (int *)cmemalign( align, 0, elemSize );
     200        test_base( ip, 0, libAlign );
     201        test_use( ip );
     202        free( ip );
     203
     204        ip = (int *)cmemalign( align, dim, 0 );
     205        test_base( ip, 0, libAlign );
     206        test_use( ip );
     207        free( ip );
     208
     209        ip = (int *)aligned_alloc( align, size );
     210        test_base( ip, size, align );
     211        test_use( ip );
     212        free( ip );
     213
     214        ip = (int *)aligned_alloc( align, 0 );
     215        test_base( ip, 0, libAlign );
     216        test_use( ip );
     217        free( ip );
     218
     219        posix_memalign( (void **) &ip, align, size );
     220        test_base( ip, size, align );
     221        test_use( ip );
     222        free( ip );
     223
     224        posix_memalign( (void **) &ip, align, 0 );
     225        test_base( ip, 0, libAlign );
     226        test_use( ip );
     227        free( ip );
     228
     229        ip = (int *)valloc( size );
     230        test_base( ip, size, getpagesize() );
     231        test_use( ip );
     232        free( ip );
     233
     234        ip = (int *)valloc( 0 );
     235        test_base( ip, 0, libAlign );
     236        test_use( ip );
     237        free( ip );
     238
     239        ip = (int *)pvalloc( getpagesize() * 3 / 2 );
     240        test_base( ip, getpagesize() * 2, getpagesize() );
     241        test_use( ip );
     242        free( ip );
     243
     244        ip = (int *)pvalloc( 0 );
     245        test_base( ip, 0, libAlign );
     246        test_use( ip );
     247        free( ip );
     248
     249        ip = (int *)malloc( size );
     250        ip = (int *)resize( ip, libAlign, size / 2 );
     251        test_base( ip, size / 2, libAlign );
     252        test_use( ip );
     253        free( ip );
     254
     255        ip = (int *)aligned_alloc( align, size );
     256        ip = (int *)resize( ip, align, size / 2 );
     257        test_base( ip, size / 2, align );
     258        test_use( ip );
     259        free( ip );
     260
     261        ip = (int *)malloc( size );
     262        ip = (int *)resize( ip, align, size / 4 );
     263        test_base( ip, size / 4, align );
     264        test_use( ip );
     265        free( ip );
     266
     267        ip = (int *)malloc( size );
     268        ip = (int *)resize( ip, align, 0 );
     269        test_base( ip, 0, libAlign );
     270        test_use( ip );
     271        free( ip );
     272
     273        ip = (int *)resize( NULL, align, size );
     274        test_base( ip, size, align );
     275        test_use( ip );
     276        free( ip );
     277
     278        ip = (int *)resize( 0p, align, size );
     279        test_base( ip, size, align );
     280        test_use( ip );
     281        free( ip );
     282
     283        ip = (int *)calloc( dim, elemSize );
     284        ip = (int *)realloc( ip, libAlign, size / 2 );
     285        test_base( ip, size / 2, libAlign );
     286        test_fill( ip, 0, size / 2, '\0' );
     287        test_use( ip );
     288        free( ip );
     289
     290        ip = (int *)cmemalign( align, dim, elemSize );
     291        ip = (int *)realloc( ip, align, size / 2 );
     292        test_base( ip, size / 2, align );
     293        test_fill( ip, 0, size / 2, '\0' );
     294        test_use( ip );
     295        free( ip );
     296
     297        ip = (int *)calloc( dim, elemSize );
     298        ip = (int *)realloc( ip, align, size / 4 );
     299        test_base( ip, size / 4, align );
     300        test_fill( ip, 0, size / 4, '\0' );
     301        test_use( ip );
     302        free( ip );
     303
     304        ip = (int *)calloc( dim, elemSize );
     305        ip = (int *)realloc( ip, libAlign, size * 4 );
     306        test_base( ip, size * 4, libAlign );
     307        test_fill( ip, 0, size * 4, '\0' );
     308        test_use( ip );
     309        free( ip );
     310
     311        ip = (int *)calloc( dim, elemSize );
     312        ip = (int *)realloc( ip, align, 0 );
     313        test_base( ip, 0, libAlign );
     314        test_use( ip );
     315        free( ip );
     316
     317        free( 0p );                                                                                     // sanity check
     318        free( NULL );                                                                           // sanity check
     319
     320        if (tests_failed == 0) sout | "PASSED C malloc tests" | nl | nl;
     321        else sout | "failed C malloc tests" | tests_failed | tests_total | nl | nl;
    326322
    327323        // testing CFA malloc
     
    331327
    332328        ip = malloc();
    333         test_base(ip, elemSize, libAlign);
    334         test_use(ip);
    335         free(ip);
     329        test_base( ip, elemSize, libAlign );
     330        test_use( ip );
     331        free( ip );
    336332
    337333        ip = aalloc( dim );
    338         test_base(ip, size, libAlign);
    339         test_use(ip);
    340         free(ip);
     334        test_base( ip, size, libAlign );
     335        test_use( ip );
     336        free( ip );
    341337
    342338        ip = aalloc( 0 );
    343         test_base(ip, 0, libAlign);
    344         test_use(ip);
    345         free(ip);
     339        test_base( ip, 0, libAlign );
     340        test_use( ip );
     341        free( ip );
    346342
    347343        ip = calloc( dim );
    348         test_base(ip, size, libAlign);
    349         test_fill(ip, 0, size, '\0');
    350         test_use(ip);
    351         free(ip);
     344        test_base( ip, size, libAlign );
     345        test_fill( ip, 0, size, '\0' );
     346        test_use( ip );
     347        free( ip );
    352348
    353349        ip = calloc( 0 );
    354         test_base(ip, 0, libAlign);
    355         test_use(ip);
    356         free(ip);
     350        test_base( ip, 0, libAlign );
     351        test_use( ip );
     352        free( ip );
    357353
    358354        ip = aalloc( dim );
    359355        ip = resize( ip, size / 4 );
    360         test_base(ip, size / 4, libAlign);
    361         test_use(ip);
    362         free(ip);
     356        test_base( ip, size / 4, libAlign );
     357        test_use( ip );
     358        free( ip );
    363359
    364360        ip = aalloc( dim );
    365361        ip = resize( ip, size * 4 );
    366         test_base(ip, size * 4, libAlign);
    367         test_use(ip);
    368         free(ip);
     362        test_base( ip, size * 4, libAlign );
     363        test_use( ip );
     364        free( ip );
    369365
    370366        ip = aalloc( dim );
    371367        ip = resize( ip, 0 );
    372         test_base(ip, 0, libAlign);
    373         test_use(ip);
    374         free(ip);
    375 
    376         ip = resize( (int*)0p, size );
    377         test_base(ip, size, libAlign);
    378         test_use(ip);
    379         free(ip);
    380 
    381         ip = resize( (int*)0p, size );
    382         test_base(ip, size, libAlign);
    383         test_use(ip);
    384         free(ip);
     368        test_base( ip, 0, libAlign );
     369        test_use( ip );
     370        free( ip );
     371
     372        ip = resize( 0p, size );
     373        test_base( ip, size, libAlign );
     374        test_use( ip );
     375        free( ip );
     376
     377        ip = resize( 0p, size );
     378        test_base( ip, size, libAlign );
     379        test_use( ip );
     380        free( ip );
    385381
    386382        ip = calloc( dim );
    387383        ip = realloc( ip, size / 4 );
    388         test_base(ip, size / 4, libAlign);
    389         test_fill(ip, 0, size / 4, '\0');
    390         test_use(ip);
    391         free(ip);
     384        test_base( ip, size / 4, libAlign );
     385        test_fill( ip, 0, size / 4, '\0' );
     386        test_use( ip );
     387        free( ip );
    392388
    393389        ip = calloc( dim );
    394390        ip = realloc( ip, size * 4 );
    395         test_base(ip, size * 4, libAlign);
    396         test_fill(ip, 0, size, '\0');
    397         test_use(ip);
    398         free(ip);
     391        test_base( ip, size * 4, libAlign );
     392        test_fill( ip, 0, size, '\0' );
     393        test_use( ip );
     394        free( ip );
    399395
    400396        ip = calloc( dim );
    401397        ip = realloc( ip, 0 );
    402         test_base(ip, 0, libAlign);
    403         test_use(ip);
    404         free(ip);
    405 
    406         ip = realloc( (int*)0p, size );
    407         test_base(ip, size , libAlign);
    408         test_use(ip);
    409         free(ip);
    410 
    411         ip = realloc( (int*)0p, size );
    412         test_base(ip, size, libAlign);
    413         test_use(ip);
    414         free(ip);
     398        test_base( ip, 0, libAlign );
     399        test_use( ip );
     400        free( ip );
     401
     402        ip = realloc( 0p, size );
     403        test_base( ip, size , libAlign );
     404        test_use( ip );
     405        free( ip );
     406
     407        ip = realloc( 0p, size );
     408        test_base( ip, size, libAlign );
     409        test_use( ip );
     410        free( ip );
    415411
    416412        ip = memalign( align );
    417         test_base(ip, elemSize, align);
    418         test_use(ip);
    419         free(ip);
     413        test_base( ip, elemSize, align );
     414        test_use( ip );
     415        free( ip );
    420416
    421417        ip = amemalign( align, dim );
    422         test_base(ip, size, align);
    423         test_use(ip);
    424         free(ip);
     418        test_base( ip, size, align );
     419        test_use( ip );
     420        free( ip );
    425421
    426422        ip = amemalign( align, 0 );
    427         test_base(ip, 0, libAlign);
    428         test_use(ip);
    429         free(ip);
     423        test_base( ip, 0, libAlign );
     424        test_use( ip );
     425        free( ip );
    430426
    431427        ip = cmemalign( align, dim );
    432         test_base(ip, size, align);
    433         test_fill(ip, 0, size, '\0');
    434         test_use(ip);
    435         free(ip);
     428        test_base( ip, size, align );
     429        test_fill( ip, 0, size, '\0' );
     430        test_use( ip );
     431        free( ip );
    436432
    437433        ip = cmemalign( align, 0 );
    438         test_base(ip, 0, libAlign);
    439         test_use(ip);
    440         free(ip);
     434        test_base( ip, 0, libAlign );
     435        test_use( ip );
     436        free( ip );
    441437
    442438        ip = aligned_alloc( align );
    443         test_base(ip, elemSize, align);
    444         test_use(ip);
    445         free(ip);
    446 
    447         (int) posix_memalign( (int **) &ip, align );
    448         test_base(ip, elemSize, align);
    449         test_use(ip);
    450         free(ip);
     439        test_base( ip, elemSize, align );
     440        test_use( ip );
     441        free( ip );
     442
     443        posix_memalign( (int **) &ip, align );
     444        test_base( ip, elemSize, align );
     445        test_use( ip );
     446        free( ip );
    451447
    452448        ip = valloc();
    453         test_base(ip, elemSize, getpagesize());
    454         test_use(ip);
    455         free(ip);
     449        test_base( ip, elemSize, getpagesize() );
     450        test_use( ip );
     451        free( ip );
    456452
    457453        ip = pvalloc();
    458         test_base(ip, getpagesize(), getpagesize());
    459         test_use(ip);
    460         free(ip);
    461 
    462         if (tests_failed == 0) printf("PASSED CFA malloc tests\n\n");
    463         else printf("failed CFA malloc tests : %d/%d\n\n", tests_failed, tests_total);
     454        test_base( ip, getpagesize(), getpagesize() );
     455        test_use( ip );
     456        free( ip );
     457
     458        if (tests_failed == 0) sout | "PASSED CFA malloc tests" | nl | nl;
     459        else sout | "failed CFA malloc tests" | tests_failed | tests_total | nl | nl;
    464460
    465461        // testing CFA malloc with aligned struct
     
    471467
    472468        tp = malloc();
    473         test_base(tp, elemSize, tAlign );
    474         test_use(tp);
    475         free(tp);
     469        test_base( tp, elemSize, tAlign );
     470        test_use( tp );
     471        free( tp );
    476472
    477473        tp = aalloc( dim );
    478         test_base(tp, size, tAlign );
    479         test_use(tp);
    480         free(tp);
     474        test_base( tp, size, tAlign );
     475        test_use( tp );
     476        free( tp );
    481477
    482478        tp = aalloc( 0 );
    483         test_base(tp, 0, libAlign);
    484         test_use(tp);
    485         free(tp);
     479        test_base( tp, 0, libAlign );
     480        test_use( tp );
     481        free( tp );
    486482
    487483        tp = calloc( dim );
    488         test_base(tp, size, tAlign );
    489         test_fill(tp, 0, size, '\0');
    490         test_use(tp);
    491         free(tp);
     484        test_base( tp, size, tAlign );
     485        test_fill( tp, 0, size, '\0' );
     486        test_use( tp );
     487        free( tp );
    492488
    493489        tp = calloc( 0 );
    494         test_base(tp, 0, libAlign);
    495         test_use(tp);
    496         free(tp);
     490        test_base( tp, 0, libAlign );
     491        test_use( tp );
     492        free( tp );
    497493
    498494        tp = aalloc( dim );
    499495        tp = resize( tp, size / 4 );
    500         test_base(tp, size / 4, tAlign );
    501         test_use(tp);
    502         free(tp);
     496        test_base( tp, size / 4, tAlign );
     497        test_use( tp );
     498        free( tp );
    503499
    504500        tp = malloc();
    505501        tp = resize( tp, size * 4 );
    506         test_base(tp, size * 4, tAlign );
    507         test_use(tp);
    508         free(tp);
     502        test_base( tp, size * 4, tAlign );
     503        test_use( tp );
     504        free( tp );
    509505
    510506        tp = aalloc( dim );
    511507        tp = resize( tp, 0 );
    512         test_base(tp, 0, libAlign);
    513         test_use(tp);
    514         free(tp);
     508        test_base( tp, 0, libAlign );
     509        test_use( tp );
     510        free( tp );
    515511
    516512        tp = resize( (T1*)0p, size );
    517         test_base(tp, size, tAlign );
    518         test_use(tp);
    519         free(tp);
     513        test_base( tp, size, tAlign );
     514        test_use( tp );
     515        free( tp );
    520516
    521517        tp = resize( (T1*)0p, size );
    522         test_base(tp, size, tAlign );
    523         test_use(tp);
    524         free(tp);
     518        test_base( tp, size, tAlign );
     519        test_use( tp );
     520        free( tp );
    525521
    526522        tp = calloc( dim );
    527523        tp = realloc( tp, size / 4 );
    528         test_base(tp, size / 4, tAlign );
    529         test_fill(tp, 0, size / 4, '\0');
    530         test_use(tp);
    531         free(tp);
     524        test_base( tp, size / 4, tAlign );
     525        test_fill( tp, 0, size / 4, '\0' );
     526        test_use( tp );
     527        free( tp );
    532528
    533529        tp = calloc( dim );
    534530        tp = realloc( tp, size * 4 );
    535         test_base(tp, size * 4, tAlign );
    536         test_fill(tp, 0, size, '\0');
    537         test_use(tp);
    538         free(tp);
     531        test_base( tp, size * 4, tAlign );
     532        test_fill( tp, 0, size, '\0' );
     533        test_use( tp );
     534        free( tp );
    539535
    540536        tp = calloc( dim );
    541537        tp = realloc( tp, 0 );
    542         test_base(tp, 0, libAlign);
    543         test_use(tp);
    544         free(tp);
     538        test_base( tp, 0, libAlign );
     539        test_use( tp );
     540        free( tp );
    545541
    546542        tp = realloc( (T1*)0p, size  );
    547         test_base(tp, size , tAlign );
    548         test_use(tp);
    549         free(tp);
     543        test_base( tp, size , tAlign );
     544        test_use( tp );
     545        free( tp );
    550546
    551547        tp = realloc( (T1*)0p, size );
    552         test_base(tp, size, tAlign );
    553         test_use(tp);
    554         free(tp);
     548        test_base( tp, size, tAlign );
     549        test_use( tp );
     550        free( tp );
    555551
    556552        tp = memalign( align );
    557         test_base(tp, elemSize, align);
    558         test_use(tp);
    559         free(tp);
     553        test_base( tp, elemSize, align );
     554        test_use( tp );
     555        free( tp );
    560556
    561557        tp = amemalign( align, dim );
    562         test_base(tp, size, align);
    563         test_use(tp);
    564         free(tp);
     558        test_base( tp, size, align );
     559        test_use( tp );
     560        free( tp );
    565561
    566562        tp = amemalign( align, 0 );
    567         test_base(tp, 0, libAlign);
    568         test_use(tp);
    569         free(tp);
     563        test_base( tp, 0, libAlign );
     564        test_use( tp );
     565        free( tp );
    570566
    571567        tp = cmemalign( align, dim );
    572         test_base(tp, size, align);
    573         test_fill(tp, 0, size, '\0');
    574         test_use(tp);
    575         free(tp);
     568        test_base( tp, size, align );
     569        test_fill( tp, 0, size, '\0' );
     570        test_use( tp );
     571        free( tp );
    576572
    577573        tp = cmemalign( align, 0 );
    578         test_base(tp, 0, libAlign);
    579         test_use(tp);
    580         free(tp);
     574        test_base( tp, 0, libAlign );
     575        test_use( tp );
     576        free( tp );
    581577
    582578        tp = aligned_alloc( align );
    583         test_base(tp, elemSize, align);
    584         test_use(tp);
    585         free(tp);
    586 
    587         (int) posix_memalign( (T1 **) &tp, align );
    588         test_base(tp, elemSize, align);
    589         test_use(tp);
    590         free(tp);
     579        test_base( tp, elemSize, align );
     580        test_use( tp );
     581        free( tp );
     582
     583        posix_memalign( (T1 **)&tp, align );
     584        test_base( tp, elemSize, align );
     585        test_use( tp );
     586        free( tp );
    591587
    592588        tp = valloc();
    593         test_base(tp, elemSize, getpagesize());
    594         test_use(tp);
    595         free(tp);
     589        test_base( tp, elemSize, getpagesize() );
     590        test_use( tp );
     591        free( tp );
    596592
    597593        tp = pvalloc();
    598         test_base(tp, getpagesize(), getpagesize());
    599         test_use(tp);
    600         free(tp);
    601 
    602         if (tests_failed == 0) printf("PASSED CFA malloc tests (aligned struct)\n\n");
    603         else printf("failed CFA malloc tests (aligned struct) : %d/%d\n\n", tests_failed, tests_total);
    604 
    605         return 0;
     594        test_base( tp, getpagesize(), getpagesize() );
     595        test_use( tp );
     596        free( tp );
     597
     598        if ( tests_failed == 0 ) sout | "PASSED CFA malloc tests (aligned struct)" | nl | nl;
     599        else sout | "failed CFA malloc tests (aligned struct)" | tests_failed | tests_total | nl | nl;
    606600}
    607601
  • tests/pybin/tools.py

    r9cd5bd2 rdf6cc9d  
    2323
    2424# helper functions to run terminal commands
    25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = []):
     25def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = [], nice = False):
    2626        try:
    2727                cmd = list(cmd)
     
    5858                        error = openfd(error, 'w', onexit, False)
    5959
     60                        # prepare the parameters to the call
     61                        popen_kwargs = {
     62                                'stdout' : output_file,
     63                                'stderr' : error,
     64                                'pass_fds': pass_fds,
     65                        }
     66
     67                        # depending on how we are passing inputs we need to set a different argument to popen
     68                        if input_text:
     69                                popen_kwargs['input'] = bytes(input_text, encoding='utf-8')
     70                        else:
     71                                popen_kwargs['stdin'] = input_file
     72
     73                        # we might want to nice this so it's not to obnixious to users
     74                        if nice:
     75                                popen_kwargs['preexec_fn'] = lambda: os.nice(5)
     76
    6077                        # run the desired command
    6178                        # use with statement to make sure proc is cleaned
    6279                        # don't use subprocess.run because we want to send SIGABRT on exit
    63                         with subprocess.Popen(
    64                                 cmd,
    65                                 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}),
    66                                 stdout  = output_file,
    67                                 stderr  = error,
    68                                 pass_fds = pass_fds
    69                         ) as proc:
    70 
     80                        with subprocess.Popen( cmd, **popen_kwargs ) as proc:
    7181                                try:
    7282                                        out, errout = proc.communicate(
  • tests/test.py

    r9cd5bd2 rdf6cc9d  
    2323
    2424        def match_test(path):
    25                 match = re.search("^%s\/([\w\/\-_]*).expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt$" % settings.SRCDIR, path)
     25                match = re.search("^%s\/([\w\/\-_]*).expect\/([\w\-_\+]+)(\.[\w\-_]+)?\.txt$" % settings.SRCDIR, path)
    2626                if match :
    2727                        test = Test()
     
    7272                                # this is a valid name, let's check if it already exists
    7373                                found = [test for test in all_tests if canonical_path( test.target() ) == testname]
    74                                 setup = itertools.product(settings.all_arch if options.arch else [None])
     74                                setup = settings.all_arch if options.arch else [None]
    7575                                if not found:
    7676                                        # it's a new name, create it according to the name and specified architecture
     
    190190                                if settings.dry_run or is_exe(exe_file):
    191191                                        # run test
    192                                         retcode, _, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True)
     192                                        retcode, _, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True, nice=True)
    193193                                else :
    194194                                        # simply cat the result into the output
Note: See TracChangeset for help on using the changeset viewer.