Changeset 14d8a9b for tests/heap.cfa


Ignore:
Timestamp:
Sep 8, 2020, 1:33:50 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b7f6f0
Parents:
ce55a81 (diff), dfc13bb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/heap.cfa

    rce55a81 r14d8a9b  
    1010// Created On       : Tue Nov  6 17:54:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  9 08:05:16 2020
    13 // Update Count     : 57
     12// Last Modified On : Mon Sep  7 18:37:41 2020
     13// Update Count     : 72
    1414//
    1515
     
    205205                        free( area );
    206206                } // for
     207        } // for
     208
     209        // check malloc/resize/free (sbrk)
     210
     211        for ( i; 2 ~ NoOfAllocs ~ 12 ) {
     212                // initial N byte allocation
     213                char * area = (char *)malloc( i );
     214                area[0] = '\345'; area[i - 1] = '\345';                 // fill first/penultimate byte
     215
     216                // Do not start this loop index at 0 because resize of 0 bytes frees the storage.
     217                int prev = i;
     218                for ( s; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
     219                        if ( area[0] != '\345' || area[prev - 1] != '\345' ) abort( "malloc/resize/free corrupt storage" );
     220                        area = (char *)resize( area, s );                       // attempt to reuse storage
     221                        area[0] = area[s - 1] = '\345';                         // fill last byte
     222                        prev = s;
     223                } // for
     224                free( area );
     225        } // for
     226
     227        // check malloc/resize/free (mmap)
     228
     229        for ( i; 2 ~ NoOfAllocs ~ 12 ) {
     230                // initial N byte allocation
     231                size_t s = i + default_mmap_start();                    // cross over point
     232                char * area = (char *)malloc( s );
     233                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/penultimate byte
     234
     235                // Do not start this loop index at 0 because resize of 0 bytes frees the storage.
     236                int prev = s;
     237                for ( r; s ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
     238                        if ( area[0] != '\345' || area[prev - 1] != '\345' ) abort( "malloc/resize/free corrupt storage" );
     239                        area = (char *)resize( area, s );                       // attempt to reuse storage
     240                        area[0] = area[r - 1] = '\345';                         // fill last byte
     241                        prev = r;
     242                } // for
     243                free( area );
     244        } // for
     245
     246        // check malloc/realloc/free (sbrk)
     247
     248        for ( i; 2 ~ NoOfAllocs ~ 12 ) {
     249                // initial N byte allocation
     250                char * area = (char *)malloc( i );
     251                area[0] = '\345'; area[i - 1] = '\345';                 // fill first/penultimate byte
     252
     253                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
     254                int prev = i;
     255                for ( s; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
     256                        if ( area[0] != '\345' || area[prev - 1] != '\345' ) abort( "malloc/realloc/free corrupt storage" );
     257                        area = (char *)realloc( area, s );                      // attempt to reuse storage
     258                        area[s - 1] = '\345';                                           // fill last byte
     259                        prev = s;
     260                } // for
     261                free( area );
     262        } // for
     263
     264        // check malloc/realloc/free (mmap)
     265
     266        for ( i; 2 ~ NoOfAllocs ~ 12 ) {
     267                // initial N byte allocation
     268                size_t s = i + default_mmap_start();                    // cross over point
     269                char * area = (char *)malloc( s );
     270                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/penultimate byte
     271
     272                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
     273                int prev = s;
     274                for ( r; s ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
     275                        if ( area[0] != '\345' || area[prev - 1] != '\345' ) abort( "malloc/realloc/free corrupt storage" );
     276                        area = (char *)realloc( area, s );                      // attempt to reuse storage
     277                        area[r - 1] = '\345';                                           // fill last byte
     278                        prev = r;
     279                } // for
     280                free( area );
    207281        } // for
    208282
     
    320394        } // for
    321395
     396        // check memalign/resize with align/free
     397
     398        amount = 2;
     399        for ( a; libAlign() ~= limit ~ a ) {                            // generate powers of 2
     400                // initial N byte allocation
     401                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
     402                //sout | alignments[a] | area | endl;
     403                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     404                        abort( "memalign/resize with align/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)amount, area );
     405                } // if
     406                area[0] = '\345'; area[amount - 2] = '\345';    // fill first/penultimate byte
     407
     408                // Do not start this loop index at 0 because resize of 0 bytes frees the storage.
     409                for ( s; amount ~ 256 * 1024 ) {                                // start at initial memory request
     410                        area = (char *)resize( area, a * 2, s );        // attempt to reuse storage
     411                        //sout | i | area | endl;
     412                        if ( (size_t)area % a * 2 != 0 ) {                      // check for initial alignment
     413                                abort( "memalign/resize with align/free bad alignment %p", area );
     414                        } // if
     415                        area[s - 1] = '\345';                                           // fill last byte
     416                } // for
     417                free( area );
     418        } // for
     419
    322420        // check memalign/realloc with align/free
    323421
Note: See TracChangeset for help on using the changeset viewer.