IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1193 for trunk/psLib/test


Ignore:
Timestamp:
Jul 7, 2004, 3:05:01 PM (22 years ago)
Author:
desonia
Message:

rewrote psImageCopy so that macro need not be expanded.

Location:
trunk/psLib/test
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/collections/tst_psList.c

    r1126 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-29 23:18:00 $
     8 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828
    2929testDescription tests[] = {
    30                               {testListAlloc,"487-testListAlloc",0},
    31                               {testListAdd,"488-testListAdd",0},
    32                               {testListGet,"489-testListGet",0},
    33                               {testListRemove,"490-testListRemove",0},
    34                               {testListConvert,"491-testListConvert",0},
    35                               {testListIterator,"494-testListIterator",0},
    36                               {testListFree,"627-testListFree",0},
    37                               {testListSort,"624-testListSort",0},
     30                              {testListAlloc,487,"psListAlloc",0,false},
     31                              {testListAdd,488,"psListAdd",0,false},
     32                              {testListGet,489,"psListGet",0,false},
     33                              {testListRemove,490,"psListRemove",0,false},
     34                              {testListConvert,491,"psListConvert",0,false},
     35                              {testListIterator,494,"psListIterator",0,false},
     36                              {testListFree,627,"psListFree",0,false},
     37                              {testListSort,624,"psListSort",0,false},
    3838                              {NULL}
    3939                          };
    4040
    41 int main()
     41int main(int argc, char* argv[])
    4242{
    4343    psLogSetLevel(PS_LOG_INFO);
    4444
    45     if (! runTestSuite(stderr,"psList",tests)) {
     45    if (! runTestSuite(stderr,"psList",tests,argc,argv) ) {
    4646        psError(__FILE__,"One or more tests failed");
    4747        return 1;
     
    138138
    139139    //  1. list is NULL (error)
    140     list = psListAdd(NULL,data,PS_LIST_HEAD);
    141 
    142     if (list != NULL) {
    143         psError(__func__,"psListAdd was given a NULL list, but returned a non-NULL list.");
    144         return 1;
    145     }
    146 
    147     //  2. data is NULL (error, list should not grow)
     140    if (psListAdd(NULL,data,PS_LIST_HEAD)) {
     141        psError(__func__,"psListAdd was given a NULL list, but returned a true/success.");
     142        return 1;
     143    }
     144
    148145    list = psListAlloc(data);
    149146    psFree(data);
     
    153150    }
    154151
    155     list = psListAdd(list, NULL,PS_LIST_HEAD);
    156 
    157     if (list->size != 1) {
    158         psError(__func__,"psListAdd with a NULL data element changed the list size.");
     152    //  2. data is NULL (error, list should not grow)
     153    if (psListAdd(list, NULL,PS_LIST_HEAD)) {
     154        psError(__func__,"psListAdd successfully added a NULL data item?");
     155        return 40;
     156    }
     157    if ( list->size != 1) {
     158        psError(__func__,"psListAdd with a NULL data element changed the list size or returned success.");
    159159        return 3;
    160160    }
     
    163163    data = psAlloc(sizeof(int));
    164164    *data = 2;
    165     list = psListAdd(list,data,PS_LIST_HEAD);
     165    if ( ! psListAdd(list,data,PS_LIST_HEAD) ) {
     166        psError(__func__,"psListAdd failed to add a data item to head.");
     167        return 21;
     168    }
     169
    166170    if (psMemGetRefCounter(data) != 2) {
    167171        psError(__func__,"psListAdd didn't increment the data reference count.");
     
    169173    }
    170174    psFree(data);
     175
    171176    // verify that the size incremented
    172177    if (list->size != 2) {
     
    183188    data = psAlloc(sizeof(int));
    184189    *data = 3;
    185     list = psListAdd(list,data,PS_LIST_TAIL);
     190    if ( ! psListAdd(list,data,PS_LIST_TAIL) ) {
     191        psError(__func__,"psListAdd failed to add a data item to tail.");
     192        return 21;
     193    }
     194
    186195    if (psMemGetRefCounter(data) != 2) {
    187196        psError(__func__,"psListAdd didn't increment the data reference count.");
    188         return 20;
     197        return 22;
    189198    }
    190199    psFree(data);
     
    211220    data = psAlloc(sizeof(int));
    212221    *data = 4;
    213     psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location");
    214     list = psListAdd(list,data,-10);
    215     if (psMemGetRefCounter(data) != 2) {
    216         psError(__func__,"psListAdd didn't increment the data reference count.");
    217         return 20;
    218     }
    219     psFree(data);
    220     // verify that the size incremented
    221     if (list->size != 4 || *(int*)list->head->data != 4) {
     222    psLogMsg(__func__,PS_LOG_INFO,"Following should error with invalid insert location");
     223
     224    if ( psListAdd(list,data,-10) ) {
     225        psError(__func__,"psListAdd successfully added data to a -10 position?");
     226        return 30;
     227    }
     228    if (psMemGetRefCounter(data) != 1) {
     229        psError(__func__,"psListAdd incremented the data reference count.");
     230        return 24;
     231    }
     232    psFree(data);
     233    // verify that the size wasn't incremented
     234    if (list->size != 3) {
    222235        printListInt(list);
    223236        psError(__func__,"psListAdd didn't insert to head when where was invalid.");
     
    228241    data = psAlloc(sizeof(int));
    229242    *data = 5;
    230     list = psListAdd(list,data,1);
     243
     244    if ( ! psListAdd(list,data,1) ) {
     245        psError(__func__,"psListAdd failed to add data to 1 position.");
     246        return 30;
     247    }
     248
    231249    if (psMemGetRefCounter(data) != 2) {
    232250        psError(__func__,"psListAdd didn't increment the data reference count.");
    233         return 20;
     251        return 25;
    234252    }
    235253    psFree(data);
    236254    // verify that the size incremented
    237     if (list->size != 5 || *(int*)list->head->next->data != 5) {
     255    if (list->size != 4 || *(int*)list->head->next->data != 5) {
    238256        printListInt(list);
    239257        psError(__func__,"psListAdd didn't insert to position #1.");
    240         return 9;
     258        return 10;
    241259    }
    242260
    243261    data = psAlloc(sizeof(int));
    244262    *data = 6;
    245     list = psListAdd(list,data,4);
     263    if ( ! psListAdd(list,data,3) ) {
     264        psError(__func__,"psListAdd failed to add data to 4 position.");
     265        return 31;
     266    }
    246267    if (psMemGetRefCounter(data) != 2) {
    247268        psError(__func__,"psListAdd didn't increment the data reference count.");
    248         return 20;
     269        return 26;
    249270    }
    250271    psFree(data);
    251272    // verify that the size incremented
    252     if (list->size != 6  || *(int *)list->head->next->next->next->next->data != 6) {
     273    if (list->size != 5  || *(int *)list->head->next->next->next->data != 6) {
    253274        printListInt(list);
    254275        psError(__func__,"psListAdd didn't insert to position #4.");
    255         return 9;
     276        return 50;
    256277    }
    257278
    258279    data = psAlloc(sizeof(int));
    259280    *data = 7;
    260     list = psListAdd(list,data,2);
     281    if ( ! psListAdd(list,data,2) ) {
     282        psError(__func__,"psListAdd failed to add data to 2 position.");
     283        return 32;
     284    }
    261285    if (psMemGetRefCounter(data) != 2) {
    262286        psError(__func__,"psListAdd didn't increment the data reference count.");
    263         return 20;
     287        return 28;
    264288    }
    265289    psFree(data);
    266290    // verify that the size incremented
    267     if (list->size != 7  || *(int *)list->head->next->next->data != 7) {
     291    if (list->size != 6  || *(int *)list->head->next->next->data != 7) {
    268292        printListInt(list);
    269293        psError(__func__,"psListAdd didn't insert to position #2.");
    270         return 9;
     294        return 11;
    271295    }
    272296
     
    274298    *data = 7;
    275299    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
    276     list = psListAdd(list,data,9);
     300
     301    if ( ! psListAdd(list,data,9) ) {
     302        psError(__func__,"psListAdd failed to add data to a 9 position?");
     303        return 30;
     304    }
     305
    277306    if (psMemGetRefCounter(data) != 2) {
    278307        psError(__func__,"psListAdd didn't increment the data reference count.");
    279         return 20;
    280     }
    281     psFree(data);
     308        return 29;
     309    }
     310
     311    psFree(data);
     312
    282313    // verify that the size incremented
    283     if (list->size != 8) {
     314    if (list->size != 7) {
    284315        printListInt(list);
    285316        psError(__func__,"psListAdd didn't insert to position #9.");
    286         return 9;
     317        return 12;
    287318    }
    288319
     
    347378    data = psAlloc(sizeof(int));
    348379    *data = 1;
    349     list = psListAdd(list,data,PS_LIST_TAIL);
     380    psListAdd(list,data,PS_LIST_TAIL);
    350381    psFree(data);
    351382
    352383    data = psAlloc(sizeof(int));
    353384    *data = 2;
    354     list = psListAdd(list,data,PS_LIST_TAIL);
     385    psListAdd(list,data,PS_LIST_TAIL);
    355386    psFree(data);
    356387
    357388    data = psAlloc(sizeof(int));
    358389    *data = 3;
    359     list = psListAdd(list,data,PS_LIST_TAIL);
     390    psListAdd(list,data,PS_LIST_TAIL);
    360391    psFree(data);
    361392
     
    452483        data = psAlloc(sizeof(int));
    453484        *data = lcv;
    454         list = psListAdd(list,data,PS_LIST_TAIL);
     485        psListAdd(list,data,PS_LIST_TAIL);
    455486        psMemDecrRefCounter(data);
    456487    }
     
    671702        data = psAlloc(sizeof(int));
    672703        *data = lcv;
    673         list = psListAdd(list,data,PS_LIST_TAIL);
     704        psListAdd(list,data,PS_LIST_TAIL);
    674705        psMemDecrRefCounter(data);
    675706    }
     
    809840        data = psAlloc(sizeof(int));
    810841        *data = lcv;
    811         list = psListAdd(list,data,PS_LIST_TAIL);
     842        psListAdd(list,data,PS_LIST_TAIL);
    812843        psFree(data);
    813844    }
     
    926957        data[lcv] = psAlloc(sizeof(int));
    927958        *data[lcv] = lcv;
    928         list = psListAdd(list,data[lcv],PS_LIST_TAIL);
     959        psListAdd(list,data[lcv],PS_LIST_TAIL);
    929960        if (psMemGetRefCounter(data[lcv]) != 2) {
    930961            psError(__func__,"Reference counter for data was not incremented");
     
    9801011            *data = lcv*2-12;
    9811012        }
    982         list = psListAdd(list,data,PS_LIST_TAIL);
     1013        psListAdd(list,data,PS_LIST_TAIL);
    9831014        psFree(data);
    9841015
     
    10461077            *data = lcv*2-12;
    10471078        }
    1048         list = psListAdd(list,data,PS_LIST_TAIL);
     1079        psListAdd(list,data,PS_LIST_TAIL);
    10491080        psFree(data);
    10501081
  • trunk/psLib/test/dataManip/builddir/tst_psImageFFT.d

    r1109 r1193  
    33  ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
    44  ../../include/psString.h ../../include/psType.h ../../include/psList.h \
    5   ../../include/psVector.h ../../include/psHash.h \
    6   ../../include/psScalar.h ../../include/psImage.h \
     5  ../../include/psCompare.h ../../include/psVector.h \
     6  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
    77  ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
    88  ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
  • trunk/psLib/test/dataManip/builddir/tst_psImageIO.d

    r1109 r1193  
    33  ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
    44  ../../include/psString.h ../../include/psType.h ../../include/psList.h \
    5   ../../include/psVector.h ../../include/psHash.h \
    6   ../../include/psScalar.h ../../include/psImage.h \
     5  ../../include/psCompare.h ../../include/psVector.h \
     6  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
    77  ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
    88  ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
  • trunk/psLib/test/dataManip/builddir/tst_psVectorFFT.d

    r1109 r1193  
    33  ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
    44  ../../include/psString.h ../../include/psType.h ../../include/psList.h \
    5   ../../include/psVector.h ../../include/psHash.h \
    6   ../../include/psScalar.h ../../include/psImage.h \
     5  ../../include/psCompare.h ../../include/psVector.h \
     6  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
    77  ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
    88  ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
  • trunk/psLib/test/dataManip/tst_psVectorFFT.c

    r1073 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:17 $
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434
    3535testDescription tests[] = {
    36                               {testVectorFFT,"600-testVectorFFT",0},
    37                               {testVectorRealImaginary,"601-testVectorRealImaginary",0},
    38                               {testVectorComplex,"602-testVectorComplex",0},
    39                               {testVectorConjugate,"603-testVectorConjugate",0},
    40                               {testVectorPowerSpectrum,"604-testVectorPowerSpectrum",0},
     36                              {testVectorFFT,600,"psVectorFFT",0,false},
     37                              {testVectorRealImaginary,601,"psVectorRealImaginary",0,false},
     38                              {testVectorComplex,602,"psVectorComplex",0,false},
     39                              {testVectorConjugate,603,"psVectorConjugate",0,false},
     40                              {testVectorPowerSpectrum,604,"psVectorPowerSpectrum",0,false},
    4141                              {NULL}
    4242                          };
    4343
    44 int main()
     44int main(int argc, char* argv[])
    4545{
    4646    psLogSetLevel(PS_LOG_INFO);
    4747
    48     if (! runTestSuite(stderr,"psFFT",tests)) {
     48    if (! runTestSuite(stderr,"psFFT",tests,argc,argv) ) {
    4949        psAbort(__FILE__,"One or more tests failed");
    5050    }
  • trunk/psLib/test/image/tst_psImage.c

    r1073 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:15 $
     8 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2929
    3030testDescription tests[] = {
    31                               {testImageAlloc,"546/548-testImageAlloc/Free",0},
    32                               {testImageSubset,"547/550-testImageSubset",0},
    33                               {testImageCopy,"551-testImageCopy",0},
    34                               {testImageClip,"571-testImageClip",0},
    35                               {testImageClipNAN,"572-testImageClipNAN",0},
    36                               {testImageOverlay,"573-testImageOverlay",0},
     31                              {testImageAlloc,546,"psImageAlloc",0,false},
     32                              {testImageAlloc,548,"psImageFree",0,true},
     33                              {testImageSubset,547,"psImageSubset",0,false},
     34                              {testImageSubset,550,"psImageSubset",0,true},
     35                              {testImageCopy,551,"psImageCopy",0,false},
     36                              {testImageClip,571,"psImageClip",0,false},
     37                              {testImageClipNAN,572,"psImageClipNAN",0,false},
     38                              {testImageOverlay,573,"psImageOverlay",0,false},
    3739                              {NULL}
    3840                          };
    3941
    40 int main()
     42int main(int argc, char* argv[])
    4143{
    4244    psLogSetLevel(PS_LOG_INFO);
    43     testImageOverlay();
    44     if (! runTestSuite(stderr,"psImage",tests)) {
     45
     46    if (! runTestSuite(stderr,"psImage",tests,argc,argv)) {
    4547        psError(__FILE__,"One or more tests failed");
    4648        return 1;
     
    572574
    573575    #define testImageCopyTypes(IN) \
     576    printf("to psF32\n"); \
     577    testImageCopyType(IN,F32);\
     578    printf("to psF64\n"); \
     579    testImageCopyType(IN,F64); \
     580    printf("to psU8\n"); \
    574581    testImageCopyType(IN,U8); \
     582    printf("to psU16\n"); \
    575583    testImageCopyType(IN,U16); \
     584    printf("to psU32\n"); \
    576585    testImageCopyType(IN,U32); \
     586    printf("to psS8\n"); \
    577587    testImageCopyType(IN,S8);\
     588    printf("to psS16\n"); \
    578589    testImageCopyType(IN,S16);\
    579     testImageCopyType(IN,S32);\
    580     testImageCopyType(IN,F32);\
    581     testImageCopyType(IN,F64);
    582 
     590    printf("to psS32\n"); \
     591    testImageCopyType(IN,S32);
     592
     593    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU8");
    583594    testImageCopyTypes(U8);
     595    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU16");
    584596    testImageCopyTypes(U16);
     597    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU32");
    585598    testImageCopyTypes(U32);
     599    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS8");
    586600    testImageCopyTypes(S8);
     601    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS16");
    587602    testImageCopyTypes(S16);
     603    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS32");
    588604    testImageCopyTypes(S32);
     605    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF32");
    589606    testImageCopyTypes(F32);
     607    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF64");
    590608    testImageCopyTypes(F64);
    591609
  • trunk/psLib/test/image/tst_psImageFFT.c

    r1073 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:17 $
     8 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434
    3535testDescription tests[] = {
    36                               {testImageFFT,"600-testImageFFT",0},
    37                               {testImageRealImaginary,"601-testImageRealImaginary",0},
    38                               {testImageComplex,"602-testImageComplex",0},
    39                               {testImageConjugate,"603-testImageConjugate",0},
    40                               {testImagePowerSpectrum,"604-testImagePowerSpectrum",0},
     36                              {testImageFFT,600,"psImageFFT",0,false},
     37                              {testImageRealImaginary,601,"psImageRealImaginary",0,false},
     38                              {testImageComplex,602,"psImageComplex",0,false},
     39                              {testImageConjugate,603,"psImageConjugate",0,false},
     40                              {testImagePowerSpectrum,604,"psImagePowerSpectrum",0,false},
    4141                              {NULL}
    4242                          };
    4343
    44 int main()
     44int main(int argc, char* argv[])
    4545{
    4646    psLogSetLevel(PS_LOG_INFO);
    4747
    48     if (! runTestSuite(stderr,"psFFT",tests)) {
     48    if (! runTestSuite(stderr,"psFFT",tests,argc,argv) ) {
    4949        psAbort(__FILE__,"One or more tests failed");
    5050    }
  • trunk/psLib/test/image/tst_psImageIO.c

    r1073 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:17 $
     8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535
    3636testDescription tests[] = {
    37                               {testImageRead,"567-testImageRead",0},
    38                               {testImageWrite,"569-testImageWrite",0},
     37                              {testImageRead,567,"psImageReadSection",0,false},
     38                              {testImageWrite,569,"psImageWriteSection",0,false},
    3939                              {NULL}
    4040                          };
    4141
    42 int main()
     42int main(int argc, char* argv[])
    4343{
    4444    psLogSetLevel(PS_LOG_INFO);
    4545
    46     testImageRead();
    47 
    48     if (! runTestSuite(stderr,"psImage",tests)) {
     46    if (! runTestSuite(stderr,"psImage",tests,argc,argv)) {
    4947        psAbort(__FILE__,"One or more tests failed");
    5048    }
  • trunk/psLib/test/psTest.c

    r1034 r1193  
    1515#include <unistd.h>
    1616#include <sys/wait.h>
     17#include <stdbool.h>
     18#include <string.h>
    1719
    1820#include "psTest.h"
     
    2527#define HEADER_BOTTOM "\\**********************************************************************************/\n\n"
    2628
    27 bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[])
     29bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName,
     30                    testDescription tests[], int argc, char * const argv[])
    2831{
    2932    bool success = true;
    30 
    31     for (int index=0; tests[index].fcn != NULL; index++) {
    32         success = p_runTest(fp,testPointFile,packageName,tests[index].testPointName,
    33                             tests[index].fcn,tests[index].expectedReturn) && success;
     33    bool runAll = true;
     34    bool useFork = true;
     35    bool found;
     36    int c;
     37    int n;
     38    extern char *optarg;
     39
     40    if (argc > 0) {
     41        while ( (c=getopt(argc,argv,"lhn:dt:")) != -1) {
     42            switch (c) {
     43            case 'h':
     44                printf("Usage: %s [-l] [-d] [-h] [-n=Testpoint#] [-t=TestpointName]\n"
     45                       "    where:\n"
     46                       "           -l  : lists the testpoints contained in this test driver executable\n"
     47                       "           -d  : turns on debugger-friendly mode (no forking, aborts/signals are not handled)\n"
     48                       "           -h  : prints this help\n"
     49                       "           -n  : specifies a particular testpoint by number to run\n"
     50                       "           -t  : specifies a particular testpoint by name to run\n"
     51                       "    (if no -l, -n or -t options are given, all testpoints are run)\n",
     52                       argv[0]);
     53                runAll = false;
     54                break;
     55            case 'd':
     56                useFork = false;
     57                break;
     58            case 'l':
     59                printf("Test Driver:  %s\n",testPointFile);
     60                printf("Package Name: %s\n",packageName);
     61                printf("Testpoints:\n");
     62                runAll = false;
     63                for (int index=0; tests[index].fcn != NULL; index++) {
     64                    printf("    %6d - %s \n",tests[index].testPointNumber,
     65                           tests[index].testPointName);
     66                }
     67                printf("\n");
     68                break;
     69            case 't':
     70                runAll = false;
     71                for (int index=0; tests[index].fcn != NULL; index++) {
     72                    if (strcmp(optarg,tests[index].testPointName) == 0) {
     73                        success = p_runTest(fp,
     74                                            testPointFile,
     75                                            packageName,
     76                                            tests[index].testPointName,
     77                                            tests[index].fcn,
     78                                            tests[index].expectedReturn,
     79                                            useFork) && success;
     80                    }
     81                }
     82                break;
     83            case 'n':
     84                runAll = false;
     85                if (sscanf(optarg,"%i",&n) != 1) {
     86                    psError(__func__,"Failed to parse the testpoint number (%s).",
     87                            optarg);
     88                    break;
     89                }
     90                found = false;
     91                for (int index=0; tests[index].fcn != NULL; index++) {
     92                    if (n==tests[index].testPointNumber) {
     93                        found = true;
     94                        success = p_runTest(fp,
     95                                            testPointFile,
     96                                            packageName,
     97                                            tests[index].testPointName,
     98                                            tests[index].fcn,
     99                                            tests[index].expectedReturn,
     100                                            useFork) && success;
     101                    }
     102                }
     103                if (! found) {
     104                    psError(__func__,"The specified testpoint number (%d) doesn't exist in this test driver.",
     105                            n);
     106                    break;
     107                }
     108                break;
     109            case '?':
     110                psError(__func__,"Option %s is not recognized and is ignored.",optarg);
     111                break;
     112            }
     113        }
     114    }
     115
     116    if (runAll) {
     117        for (int index=0; tests[index].fcn != NULL; index++) {
     118            if (! tests[index].isDuplicateEntry) {
     119                success = p_runTest(fp,
     120                                    testPointFile,
     121                                    packageName,
     122                                    tests[index].testPointName,
     123                                    tests[index].fcn,
     124                                    tests[index].expectedReturn,
     125                                    useFork) && success;
     126            }
     127        }
    34128    }
    35129    return success;
     
    37131
    38132bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
    39                testFcn fcn, int expectedReturn)
     133               testFcn fcn, int expectedReturn, bool useFork)
    40134{
    41135    int childReturn = 0;
     
    44138    p_printPositiveTestHeader(fp,testPointFile,packageName,testPointName);
    45139
    46     child = fork();
    47     if (child == 0) {                   // I am the child process, run the test
     140    if (useFork) {
     141        child = fork();
     142        if (child == 0) {                   // I am the child process, run the test
     143            int currentId = psMemGetId();
     144            int retVal = fcn();
     145            if (retVal == 0) { // only bother checking memory if test executed to end.
     146                if (psMemCheckLeaks(currentId,NULL,stderr) != 0) {
     147                    psError(__func__,"Memory Leaks Detected");
     148                    retVal = 64;
     149                }
     150                psMemCheckCorruption(1);
     151            }
     152            exit(retVal);
     153        } else if (child < 0) {
     154            fprintf(fp,"Couldn't fork a process to run a negative test (%s|%s)",
     155                    packageName, testPointName);
     156            abort();
     157        }
     158
     159        waitpid(child,&childReturn,0);
     160        if (WIFSIGNALED(childReturn)) {
     161            childReturn =  -WTERMSIG(childReturn);
     162        } else {
     163            childReturn = WEXITSTATUS(childReturn);
     164        }
     165    } else {
    48166        int currentId = psMemGetId();
    49         int retVal = fcn();
    50         if (retVal == 0) { // only bother checking memory if test executed to end.
     167        childReturn = fcn();
     168        if (childReturn == 0) { // only bother checking memory if test executed to end.
    51169            if (psMemCheckLeaks(currentId,NULL,stderr) != 0) {
    52170                psError(__func__,"Memory Leaks Detected");
    53                 retVal = 64;
     171                childReturn = 64;
    54172            }
    55173            psMemCheckCorruption(1);
    56174        }
    57         exit(retVal);
    58     } else if (child < 0) {
    59         fprintf(fp,"Couldn't fork a process to run a negative test (%s|%s)",
    60                 packageName, testPointName);
    61         abort();
    62     }
    63 
    64     waitpid(child,&childReturn,0);
    65     if (WIFSIGNALED(childReturn)) {
    66         childReturn =  -WTERMSIG(childReturn);
    67     } else {
    68         childReturn = WEXITSTATUS(childReturn);
    69     }
     175    }
     176
    70177
    71178    if (childReturn != expectedReturn) {
  • trunk/psLib/test/psTest.h

    r637 r1193  
    2020{
    2121    testFcn     fcn;
     22    int         testPointNumber;
    2223    const char* testPointName;
    2324    int         expectedReturn;
     25    bool        isDuplicateEntry;
    2426}
    2527testDescription;
    2628
    27 #define runTest(filePtr, packageName, testPointName, fcn, expectedReturn) \
    28 p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn)
     29#define runTest(filePtr, packageName, testPointName, fcn, expectedReturn, useFork) \
     30p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn, useFork)
    2931
    30 #define runTestSuite(filePtr, packageName, tests) \
    31 p_runTestSuite(filePtr, __FILE__, packageName, tests)
     32#define runTestSuite(filePtr, packageName, tests, argc, argv) \
     33p_runTestSuite(filePtr, __FILE__, packageName, tests, argc, argv)
    3234
    3335
    3436/////////////////////////// PRIVATE FUNCTIONS //////////////////////////////
    3537
    36 bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
    37                testFcn fcn, int expectedReturn);
     38bool p_runTest(
     39    FILE *fp,
     40    const char* testPointFile,
     41    const char* packageName,
     42    const char* testPointName,
     43    testFcn fcn,
     44    int expectedReturn,
     45    bool useFork
     46);
    3847
    39 bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[]);
     48bool p_runTestSuite(
     49    FILE *fp,
     50    const char* testPointFile,
     51    const char* packageName,
     52    testDescription tests[],
     53    int argc,
     54    char * const argv[]
     55);
    4056
    41 void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName,
    42                                const char* testPointName);
     57void p_printPositiveTestHeader(
     58    FILE *fp,
     59    const char* testPointFile,
     60    const char* packageName,
     61    const char* testPointName
     62);
    4363
    44 void p_printNegativeTestHeader(FILE *fp, const char* testPointFile, const char* packageName,
    45                                const char* testPointName,const char* expectedError, int exitValue);
     64void p_printNegativeTestHeader(
     65    FILE *fp,
     66    const char* testPointFile,
     67    const char* packageName,
     68    const char* testPointName,
     69    const char* expectedError,
     70    int exitValue
     71);
    4672
    47 void p_printFooter(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
    48                    bool success);
     73void p_printFooter(
     74    FILE *fp,
     75    const char* testPointFile,
     76    const char* packageName,
     77    const char* testPointName,
     78    bool success
     79);
    4980
    5081#endif
  • trunk/psLib/test/sysUtils/builddir/tst_psMemory.d

    r1109 r1193  
    33  ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
    44  ../../include/psString.h ../../include/psType.h ../../include/psList.h \
    5   ../../include/psVector.h ../../include/psHash.h \
    6   ../../include/psScalar.h ../../include/psImage.h \
     5  ../../include/psCompare.h ../../include/psVector.h \
     6  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
    77  ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
    88  ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
  • trunk/psLib/test/sysUtils/tst_psMemory.c

    r1097 r1193  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-25 21:51:46 $
     8 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-08 01:05:01 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4545
    4646testDescription tests[] = {
    47                               {TPCheckBufferPositive,"449-TPCheckBufferPositive",0},
    48                               {TPOutOfMemory,"450-TPOutOfMemory",-6},
    49                               {TPReallocOutOfMemory,"562-TPReallocOutOfMemory",-6},
    50                               {TPrealloc,"451-TPrealloc",0},
    51                               {TPallocCallback,"452/453-TPallocCallback",0},
    52                               {TPcheckLeaks,"454-TPcheckLeaks",0},
    53                               {TPmemCorruption,"455-TPmemCorruption",0},
    54                               {TPFreeReferencedMemory,"456-TPFreeReferencedMemory",0},
     47                              {TPCheckBufferPositive,449,"checkBufferPositive",0,false},
     48                              {TPOutOfMemory,450,"outOfMemory",-6,false},
     49                              {TPReallocOutOfMemory,562,"reallocOutOfMemory",-6,false},
     50                              {TPrealloc,451,"psRealloc",0,false},
     51                              {TPallocCallback,452,"allocCallback",0,false},
     52                              {TPallocCallback,453,"allocCallback2",0,true},
     53                              {TPcheckLeaks,454,"checkLeaks",0,false},
     54                              {TPmemCorruption,455,"psMemCorruption",0,false},
     55                              {TPFreeReferencedMemory,456,"freeReferencedMemory",0,false},
    5556                              {NULL}
    5657                          };
    5758
    58 int main()
     59int main(int argc, char* argv[])
    5960{
    6061    psLogSetLevel(PS_LOG_INFO);
    6162
    62     if (! runTestSuite(stderr,"psMemory",tests)) {
     63    if (! runTestSuite(stderr,"psMemory",tests,argc,argv) ) {
    6364        psError(__FILE__,"One or more tests failed");
    6465        return 1;
Note: See TracChangeset for help on using the changeset viewer.