IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2004, 11:51:46 AM (22 years ago)
Author:
desonia
Message:

added regression test for psRealloc.

File:
1 edited

Legend:

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

    r1075 r1097  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-24 00:54:59 $
     8 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-25 21:51:46 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828static int TPFreeReferencedMemory(void);
    2929static int TPOutOfMemory(void);
     30static int TPReallocOutOfMemory(void);
    3031static void* TPOutOfMemoryExhaustedCallback(size_t size);
    3132static int TPCheckBufferPositive(void);
     
    4647                              {TPCheckBufferPositive,"449-TPCheckBufferPositive",0},
    4748                              {TPOutOfMemory,"450-TPOutOfMemory",-6},
     49                              {TPReallocOutOfMemory,"562-TPReallocOutOfMemory",-6},
    4850                              {TPrealloc,"451-TPrealloc",0},
    4951                              {TPallocCallback,"452/453-TPallocCallback",0},
     
    145147}
    146148
     149// Bug/Task #562 regression test.  Upon requesting more memory than is available, psRealloc shall call
     150// the psMemExhaustedCallback.
     151int TPReallocOutOfMemory(void)
     152{
     153    int* mem[100];
     154    psMemExhaustedCallback cb;
     155
     156    for (int lcv = 0; lcv<100; lcv++) {
     157        mem[lcv] = NULL;
     158    }
     159
     160    psLogMsg(__func__,PS_LOG_INFO,"Upon requesting more memory than is available, psRealloc shall call "
     161             "the psMemExhaustedCallback.\n");
     162
     163    exhaustedCallbackCalled = 0;
     164
     165    cb = psMemExhaustedCallbackSet(TPOutOfMemoryExhaustedCallback);
     166
     167    for (int lcv = 0; lcv<100; lcv++) {
     168        mem[lcv] = (int*) psAlloc(10);
     169    }
     170
     171    for (int lcv = 0; lcv<100; lcv++) {
     172        mem[lcv] = (int*) psRealloc(mem[lcv],SIZE_MAX-1000);
     173    }
     174
     175    psMemExhaustedCallbackSet(cb);
     176
     177    if (exhaustedCallbackCalled == 0) {
     178        psError(__FILE__,"Called psRealloc with HUGE memory requirement and survived in %s!",__func__);
     179        return 1;
     180    }
     181
     182    for (int lcv = 0; lcv<100; lcv++) {
     183        psFree(mem[lcv]);
     184    }
     185
     186    return 0;
     187}
    147188// Testpoint #450,  Upon requesting more memory than is available, psalloc shall call
    148189// the psMemExhaustedCallback.
Note: See TracChangeset for help on using the changeset viewer.