Changeset 1193 for trunk/psLib/test/psTest.c
- Timestamp:
- Jul 7, 2004, 3:05:01 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/psTest.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/psTest.c
r1034 r1193 15 15 #include <unistd.h> 16 16 #include <sys/wait.h> 17 #include <stdbool.h> 18 #include <string.h> 17 19 18 20 #include "psTest.h" … … 25 27 #define HEADER_BOTTOM "\\**********************************************************************************/\n\n" 26 28 27 bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[]) 29 bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, 30 testDescription tests[], int argc, char * const argv[]) 28 31 { 29 32 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 } 34 128 } 35 129 return success; … … 37 131 38 132 bool 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) 40 134 { 41 135 int childReturn = 0; … … 44 138 p_printPositiveTestHeader(fp,testPointFile,packageName,testPointName); 45 139 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 { 48 166 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. 51 169 if (psMemCheckLeaks(currentId,NULL,stderr) != 0) { 52 170 psError(__func__,"Memory Leaks Detected"); 53 retVal= 64;171 childReturn = 64; 54 172 } 55 173 psMemCheckCorruption(1); 56 174 } 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 70 177 71 178 if (childReturn != expectedReturn) {
Note:
See TracChangeset
for help on using the changeset viewer.
