Changeset 1406 for trunk/psLib/test/psTest.c
- Timestamp:
- Aug 6, 2004, 12:34:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/psTest.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/psTest.c
r1365 r1406 37 37 int n; 38 38 extern char *optarg; 39 39 40 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 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 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 }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 130 130 if ( ! success ) { 131 psError( testPointFile, "One or more tests failed" );132 }133 131 psError( testPointFile, "One or more tests failed" ); 132 } 133 134 134 return success; 135 135 } … … 140 140 int childReturn = 0; 141 141 pid_t child; 142 142 143 143 p_printPositiveTestHeader( fp, testPointFile, packageName, testPointName ); 144 144 145 145 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 ); 170 168 } 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 183 184 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 188 189 p_printFooter( fp, testPointFile, packageName, testPointName, 189 190 ( childReturn == expectedReturn ) ); 190 191 191 192 return ( childReturn == expectedReturn ); 192 193 } … … 198 199 { 199 200 char TP[ 80 ]; 200 201 201 202 snprintf( TP, 80, "%s{%s}", packageName, testPointName ); 202 203 203 204 fprintf( fp, HEADER_TOP ); 204 205 fprintf( fp, HEADER_LINE_STRING, "TestFile", testPointFile ); … … 216 217 { 217 218 char TP[ 80 ]; 218 219 219 220 snprintf( TP, 80, "%s{%s}", packageName, testPointName ); 220 221 221 222 fprintf( fp, HEADER_TOP ); 222 223 fprintf( fp, HEADER_LINE_STRING, "TestFile", testPointFile ); … … 236 237 { 237 238 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.
