IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 26, 2004, 2:57:34 PM (22 years ago)
Author:
desonia
Message:

converted native C types to ps Types, where practical.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/sysUtils/tst_psMemory.c

    r1811 r2204  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-09-14 23:55:47 $
     8*  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2004-10-27 00:57:33 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626#include "pslib.h"
    2727
    28 static int TPFreeReferencedMemory( void );
    29 static int TPOutOfMemory( void );
    30 static int TPReallocOutOfMemory( void );
    31 static void* TPOutOfMemoryExhaustedCallback( size_t size );
    32 static int TPCheckBufferPositive( void );
    33 static int TPrealloc( void );
    34 static int TPallocCallback( void );
     28static psS32 TPFreeReferencedMemory( void );
     29static psS32 TPOutOfMemory( void );
     30static psS32 TPReallocOutOfMemory( void );
     31static psPtr TPOutOfMemoryExhaustedCallback( size_t size );
     32static psS32 TPCheckBufferPositive( void );
     33static psS32 TPrealloc( void );
     34static psS32 TPallocCallback( void );
    3535static psMemoryId memAllocateCallback( const psMemBlock *ptr );
    3636static psMemoryId memFreeCallback( const psMemBlock *ptr );
    37 static int TPcheckLeaks( void );
    38 static int TPmemCorruption( void );
    39 static int TPmultipleFree( void );
    40 void memProblemCallback( const psMemBlock *ptr, const char *file, int lineno );
    41 
    42 static int problemCallbackCalled = 0;
    43 static int allocCallbackCalled = 0;
    44 static int freeCallbackCalled = 0;
    45 static int exhaustedCallbackCalled = 0;
     37static psS32 TPcheckLeaks( void );
     38static psS32 TPmemCorruption( void );
     39static psS32 TPmultipleFree( void );
     40void memProblemCallback( const psMemBlock *ptr, const char *file, psS32 lineno );
     41
     42static psS32 problemCallbackCalled = 0;
     43static psS32 allocCallbackCalled = 0;
     44static psS32 freeCallbackCalled = 0;
     45static psS32 exhaustedCallbackCalled = 0;
    4646
    4747testDescription tests[] = {
     
    8181                          };
    8282
    83 int main( int argc, char* argv[] )
     83psS32 main( psS32 argc, char* argv[] )
    8484{
    8585    psLogSetLevel( PS_LOG_INFO );
     
    8989
    9090// Testpoint #449, psAlloc shall allocate memory blocks writeable by caller.
    91 int TPCheckBufferPositive( void )
    92 {
    93     int * mem;
    94     const int size = 100;
    95     int failed = 0;
     91psS32 TPCheckBufferPositive( void )
     92{
     93    psS32 * mem;
     94    const psS32 size = 100;
     95    psS32 failed = 0;
    9696
    9797    psLogMsg( __func__, PS_LOG_INFO, "psAlloc shall allocate memory blocks writeable by caller.\n" );
    9898
    99     mem = ( int* ) psAlloc( size * sizeof( int ) );
     99    mem = ( psS32* ) psAlloc( size * sizeof( psS32 ) );
    100100    if ( mem == NULL ) {
    101101        psError( __FILE__, "psAlloc returned a NULL value in %s!", __func__ );
     
    103103    }
    104104
    105     for ( int index = 0;index < size;index++ ) {
     105    for ( psS32 index = 0;index < size;index++ ) {
    106106        mem[ index ] = index;
    107107    }
    108108
    109     for ( int index = 0;index < size;index++ ) {
     109    for ( psS32 index = 0;index < size;index++ ) {
    110110        if ( mem[ index ] != index ) {
    111111            failed++;
     
    118118}
    119119
    120 int TPFreeReferencedMemory( void )
     120psS32 TPFreeReferencedMemory( void )
    121121{
    122122    // create memory
    123     int * mem;
    124     int ref = 0;
     123    psS32 * mem;
     124    psS32 ref = 0;
    125125
    126126    psLogMsg( __func__, PS_LOG_INFO, "memory reference count shall be incrementable/decrementable" );
    127127
    128     mem = ( int* ) psAlloc( 100 * sizeof( int ) );
     128    mem = ( psS32* ) psAlloc( 100 * sizeof( psS32 ) );
    129129
    130130    ref = psMemGetRefCounter( mem );
     
    170170// Bug/Task #562 regression test.  Upon requesting more memory than is available, psRealloc shall call
    171171// the psMemExhaustedCallback.
    172 int TPReallocOutOfMemory( void )
    173 {
    174     int * mem[ 100 ];
     172psS32 TPReallocOutOfMemory( void )
     173{
     174    psS32 * mem[ 100 ];
    175175    psMemExhaustedCallback cb;
    176176
    177     for ( int lcv = 0; lcv < 100; lcv++ ) {
     177    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
    178178        mem[ lcv ] = NULL;
    179179    }
     
    186186    cb = psMemExhaustedCallbackSet( TPOutOfMemoryExhaustedCallback );
    187187
    188     for ( int lcv = 0; lcv < 100; lcv++ ) {
    189         mem[ lcv ] = ( int* ) psAlloc( 10 );
    190     }
    191 
    192     for ( int lcv = 0; lcv < 100; lcv++ ) {
    193         mem[ lcv ] = ( int* ) psRealloc( mem[ lcv ], SIZE_MAX/2 - 1000 );
     188    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
     189        mem[ lcv ] = ( psS32* ) psAlloc( 10 );
     190    }
     191
     192    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
     193        mem[ lcv ] = ( psS32* ) psRealloc( mem[ lcv ], SIZE_MAX/2 - 1000 );
    194194    }
    195195
     
    201201    }
    202202
    203     for ( int lcv = 0; lcv < 100; lcv++ ) {
     203    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
    204204        psFree( mem[ lcv ] );
    205205    }
     
    209209// Testpoint #450,  Upon requesting more memory than is available, psalloc shall call
    210210// the psMemExhaustedCallback.
    211 int TPOutOfMemory( void )
    212 {
    213     int * mem[ 100 ];
     211psS32 TPOutOfMemory( void )
     212{
     213    psS32 * mem[ 100 ];
    214214    psMemExhaustedCallback cb;
    215215
    216     for ( int lcv = 0; lcv < 100; lcv++ ) {
     216    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
    217217        mem[ lcv ] = NULL;
    218218    }
     
    225225    cb = psMemExhaustedCallbackSet( TPOutOfMemoryExhaustedCallback );
    226226
    227     for ( int lcv = 0; lcv < 100; lcv++ ) {
    228         mem[ lcv ] = ( int* ) psAlloc( SIZE_MAX/2 - 1000 );
     227    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
     228        mem[ lcv ] = ( psS32* ) psAlloc( SIZE_MAX/2 - 1000 );
    229229    }
    230230
     
    236236    }
    237237
    238     for ( int lcv = 0; lcv < 100; lcv++ ) {
     238    for ( psS32 lcv = 0; lcv < 100; lcv++ ) {
    239239        psFree( mem[ lcv ] );
    240240    }
     
    244244
    245245// Testpoint #451,  psRealloc shall increase/decrease memory buffer while preserving contents
    246 int TPrealloc( void )
    247 {
    248     int * mem1;
    249     int* mem2;
    250     int* mem3;
    251     const int initialSize = 100;
     246psS32 TPrealloc( void )
     247{
     248    psS32 * mem1;
     249    psS32* mem2;
     250    psS32* mem3;
     251    const psS32 initialSize = 100;
    252252
    253253    psLogMsg( __func__, PS_LOG_INFO, "psRealloc shall increase/decrease memory buffer while "
     
    255255
    256256    // allocate buffer with known values.
    257     mem1 = ( int* ) psAlloc( initialSize * sizeof( int ) );
    258     mem2 = ( int* ) psAlloc( initialSize * sizeof( int ) );
    259     mem3 = ( int* ) psAlloc( initialSize * sizeof( int ) );
    260     for ( int lcv = 0;lcv < initialSize;lcv++ ) {
     257    mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
     258    mem2 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
     259    mem3 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
     260    for ( psS32 lcv = 0;lcv < initialSize;lcv++ ) {
    261261        mem1[ lcv ] = mem2[ lcv ] = mem3[ lcv ] = lcv;
    262262    }
     
    266266
    267267    // realloc to 2x
    268     mem1 = ( int* ) psRealloc( mem1, 2 * initialSize * sizeof( int ) );
    269     mem2 = ( int* ) psRealloc( mem2, 2 * initialSize * sizeof( int ) );
    270     mem3 = ( int* ) psRealloc( mem3, 2 * initialSize * sizeof( int ) );
     268    mem1 = ( psS32* ) psRealloc( mem1, 2 * initialSize * sizeof( psS32 ) );
     269    mem2 = ( psS32* ) psRealloc( mem2, 2 * initialSize * sizeof( psS32 ) );
     270    mem3 = ( psS32* ) psRealloc( mem3, 2 * initialSize * sizeof( psS32 ) );
    271271
    272272    // check values of initial block
    273     for ( int i = 0;i < initialSize;i++ ) {
     273    for ( psS32 i = 0;i < initialSize;i++ ) {
    274274        if ( mem1[ i ] != i || mem2[ i ] != i || mem3[ i ] != i ) {
    275275            psError( __FILE__, "Realloc didn't preserve the contents with expanding buffer in %s.",
     
    283283
    284284    // realloc to 1/2 initial value.
    285     mem1 = ( int* ) psRealloc( mem1, ( initialSize / 2 ) * sizeof( int ) );
    286     mem2 = ( int* ) psRealloc( mem2, ( initialSize / 2 ) * sizeof( int ) );
    287     mem3 = ( int* ) psRealloc( mem3, ( initialSize / 2 ) * sizeof( int ) );
     285    mem1 = ( psS32* ) psRealloc( mem1, ( initialSize / 2 ) * sizeof( psS32 ) );
     286    mem2 = ( psS32* ) psRealloc( mem2, ( initialSize / 2 ) * sizeof( psS32 ) );
     287    mem3 = ( psS32* ) psRealloc( mem3, ( initialSize / 2 ) * sizeof( psS32 ) );
    288288
    289289    // check values of initial block
    290     for ( int i = 0;i < initialSize / 2;i++ ) {
     290    for ( psS32 i = 0;i < initialSize / 2;i++ ) {
    291291        if ( mem1[ i ] != i || mem2[ i ] != i || mem3[ i ] != i ) {
    292292            psError( __FILE__, "Realloc didn't preserve the contents with shrinking buffer in %s.",
     
    303303}
    304304
    305 int TPallocCallback( void )
    306 {
    307     int * mem1;
    308     int* mem2;
    309     int* mem3;
    310     int currentId = psMemGetId();
    311     const int initialSize = 100;
    312     int mark;
     305psS32 TPallocCallback( void )
     306{
     307    psS32 * mem1;
     308    psS32* mem2;
     309    psS32* mem3;
     310    psS32 currentId = psMemGetId();
     311    const psS32 initialSize = 100;
     312    psS32 mark;
    313313
    314314    allocCallbackCalled = 0;
     
    324324
    325325    // allocate buffer with known values.
    326     mem1 = ( int* ) psAlloc( initialSize * sizeof( int ) );
    327     mem2 = ( int* ) psAlloc( initialSize * sizeof( int ) );
    328     mem3 = ( int* ) psAlloc( initialSize * sizeof( int ) );
     326    mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
     327    mem2 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
     328    mem3 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
    329329
    330330    psFree( mem1 );
     
    343343    mark = psMemGetId();
    344344
    345     mem1 = ( int* ) psAlloc( initialSize * sizeof( int ) );
     345    mem1 = ( psS32* ) psAlloc( initialSize * sizeof( psS32 ) );
    346346
    347347    psMemAllocateCallbackSetID( mark );
    348348
    349     mem1 = ( int* ) psRealloc( mem1, initialSize * 2 * sizeof( int ) );
     349    mem1 = ( psS32* ) psRealloc( mem1, initialSize * 2 * sizeof( psS32 ) );
    350350
    351351    psFree( mem1 );
     
    361361}
    362362
    363 int TPcheckLeaks( void )
    364 {
    365     const int numBuffers = 5;
    366     int* buffers[ 5 ];
    367     int lcv;
    368     int currentId = psMemGetId();
     363psS32 TPcheckLeaks( void )
     364{
     365    const psS32 numBuffers = 5;
     366    psS32* buffers[ 5 ];
     367    psS32 lcv;
     368    psS32 currentId = psMemGetId();
    369369    psMemBlock** blks;
    370     int nLeaks = 0;
    371     int lineMark = 0;
     370    psS32 nLeaks = 0;
     371    psS32 lineMark = 0;
    372372
    373373    psLogMsg( __func__, PS_LOG_INFO, "psMemCheckLeaks shall return the number of blocks above an ID "
     
    376376    for ( lcv = 0;lcv < numBuffers;lcv++ ) {
    377377        lineMark = __LINE__ + 1;
    378         buffers[ lcv ] = psAlloc( sizeof( int ) );
     378        buffers[ lcv ] = psAlloc( sizeof( psS32 ) );
    379379    }
    380380
     
    406406    for ( lcv = 0;lcv < numBuffers;lcv++ ) {
    407407        lineMark = __LINE__ + 1;
    408         buffers[ lcv ] = psAlloc( sizeof( int ) );
     408        buffers[ lcv ] = psAlloc( sizeof( psS32 ) );
    409409    }
    410410
     
    434434    for ( lcv = 0;lcv < numBuffers;lcv++ ) {
    435435        lineMark = __LINE__ + 1;
    436         buffers[ lcv ] = psAlloc( sizeof( int ) );
     436        buffers[ lcv ] = psAlloc( sizeof( psS32 ) );
    437437    }
    438438
     
    464464}
    465465
    466 int TPmemCorruption( void )
    467 {
    468     int * buffer = NULL;
    469     int oldValue = 0;
    470     int corruptions = 0;
     466psS32 TPmemCorruption( void )
     467{
     468    psS32 * buffer = NULL;
     469    psS32 oldValue = 0;
     470    psS32 corruptions = 0;
    471471    psMemProblemCallback cb;
    472472
    473473    psLogMsg( __func__, PS_LOG_INFO, "psMemCheckCorruption shall detect memory corruptions" );
    474474
    475     buffer = psAlloc( sizeof( int ) );
     475    buffer = psAlloc( sizeof( psS32 ) );
    476476
    477477    // cause memory corruption via buffer underflow
     
    514514}
    515515
    516 void memProblemCallback( const psMemBlock *ptr, const char *file, int lineno )
     516void memProblemCallback( const psMemBlock *ptr, const char *file, psS32 lineno )
    517517{
    518518    psLogMsg( __func__, PS_LOG_INFO, "memory callback called for id %d (%s:%d).",
     
    536536}
    537537
    538 void* TPOutOfMemoryExhaustedCallback( size_t size )
     538psPtr TPOutOfMemoryExhaustedCallback( size_t size )
    539539{
    540540    psLogMsg( __func__, PS_LOG_INFO, "Custom MemExhaustedCallback was invoked." );
     
    543543}
    544544
    545 int TPmultipleFree( void )
    546 {
    547 
    548     void * buffer = psAlloc( 1024 );
     545psS32 TPmultipleFree( void )
     546{
     547
     548    psPtr buffer = psAlloc( 1024 );
    549549
    550550    psFree( buffer );
Note: See TracChangeset for help on using the changeset viewer.