Index: /trunk/psLib/test/sysUtils/Makefile
===================================================================
--- /trunk/psLib/test/sysUtils/Makefile	(revision 636)
+++ /trunk/psLib/test/sysUtils/Makefile	(revision 637)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/sysUtils
 ##
-##  $Revision: 1.8 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-05-10 18:22:22 $
+##  $Revision: 1.9 $  $Name: not supported by cvs2svn $
+##  $Date: 2004-05-11 03:14:49 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -39,24 +39,24 @@
 all: $(TARGET)
 
-atst_psAbort_01: atst_psAbort_01.o
-atst_psAbort_02: atst_psAbort_02.o
-atst_psAbort_03: atst_psAbort_03.o
-tst_psMemory: tst_psMemory.o
-tst_psError: tst_psError.o   
-tst_psHash00: tst_psHash00.o  
-tst_psHash01: tst_psHash01.o  
-tst_psHash02: tst_psHash02.o 
-tst_psHash03: tst_psHash03.o 
-tst_psHash04: tst_psHash04.o  
-tst_psLogMsg00: tst_psLogMsg00.o
-tst_psLogMsg01: tst_psLogMsg01.o
-tst_psLogMsg02: tst_psLogMsg02.o
-tst_psLogMsg03: tst_psLogMsg03.o
-tst_psStringCopy: tst_psStringCopy.o
-tst_psTrace00: tst_psTrace00.o 
-tst_psTrace01: tst_psTrace01.o
-tst_psTrace02: tst_psTrace02.o
-tst_psTrace03: tst_psTrace03.o 
-tst_psTrace04: tst_psTrace04.o
+atst_psAbort_01:    atst_psAbort_01.o
+atst_psAbort_02:    atst_psAbort_02.o
+atst_psAbort_03:    atst_psAbort_03.o
+tst_psMemory:       tst_psMemory.o
+tst_psError:        tst_psError.o
+tst_psHash00:       tst_psHash00.o
+tst_psHash01:       tst_psHash01.o
+tst_psHash02:       tst_psHash02.o
+tst_psHash03:       tst_psHash03.o
+tst_psHash04:       tst_psHash04.o
+tst_psLogMsg00:     tst_psLogMsg00.o
+tst_psLogMsg01:     tst_psLogMsg01.o
+tst_psLogMsg02:     tst_psLogMsg02.o
+tst_psLogMsg03:     tst_psLogMsg03.o
+tst_psStringCopy:   tst_psStringCopy.o
+tst_psTrace00:      tst_psTrace00.o
+tst_psTrace01:      tst_psTrace01.o
+tst_psTrace02:      tst_psTrace02.o
+tst_psTrace03:      tst_psTrace03.o
+tst_psTrace04:      tst_psTrace04.o
 
 clean:
@@ -65,8 +65,8 @@
 
 %.o : %.c
-	$(CC) $(CFLAGS) $(CPPFLAGS) -I$(PSLIB_INCL_DIR) -c -o $@ $< 
+	$(CC) $(CFLAGS) $(CPPFLAGS) -I.. -I$(PSLIB_INCL_DIR) -c -o $@ $<
 
 %   : %.o
-	$(CC) $(LDFLAGS) -L$(PSLIB_LIB_DIR) -lpslib -lpstest -o $@ $<
+	$(CC) $(LDFLAGS) -L.. -L$(PSLIB_LIB_DIR) -lpslib -lpstest -o $@ $<
 
 %.lint: %.c
Index: /trunk/psLib/test/sysUtils/tst_psMemory.c
===================================================================
--- /trunk/psLib/test/sysUtils/tst_psMemory.c	(revision 636)
+++ /trunk/psLib/test/sysUtils/tst_psMemory.c	(revision 637)
@@ -1,3 +1,3 @@
-/** @file  tstMemory.c
+/** @file  tst_psMemory.c
  *
  *  @brief Contains the tests for psMemory.[ch]
@@ -6,9 +6,12 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-04-28 02:50:56 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-11 03:14:49 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
+
+// need to allow malloc for callback use
+#define PS_ALLOW_MALLOC 1
 
 #include <unistd.h>
@@ -16,14 +19,29 @@
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <limits.h>
+#include <stdlib.h>
+
 
 #include "psTest.h"
-#include "psMemory.h"
-#include "psAbort.h"
+#include "psLib.h"
 
 static int TPFreeReferencedMemory(void);
+static int TPOutOfMemory(void);
+static void* TPOutOfMemoryExhaustedCallback(size_t size);
 static int TPCheckBufferPositive(void);
+static int TPrealloc(void);
+static int TPallocCallback(void);
+static long memAllocateCallback(const psMemBlock *ptr);
+static long memFreeCallback(const psMemBlock *ptr);
+static int allocCallbackCalled = 0;
+static int freeCallbackCalled = 0;
+
+bool TPOutOfMemoryExhaustedCallbackCalled = false;
 
 testDescription tests[] = {
-                              {TPCheckBufferPositive,"TPCheckBufferPositive",0},
+                              {TPCheckBufferPositive,"449-TPCheckBufferPositive",0},
+                              {TPOutOfMemory,"450-TPOutOfMemory",0},
+                              {TPrealloc,"451-TPrealloc",0},
+                              {TPallocCallback,"452-TPallocCallback",0},
                               {TPFreeReferencedMemory,"TPFreeReferencedMemory",6},
                               {NULL}
@@ -32,7 +50,13 @@
 int main()
 {
-    runTestSuite(stderr,"psMemory",tests);
-}
-
+    psSetLogLevel(PS_LOG_INFO);
+
+    if (! runTestSuite(stderr,"psMemory",tests)) {
+        psAbort(__FILE__,"One or more tests failed");
+    }
+    return 0;
+}
+
+// Testpoint #449, psAlloc shall allocate memory blocks writeable by caller.
 int TPCheckBufferPositive(void)
 {
@@ -40,7 +64,13 @@
     const int size = 100;
     int failed = 0;
-
-    printf("Allocating buffer\n");
+    int currentId = psMemGetId();
+
+    psLogMsg(__func__,PS_LOG_INFO,"psAlloc shall allocate memory blocks writeable by caller.\n");
+
     mem = (int*) psAlloc(size*sizeof(int));
+    if (mem == NULL) {
+        psError(__FILE__,"psAlloc returned a NULL value in %s!",__func__);
+        return 1;
+    }
 
     for (int index=0;index<size;index++) {
@@ -54,4 +84,7 @@
     }
 
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
+
     return failed;
 }
@@ -61,13 +94,192 @@
     // create memory
     int* mem;
-
-    printf("Allocating buffer.\n");
+    int currentId = psMemGetId();
+
+    fprintf(stderr,"Allocating buffer.\n");
     mem = (int*) psAlloc(100*sizeof(int));
 
     psMemIncrRefCounter(mem);
-    printf("Freeing buffer after incrementing reference count.\n");
+    fprintf(stderr,"Freeing buffer after incrementing reference count.\n");
     psFree(mem);
 
-    return 0;
-}
-
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
+
+    return 0;
+}
+
+// Testpoint #450,  Upon requesting more memory than is available, psalloc shall call
+// the psMemExhaustedCallback.
+int TPOutOfMemory(void)
+{
+    int currentId = psMemGetId();
+    int* mem;
+    psMemExhaustedCallback cb;
+
+    psLogMsg(__func__,PS_LOG_INFO,"Upon requesting more memory than is available, psalloc shall call "
+             "the psMemExhaustedCallback.\n");
+
+    TPOutOfMemoryExhaustedCallbackCalled = false;
+
+    cb = psMemExhaustedCallbackSet(TPOutOfMemoryExhaustedCallback);
+
+    mem = (int*) psAlloc(INT_MAX);
+
+    psMemExhaustedCallbackSet(cb);
+
+    if (!TPOutOfMemoryExhaustedCallbackCalled) {
+        psError(__FILE__,"Called psAlloc with HUGE memory requirement and survived in %s!",__func__);
+        return 1;
+    }
+
+    psFree(mem);
+
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
+
+    return 0;
+}
+
+
+
+void* TPOutOfMemoryExhaustedCallback(size_t size)
+{
+    psLogMsg(__func__,PS_LOG_INFO,"Custom MemExhaustedCallback was invoked.");
+    TPOutOfMemoryExhaustedCallbackCalled = true;
+    return malloc(1024);
+}
+
+// Testpoint #451,  psRealloc shall increase/decrease memory buffer while preserving contents
+int TPrealloc(void)
+{
+    int currentId = psMemGetId();
+    int* mem1;
+    int* mem2;
+    int* mem3;
+    const int initialSize = 100;
+
+    psLogMsg(__func__,PS_LOG_INFO,"psRealloc shall increase/decrease memory buffer while "
+             "preserving contents");
+
+    // allocate buffer with known values.
+    mem1 = (int*) psAlloc(initialSize*sizeof(int));
+    mem2 = (int*) psAlloc(initialSize*sizeof(int));
+    mem3 = (int*) psAlloc(initialSize*sizeof(int));
+    for (int lcv=0;lcv<initialSize;lcv++) {
+        mem1[lcv] = mem2[lcv] = mem3[lcv] = lcv;
+    }
+
+    psMemCheckCorruption(1);
+    psLogMsg(__func__,PS_LOG_INFO,"Expanding memory buffer.");
+
+    // realloc to 2x
+    mem1 = (int*) psRealloc(mem1, 2*initialSize*sizeof(int));
+    mem2 = (int*) psRealloc(mem2, 2*initialSize*sizeof(int));
+    mem3 = (int*) psRealloc(mem3, 2*initialSize*sizeof(int));
+
+    // check values of initial block
+    for (int i=0;i<initialSize;i++) {
+        if (mem1[i] != i || mem2[i] != i || mem3[i] != i) {
+            psError(__FILE__,"Realloc didn't preserve the contents with expanding buffer in %s.",
+                    __func__);
+            break;
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psLogMsg(__func__,PS_LOG_INFO,"Shrinking memory buffer.");
+
+    // realloc to 1/2 initial value.
+    mem1 = (int*) psRealloc(mem1, (initialSize/2)*sizeof(int));
+    mem2 = (int*) psRealloc(mem2, (initialSize/2)*sizeof(int));
+    mem3 = (int*) psRealloc(mem3, (initialSize/2)*sizeof(int));
+
+    // check values of initial block
+    for (int i=0;i<initialSize/2;i++) {
+        if (mem1[i] != i || mem2[i] != i || mem3[i] != i) {
+            psError(__FILE__,"Realloc didn't preserve the contents with shrinking buffer in %s.",
+                    __func__);
+            break;
+        }
+    }
+
+    psFree(mem1);
+    psFree(mem2);
+    psFree(mem3);
+
+    psMemCheckLeaks(currentId,NULL,NULL);
+    psMemCheckCorruption(1);
+
+    return 0;
+}
+
+int TPallocCallback(void)
+{
+    int* mem1;
+    int* mem2;
+    int* mem3;
+    int currentId = psMemGetId();
+    const int initialSize = 100;
+    int mark;
+
+    allocCallbackCalled = 0;
+    freeCallbackCalled = 0;
+    psMemAllocateCallbackSet(memAllocateCallback);
+    psMemFreeCallbackSet(memFreeCallback);
+
+    psMemAllocateCallbackSetID(currentId+1);
+    psMemFreeCallbackSetID(currentId+1);
+
+    psLogMsg(__func__,PS_LOG_INFO,"call to psAlloc/psRealloc shall generate a callback if specified "
+             "memory ID is allocated.");
+
+    // allocate buffer with known values.
+    mem1 = (int*) psAlloc(initialSize*sizeof(int));
+    mem2 = (int*) psAlloc(initialSize*sizeof(int));
+    mem3 = (int*) psAlloc(initialSize*sizeof(int));
+
+    psFree(mem1);
+    psFree(mem2);
+    psFree(mem3);
+
+    if (allocCallbackCalled != 2 || freeCallbackCalled != 2) {
+        psError(__FILE__,"alloc/free callbacks were not called the proper number of times in %s",
+                __func__);
+        return 1;
+    }
+
+    allocCallbackCalled = 0;
+    freeCallbackCalled = 0;
+
+    mark = psMemGetId();
+
+    mem1 = (int*) psAlloc(initialSize*sizeof(int));
+
+    psMemAllocateCallbackSetID(mark);
+
+    mem1 = (int*) psRealloc(mem1,initialSize*2*sizeof(int));
+
+    psFree(mem1);
+
+    if (allocCallbackCalled != 2) {
+        psError(__FILE__,"realloc callbacks were not called the proper number of times in %s",
+                __func__);
+        return 1;
+    }
+    return 0;
+
+}
+
+long memAllocateCallback(const psMemBlock *ptr)
+{
+    psLogMsg(__func__,PS_LOG_INFO,"block %d was (re)allocated",ptr->id);
+    allocCallbackCalled++;
+    return 1;
+}
+
+long memFreeCallback(const psMemBlock *ptr)
+{
+    psLogMsg(__func__,PS_LOG_INFO,"block %d was freed",ptr->id);
+    freeCallbackCalled++;
+    return 1;
+}
Index: /trunk/psLib/test/sysUtils/verified/tst_psMemory.stderr
===================================================================
--- /trunk/psLib/test/sysUtils/verified/tst_psMemory.stderr	(revision 637)
+++ /trunk/psLib/test/sysUtils/verified/tst_psMemory.stderr	(revision 637)
@@ -0,0 +1,63 @@
+/----------------------------- TESTPOINT ------------------------------------------\
+|             TestFile: tst_psMemory.c                                             |
+|            TestPoint: psMemory{449-TPCheckBufferPositive}                        |
+|             TestType: Positive                                                   |
+\----------------------------------------------------------------------------------/
+
+ <DATE> <TIME> <HOST> |I|TPCheckBufferPositive|psAlloc shall allocate memory blocks writeable by caller.
+
+---> TESTPOINT PASSED (psMemory{449-TPCheckBufferPositive} | tst_psMemory.c)
+
+/----------------------------- TESTPOINT ------------------------------------------\
+|             TestFile: tst_psMemory.c                                             |
+|            TestPoint: psMemory{450-TPOutOfMemory}                                |
+|             TestType: Positive                                                   |
+\----------------------------------------------------------------------------------/
+
+ <DATE> <TIME> <HOST> |I|TPOutOfMemory  |Upon requesting more memory than is available, psalloc shall call the psMemExhaustedCallback.
+ <DATE> <TIME> <HOST> |I|TPOutOfMemoryExhaustedCallback|Custom MemExhaustedCallback was invoked.
+
+---> TESTPOINT PASSED (psMemory{450-TPOutOfMemory} | tst_psMemory.c)
+
+/----------------------------- TESTPOINT ------------------------------------------\
+|             TestFile: tst_psMemory.c                                             |
+|            TestPoint: psMemory{451-TPrealloc}                                    |
+|             TestType: Positive                                                   |
+\----------------------------------------------------------------------------------/
+
+ <DATE> <TIME> <HOST> |I|TPrealloc      |psRealloc shall increase/decrease memory buffer while preserving contents
+ <DATE> <TIME> <HOST> |I|TPrealloc      |Expanding memory buffer.
+ <DATE> <TIME> <HOST> |I|TPrealloc      |Shrinking memory buffer.
+
+---> TESTPOINT PASSED (psMemory{451-TPrealloc} | tst_psMemory.c)
+
+/----------------------------- TESTPOINT ------------------------------------------\
+|             TestFile: tst_psMemory.c                                             |
+|            TestPoint: psMemory{452-TPallocCallback}                              |
+|             TestType: Positive                                                   |
+\----------------------------------------------------------------------------------/
+
+ <DATE> <TIME> <HOST> |I|TPallocCallback|call to psAlloc/psRealloc shall generate a callback if specified memory ID is allocated.
+ <DATE> <TIME> <HOST> |I|memAllocateCallback|block 2 was (re)allocated
+ <DATE> <TIME> <HOST> |I|memAllocateCallback|block 3 was (re)allocated
+ <DATE> <TIME> <HOST> |I|memFreeCallback|block 2 was freed
+ <DATE> <TIME> <HOST> |I|memFreeCallback|block 3 was freed
+ <DATE> <TIME> <HOST> |I|memAllocateCallback|block 4 was (re)allocated
+ <DATE> <TIME> <HOST> |I|memAllocateCallback|block 4 was (re)allocated
+ <DATE> <TIME> <HOST> |I|memFreeCallback|block 4 was freed
+
+---> TESTPOINT PASSED (psMemory{452-TPallocCallback} | tst_psMemory.c)
+
+/----------------------------- TESTPOINT ------------------------------------------\
+|             TestFile: tst_psMemory.c                                             |
+|            TestPoint: psMemory{TPFreeReferencedMemory}                           |
+|             TestType: Positive                                                   |
+\----------------------------------------------------------------------------------/
+
+Allocating buffer.
+Freeing buffer after incrementing reference count.
+ <DATE> <TIME> <HOST> |E|p_psFree       |The buffer being freed is referenced elsewhere. Buffer's reference count was decremented instead.
+ <DATE> <TIME> <HOST> |A|memProblemCallbackDefault|Detected a problem in the memory system at tst_psMemory.c:103
+
+---> TESTPOINT PASSED (psMemory{TPFreeReferencedMemory} | tst_psMemory.c)
+
