IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 12:34:06 PM (22 years ago)
Author:
desonia
Message:

astyle fixed?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/psTest.c

    r1365 r1406  
    3737    int n;
    3838    extern char *optarg;
    39    
     39
    4040    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        
     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
    116116    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                 }
    128         }
    129        
     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        }
     128    }
     129
    130130    if ( ! success ) {
    131             psError( testPointFile, "One or more tests failed" );
    132         }
    133        
     131        psError( testPointFile, "One or more tests failed" );
     132    }
     133
    134134    return success;
    135135}
     
    140140    int childReturn = 0;
    141141    pid_t child;
    142    
     142
    143143    p_printPositiveTestHeader( fp, testPointFile, packageName, testPointName );
    144    
     144
    145145    if ( useFork ) {
    146             child = fork();
    147             if ( child == 0 ) {                   // I am the child process, run the test
    148                     int currentId = psMemGetId();
    149                     int retVal = fcn();
    150                     if ( retVal == 0 ) { // only bother checking memory if test executed to end.
    151                             if ( psMemCheckLeaks( currentId, NULL, stderr ) != 0 ) {
    152                                     psError( __func__, "Memory Leaks Detected" );
    153                                     retVal = 64;
    154                                 }
    155                             psMemCheckCorruption( 1 );
    156                         }
    157                     exit( retVal );
    158                 } else if ( child < 0 ) {
    159                     fprintf( fp, "Couldn't fork a process to run a negative test (%s|%s)",
    160                              packageName, testPointName );
    161                     abort();
    162                 }
    163                
    164             waitpid( child, &childReturn, 0 );
    165             if ( WIFSIGNALED( childReturn ) ) {
    166                     childReturn = -WTERMSIG( childReturn );
    167                 } else {
    168                     childReturn = WEXITSTATUS( childReturn );
    169                 }
     146        child = fork();
     147        if ( child == 0 ) {                   // I am the child process, run the test
     148            int currentId = psMemGetId();
     149            int retVal = fcn();
     150            if ( retVal == 0 ) { // only bother checking memory if test executed to end.
     151                if ( psMemCheckLeaks( currentId, NULL, stderr ) != 0 ) {
     152                    psError( __func__, "Memory Leaks Detected" );
     153                    retVal = 64;
     154                }
     155                psMemCheckCorruption( 1 );
     156            }
     157            exit( retVal );
     158        } else
     159            if ( child < 0 ) {
     160                fprintf( fp, "Couldn't fork a process to run a negative test (%s|%s)",
     161                         packageName, testPointName );
     162                abort();
     163            }
     164
     165        waitpid( child, &childReturn, 0 );
     166        if ( WIFSIGNALED( childReturn ) ) {
     167            childReturn = -WTERMSIG( childReturn );
    170168        } else {
    171             int currentId = psMemGetId();
    172             childReturn = fcn();
    173             if ( childReturn == 0 ) { // only bother checking memory if test executed to end.
    174                     if ( psMemCheckLeaks( currentId, NULL, stderr ) != 0 ) {
    175                             psError( __func__, "Memory Leaks Detected" );
    176                             childReturn = 64;
    177                         }
    178                     psMemCheckCorruption( 1 );
    179                 }
    180         }
    181        
    182        
     169            childReturn = WEXITSTATUS( childReturn );
     170        }
     171    } else {
     172        int currentId = psMemGetId();
     173        childReturn = fcn();
     174        if ( childReturn == 0 ) { // only bother checking memory if test executed to end.
     175            if ( psMemCheckLeaks( currentId, NULL, stderr ) != 0 ) {
     176                psError( __func__, "Memory Leaks Detected" );
     177                childReturn = 64;
     178            }
     179            psMemCheckCorruption( 1 );
     180        }
     181    }
     182
     183
    183184    if ( childReturn != expectedReturn ) {
    184             fprintf( fp, "Return value mismatch: expected %d, got %d",
    185                      expectedReturn, childReturn );
    186         }
    187        
     185        fprintf( fp, "Return value mismatch: expected %d, got %d",
     186                 expectedReturn, childReturn );
     187    }
     188
    188189    p_printFooter( fp, testPointFile, packageName, testPointName,
    189190                   ( childReturn == expectedReturn ) );
    190                    
     191
    191192    return ( childReturn == expectedReturn );
    192193}
     
    198199{
    199200    char TP[ 80 ];
    200    
     201
    201202    snprintf( TP, 80, "%s{%s}", packageName, testPointName );
    202    
     203
    203204    fprintf( fp, HEADER_TOP );
    204205    fprintf( fp, HEADER_LINE_STRING, "TestFile", testPointFile );
     
    216217{
    217218    char TP[ 80 ];
    218    
     219
    219220    snprintf( TP, 80, "%s{%s}", packageName, testPointName );
    220    
     221
    221222    fprintf( fp, HEADER_TOP );
    222223    fprintf( fp, HEADER_LINE_STRING, "TestFile", testPointFile );
     
    236237{
    237238    if ( success ) {
    238             fprintf( fp, "\n---> TESTPOINT PASSED (%s{%s} | %s)\n\n", packageName, testPointName, testPointFile );
    239         } else {
    240             fprintf( fp, "\n---> TESTPOINT FAILED (%s{%s} | %s)\n\n", packageName, testPointName, testPointFile );
    241         }
    242 }
     239        fprintf( fp, "\n---> TESTPOINT PASSED (%s{%s} | %s)\n\n", packageName, testPointName, testPointFile );
     240    } else {
     241        fprintf( fp, "\n---> TESTPOINT FAILED (%s{%s} | %s)\n\n", packageName, testPointName, testPointFile );
     242    }
     243}
Note: See TracChangeset for help on using the changeset viewer.