Changeset 80228a7 for tests/heap.cfa


Ignore:
Timestamp:
Nov 8, 2018, 9:00:59 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
1e995d6
Parents:
303d866
Message:

change from old to new style for-control

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/heap.cfa

    r303d866 r80228a7  
    1010// Created On       : Tue Nov  6 17:54:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Nov  6 17:55:39 2018
    13 // Update Count     : 2
     12// Last Modified On : Thu Nov  8 09:03:54 2018
     13// Update Count     : 17
    1414//
    1515
    1616#include <thread.hfa>
    17 #include <kernel.hfa>                                                                           // processor
    18 #include <stdlib.hfa>                                                                           // *allocs
     17#include <kernel.hfa>                                                                   // processor
     18#include <stdlib.hfa>                                                                   // *allocs
    1919#include <malloc.h>                                                                             // malloc_*
    2020
     
    3737void main( Worker & ) {
    3838    enum { NoOfAllocs = 5000, NoOfMmaps = 10 };
    39     char *locns[NoOfAllocs];
     39    char * locns[NoOfAllocs];
    4040    int i;
    4141
    4242    // check alloc/free
    4343
    44     for ( int j = 0; j < 40; j += 1 ) {
    45                 for ( i = 0; i < NoOfAllocs; i += 1 ) {
     44    for ( j; 40 ) {
     45                for ( i; NoOfAllocs ) {
    4646                        locns[i] = alloc( i );
    4747                        //sout | (void *)locns[i] | endl;
    48                         for ( int k = 0; k < i; k += 1 ) locns[i][k] = '\345';
     48                        for ( k; i ) locns[i][k] = '\345';
    4949                } // for
    5050                //sout | (char *)sbrk(0) - start | " bytes" | endl;
    5151
    52                 for ( i = 0; i < NoOfAllocs; i += 1 ) {
     52                for ( i; NoOfAllocs ) {
    5353                        //sout | (void *)locns[i] | endl;
    54                         for ( int k = 0; k < i; k += 1 ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" );
     54                        for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" );
    5555                        free( locns[i] );
    5656                } // for
    5757                //sout | (char *)sbrk(0) - start | " bytes" | endl;
    5858
    59                 for ( i = 0; i < NoOfAllocs; i += 1 ) {
     59                for ( i; NoOfAllocs ) {
    6060                        locns[i] = alloc( i );
    6161                        //sout | (void *)locns[i] | endl;
    62                         for ( int k = 0; k < i; k += 1 ) locns[i][k] = '\345';
    63                 } // for
    64                 for ( i = NoOfAllocs - 1; i >=0 ; i -= 1 ) {
     62                        for ( k; i ) locns[i][k] = '\345';
     63                } // for
     64                for ( i; NoOfAllocs - 1 -~= 0 ) {
    6565                        //sout | (void *)locns[i] | endl;
    66                         for ( int k = 0; k < i; k += 1 ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" );
     66                        for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" );
    6767                        free( locns[i] );
    6868                } // for
     
    7171    // check malloc/free (sbrk)
    7272
    73     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     73    for ( i; NoOfAllocs ) {
    7474                size_t s = (i + 1) * 20;
    75                 char *area = (char *)malloc( s );
     75                char * area = (char *)malloc( s );
    7676                if ( area == 0 ) abort( "malloc/free out of memory" );
    7777                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
     
    8080    } // for
    8181
    82     for ( i = 0; i < NoOfAllocs; i += 1 ) {
    83                 size_t s = i + 1;                               // +1 to make initialization simpler
     82    for ( i; NoOfAllocs ) {
     83                size_t s = i + 1;                                                               // +1 to make initialization simpler
    8484                locns[i] = (char *)malloc( s );
    8585                if ( locns[i] == 0 ) abort( "malloc/free out of memory" );
     
    8787                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    8888    } // for
    89     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     89    for ( i; NoOfAllocs ) {
    9090                size_t s = i + 1;
    9191                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
     
    9696    // check malloc/free (mmap)
    9797
    98     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    99                 size_t s = i + default_mmap_start();                            // cross over point
    100                 char *area = (char *)malloc( s );
     98    for ( i; NoOfMmaps ) {
     99                size_t s = i + default_mmap_start();                    // cross over point
     100                char * area = (char *)malloc( s );
    101101                if ( area == 0 ) abort( "malloc/free out of memory" );
    102102                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
     
    105105    } // for
    106106
    107     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    108                 size_t s = i + default_mmap_start();                            // cross over point
     107    for ( i; NoOfMmaps ) {
     108                size_t s = i + default_mmap_start();                    // cross over point
    109109                locns[i] = (char *)malloc( s );
    110110                if ( locns[i] == 0 ) abort( "malloc/free out of memory" );
     
    112112                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    113113    } // for
    114     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    115                 size_t s = i + default_mmap_start();                            // cross over point
     114    for ( i; NoOfMmaps ) {
     115                size_t s = i + default_mmap_start();                    // cross over point
    116116                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
    117117                         locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "malloc/free corrupt storage" );
     
    121121    // check calloc/free (sbrk)
    122122
    123     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     123    for ( i; NoOfAllocs ) {
    124124                size_t s = (i + 1) * 20;
    125                 char *area = (char *)calloc( 5, s );
     125                char * area = (char *)calloc( 5, s );
    126126                if ( area == 0 ) abort( "calloc/free out of memory" );
    127127                if ( area[0] != '\0' || area[s - 1] != '\0' ||
     
    133133    } // for
    134134
    135     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     135    for ( i; NoOfAllocs ) {
    136136                size_t s = i + 1;
    137137                locns[i] = (char *)calloc( 5, s );
     
    143143                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    144144    } // for
    145     for ( i = 0; i < NoOfAllocs; i += 1 ) {
     145    for ( i; NoOfAllocs ) {
    146146                size_t s = i + 1;
    147147                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
     
    152152    // check calloc/free (mmap)
    153153
    154     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    155                 size_t s = i + default_mmap_start();                            // cross over point
    156                 char *area = (char *)calloc( 1, s );
     154    for ( i; NoOfMmaps ) {
     155                size_t s = i + default_mmap_start();                    // cross over point
     156                char * area = (char *)calloc( 1, s );
    157157                if ( area == 0 ) abort( "calloc/free out of memory" );
    158158                if ( area[0] != '\0' || area[s - 1] != '\0' ) abort( "calloc/free corrupt storage4.1" );
     
    164164    } // for
    165165
    166     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    167                 size_t s = i + default_mmap_start();                            // cross over point
     166    for ( i; NoOfMmaps ) {
     167                size_t s = i + default_mmap_start();                    // cross over point
    168168                locns[i] = (char *)calloc( 1, s );
    169169                if ( locns[i] == 0 ) abort( "calloc/free out of memory" );
     
    174174                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
    175175    } // for
    176     for ( i = 0; i < NoOfMmaps; i += 1 ) {
    177                 size_t s = i + default_mmap_start();                            // cross over point
     176    for ( i; NoOfMmaps ) {
     177                size_t s = i + default_mmap_start();                    // cross over point
    178178                if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' ||
    179179                         locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "calloc/free corrupt storage6" );
     
    185185    enum { limit = 64 * 1024 };                                                 // check alignments up to here
    186186
    187     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
     187        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    188188                //sout | alignments[a] | endl;
    189                 for ( int s = 1; s < NoOfAllocs; s += 1 ) {             // allocation of size 0 can return null
    190                         char *area = (char *)memalign( a, s );
     189                for ( s; 1 ~ NoOfAllocs ) {                                             // allocation of size 0 can return null
     190                        char * area = (char *)memalign( a, s );
    191191                        if ( area == 0 ) abort( "memalign/free out of memory" );
    192192                        //sout | i | " " | area | endl;
     
    202202    // check memalign/free (mmap)
    203203
    204     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
     204        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    205205                //sout | alignments[a] | endl;
    206                 for ( i = 1; i < NoOfMmaps; i += 1 ) {
    207                         size_t s = i + default_mmap_start();                    // cross over point
    208                         char *area = (char *)memalign( a, s );
     206                for ( i; 1 ~ NoOfMmaps ) {
     207                        size_t s = i + default_mmap_start();            // cross over point
     208                        char * area = (char *)memalign( a, s );
    209209                        if ( area == 0 ) abort( "memalign/free out of memory" );
    210210                        //sout | i | " " | area | endl;
     
    220220    // check calloc/realloc/free (sbrk)
    221221
    222     for ( i = 1; i < 10000; i += 12 ) {
     222    for ( i; 1 ~ 10_000 ~ 12 ) {
    223223                // initial N byte allocation
    224                 char *area = (char *)calloc( 5, i );
     224                char * area = (char *)calloc( 5, i );
    225225                if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
    226226                if ( area[0] != '\0' || area[i - 1] != '\0' ||
     
    229229
    230230                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    231                 for ( int s = i; s < 256 * 1024; s += 26 ) {    // start at initial memory request
     231                for ( s; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
    232232                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    233233                        if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
     
    241241    // check calloc/realloc/free (mmap)
    242242
    243     for ( i = 1; i < 1000; i += 12 ) {
     243    for ( i; 1 ~ 10_000 ~ 12 ) {
    244244                // initial N byte allocation
    245                 size_t s = i + default_mmap_start();                            // cross over point
    246                 char *area = (char *)calloc( 1, s );
     245                size_t s = i + default_mmap_start();                    // cross over point
     246                char * area = (char *)calloc( 1, s );
    247247                if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
    248248                if ( area[0] != '\0' || area[s - 1] != '\0' ||
     
    251251
    252252                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    253                 for ( int r = i; r < 256 * 1024; r += 26 ) {    // start at initial memory request
    254                         area = (char *)realloc( area, r );              // attempt to reuse storage
     253                for ( r; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
     254                        area = (char *)realloc( area, r );                      // attempt to reuse storage
    255255                        if ( area == 0 ) abort( "calloc/realloc/free out of memory" );
    256256                        if ( area[0] != '\0' || area[r - 1] != '\0' ||
     
    264264
    265265    size_t amount = 2;
    266     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
     266        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    267267                // initial N byte allocation
    268                 char *area = (char *)memalign( a, amount );             // aligned N-byte allocation
     268                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
    269269                if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    270270                //sout | alignments[a] | " " | area | endl;
     
    275275
    276276                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    277                 for ( int s = amount; s < 256 * 1024; s += 1 ) { // start at initial memory request
     277                for ( s; amount ~ 256 * 1024 ) {                                // start at initial memory request
    278278                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" );
    279279                        area = (char *)realloc( area, s );                      // attempt to reuse storage
     
    290290    // check cmemalign/free
    291291
    292     for ( size_t a = libAlign(); a <= limit; a += a ) { // generate powers of 2
     292        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    293293                //sout | alignments[a] | endl;
    294                 for ( int s = 1; s < limit; s += 1 ) {                  // allocation of size 0 can return null
    295                         char *area = (char *)cmemalign( a, 1, s );
     294                for ( s; 1 ~ limit ) {                                                  // allocation of size 0 can return null
     295                        char * area = (char *)cmemalign( a, 1, s );
    296296                        if ( area == 0 ) abort( "cmemalign/free out of memory" );
    297297                        //sout | i | " " | area | endl;
     
    310310
    311311    amount = 2;
    312     for ( size_t a = libAlign() + libAlign(); a <= limit; a += a ) { // generate powers of 2
     312        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
    313313                // initial N byte allocation
    314                 char *area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
     314                char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
    315315                if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?
    316316                //sout | alignments[a] | " " | area | endl;
     
    324324
    325325                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    326                 for ( int s = amount; s < 256 * 1024; s += 1 ) { // start at initial memory request
     326                for ( s; amount ~ 256 * 1024 ) {                                // start at initial memory request
    327327                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc/free corrupt storage2" );
    328328                        area = (char *)realloc( area, s );                      // attempt to reuse storage
Note: See TracChangeset for help on using the changeset viewer.