Mercurial > projects > dstress
annotate dstress.c @ 971:8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
* fixed parallel build of test cases with multiple object files
author | thomask |
---|---|
date | Thu, 20 Apr 2006 08:50:01 +0000 |
parents | 8b6d2dcf9954 |
children | 1aba99b7f01c |
rev | line source |
---|---|
438 | 1 /* |
2 * core test tool for the DStress test suite | |
251 | 3 * http://dstress.kuehne.cn |
4 * | |
940 | 5 * Copyright (C) |
6 * 2005, 2006 Thomas Kuehne <thomas@kuehne.cn> | |
7 * 2005 Carlos Santander (Window files) | |
8 * 2005 Stewart Gordon <smjg_1998@yahoo.com> (Window crashRun) | |
251 | 9 * |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 * $HeadURL$ | |
25 * $Date$ | |
26 * $Author$ | |
27 * | |
438 | 28 */ |
251 | 29 |
704 | 30 /* Beware: the code doesn't care about freeing allocated memory etc. ... */ |
432 | 31 |
251 | 32 #include <stdlib.h> |
33 #include <stdio.h> | |
34 #include <string.h> | |
35 #include <errno.h> | |
681 | 36 #include <ctype.h> |
251 | 37 |
734 | 38 /* number's choice: XOR and printf :) */ |
39 #define MODE_RUN (0x10000) | |
40 #define MODE_NORUN (0x1000) | |
41 #define MODE_COMPILE (0x100) | |
42 #define MODE_NOCOMPILE (0x10) | |
43 #define MODE_TORTURE (0x2) | |
251 | 44 |
734 | 45 #define RES_BASE_MASK (0xFFFFFF0) |
46 #define RES_PASS (0x1000000) | |
47 #define RES_XFAIL (0x100000) | |
48 #define RES_XPASS (0x10000) | |
49 #define RES_FAIL (0x1000) | |
50 #define RES_ERROR (0x100) | |
51 #define RES_UNTESTED (0x10) | |
52 #define RES_BAD_GDB (0x4) | |
53 #define RES_BAD_MSG (0x2) | |
490 | 54 |
499 | 55 #if defined(__GNU_LIBRARY__) || defined(__GLIBC__) |
697 | 56 #define USE_POSIX 1 |
251 | 57 #endif |
58 | |
685 | 59 #if defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) |
697 | 60 #define USE_POSIX 1 |
251 | 61 #endif |
62 | |
273 | 63 #if defined(__APPLE__) && defined(__MACH__) |
697 | 64 #define USE_POSIX 1 |
273 | 65 #endif |
66 | |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
67 #if defined(WIN) || defined(WIN32) || defined(WIN64) |
633 | 68 #define USE_WINDOWS 1 |
69 #endif | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
70 |
704 | 71 /* prefere USE_POSIX over USE_WINDOWS if both APIs are detected */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
72 #ifdef USE_POSIX |
254 | 73 |
251 | 74 #include <sys/types.h> |
75 #include <sys/stat.h> | |
76 #include <fcntl.h> | |
77 #include <unistd.h> | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
78 #include <regex.h> |
734 | 79 #include <limits.h> |
490 | 80 |
904 | 81 /* not every STDLIB propperly supports C99's "%z" for printf formating */ |
82 /* (I just love those non-conforming headers...) */ | |
83 #undef ZU | |
84 | |
85 #if !defined(ZU) && defined(SSIZE_MAX) | |
86 #if defined(INT_MAX) && SSIZE_MAX == INT_MAX | |
87 #define ZU "%u" | |
88 #elif defined(LONG_MAX) && SSIZE_MAX == LONG_MAX | |
89 #define ZU "%lu" | |
90 #elif defined(LLONG_MAX) && SSIZE_MAX == LLONG_MAX | |
91 #define ZU "%llu" | |
92 #elif defined(SHRT_MAX) && SSIZE_MAX == SHRT_MAX | |
93 #define ZU "%hu" | |
94 #endif | |
95 #endif /* SSIZE_MAX */ | |
96 | |
97 #if !defined(ZU) && defined(SIZE_T_MAX) | |
98 #if defined(UINT_MAX) && SIZE_T_MAX == UINT_MAX | |
734 | 99 #define ZU "%u" |
904 | 100 #elif defined(ULONG_MAX) && SIZE_T_MAX == ULONG_MAX |
734 | 101 #define ZU "%lu" |
904 | 102 #elif defined(ULLONG_MAX) && SIZE_T_MAX == ULLONG_MAX |
103 #define ZU "%llu" | |
104 #elif defined(USHRT_MAX) && SIZE_T_MAX == USHRT_MAX | |
734 | 105 #define ZU "%hu" |
904 | 106 #endif |
107 #endif /* SIZE_T_MAX */ | |
108 | |
109 #ifndef ZU | |
110 #include <stdint.h> | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
111 #undef ZU |
904 | 112 #ifdef PTRDIFF_MAX |
113 #if defined(INT_MAX) && PTRDIFF_MAX == INT_MAX | |
114 #define ZU "%u" | |
115 #elif defined(LONG_MAX) && PTRDIFF_MAX == LONG_MAX | |
116 #define ZU "%lu" | |
117 #elif defined(LLONG_MAX) && PTRDIFF_MAX == LLONG_MAX | |
118 #define ZU "%llu" | |
119 #elif defined(SHRT_MAX) && PTRDIFF_MAX == SHRT_MAX | |
120 #define ZU "%hu" | |
121 #endif | |
122 #endif | |
123 #endif /* PTRDIFF_MAX */ | |
124 | |
125 #ifndef ZU | |
734 | 126 #error what is the size of a pointer? |
127 #endif | |
904 | 128 |
490 | 129 #else |
633 | 130 #ifdef USE_WINDOWS |
490 | 131 |
132 #include <windows.h> | |
685 | 133 #define snprintf _snprintf |
697 | 134 #ifndef INVALID_FILE_SIZE |
704 | 135 #define INVALID_FILE_SIZE (-1) |
742 | 136 #endif |
734 | 137 |
138 /* not every STDLIB supports C99's "%z" for printf formating */ | |
746 | 139 #ifdef WIN32 |
734 | 140 #define ZU "%u" |
141 #else | |
746 | 142 #ifdef WIN64 |
734 | 143 #define ZU "%llu" |
144 #else | |
145 #error what is the size of a pointer? | |
146 #endif | |
147 #endif | |
148 | |
633 | 149 #else |
704 | 150 #error neither POSIX nor MSWindows API detected |
633 | 151 #endif /* USE_WINDOWS else */ |
490 | 152 #endif /* USE_POSIX else */ |
153 | |
734 | 154 #define TORTURE_PREFIX "torture-" |
697 | 155 |
704 | 156 #ifdef USE_POSIX |
968 | 157 #define CRASH_RUN "./crashRun 30 2000" |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
158 #ifdef USE_VALGRIND |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
159 #define VALGRIND "valgrind --leak-check=no -q --suppressions=valgrind.suppress" |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
160 #else |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
161 #define VALGRIND "" |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
162 #endif |
734 | 163 #define TMP_DIR "./obj" |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
164 #define RM_DIR "rm -rf" |
704 | 165 #else |
633 | 166 #ifdef USE_WINDOWS |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
167 #define VALGRIND "" |
734 | 168 #define TMP_DIR ".\\obj" |
633 | 169 #else |
704 | 170 #error OS dependent file names not defined |
633 | 171 #endif |
172 #endif | |
173 | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
174 char* tmp_dir; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
175 |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
176 #ifdef USE_WINDOWS |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
177 HANDLE originalStdout, originalStderr; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
178 #endif |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
179 |
734 | 180 const char* torture[] = { |
181 "", | |
746 | 182 |
734 | 183 "-g", "-inline", "-fPIC", "-O", "-release", |
746 | 184 |
734 | 185 "-g -inline", "-g -fPIC", "-g -O", "-g -release", |
186 "-inline -fPIC", "-inline -O", "-inline -release", | |
187 "-fPIC -O", "-fPIC -release", | |
188 "-O -release", | |
746 | 189 |
734 | 190 "-g -inline -fPIC", "-g -inline -O", "-g -inline -release", |
191 "-g -fPIC -O", "-g -fPIC -release", "-g -O -release", | |
192 "-inline -fPIC -O", "-inline -fPIC -release", "-inline -O -release", | |
193 "-fPIC -O -release", | |
194 | |
195 "-g -inline -fPIC -O", "-g -inline -fPIC -release", | |
196 "-g -fPIC -O -release", | |
197 "-inline -fPIC -O -release", | |
198 | |
199 "-g -inline -fPIC -O -release" | |
200 }; | |
201 | |
202 /* secure malloc */ | |
203 void *xmalloc(size_t size){ | |
204 void *p = malloc(size); | |
205 if (p == NULL){ | |
206 fprintf(stderr, "Failed to allocate " ZU " bytes!\n", size); | |
207 exit(EXIT_FAILURE); | |
208 } | |
209 return p; | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
210 } |
734 | 211 #define malloc xmalloc |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
212 |
734 | 213 /* secure calloc */ |
214 void* xcalloc(size_t members, size_t size){ | |
215 void* ptr = calloc(members, size); | |
216 if(ptr == NULL){ | |
217 fprintf(stderr, "Failed to allocate " ZU " elements" | |
218 "(" ZU " bytes each)!\n", members, size); | |
219 exit(EXIT_FAILURE); | |
220 } | |
221 return ptr; | |
222 } | |
223 #define calloc xcalloc | |
224 | |
225 | |
226 void printResult(int result, int modus, char* case_file, FILE* stream){ | |
227 char* msg = NULL; | |
228 #ifdef DEBUG | |
229 fprintf(stderr, "case: %s, modus: %x, result: %x\n", case_file, modus, | |
230 result); | |
231 #endif | |
232 | |
233 if(result & RES_PASS){ | |
234 msg = "PASS: "; | |
235 }else if(result & RES_XFAIL){ | |
236 msg = "XFAIL:"; | |
237 }else if(result & RES_XPASS){ | |
238 msg = "XPASS:"; | |
239 }else if(result & RES_FAIL){ | |
240 msg = "FAIL: "; | |
241 }else if(result & RES_ERROR){ | |
242 msg = "ERROR:"; | |
243 } | |
244 | |
245 fprintf(stream, "%s\t%s%s%s\n", msg, case_file, | |
246 (result & RES_BAD_MSG) ? " [bad error message]" : "", | |
247 (result & RES_BAD_GDB) ? " [bad debugger message]" : ""); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
248 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
249 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
250 char* strip(char* buffer){ |
697 | 251 char* tmp = NULL; |
685 | 252 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
253 if(buffer!=NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
254 while(isspace(buffer[0])){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
255 buffer++; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
256 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
257 |
622 | 258 for(tmp=buffer+strlen(buffer)-1; isspace(tmp[0]); tmp=buffer+strlen(buffer)-1){ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
259 tmp[0]='\x00'; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
260 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
261 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
262 return buffer; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
263 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
264 |
734 | 265 unsigned int genTempFileNameCount; |
266 char* genTempFileName(){ | |
267 char* back; | |
268 size_t len; | |
269 | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
270 len = strlen(tmp_dir) + 128; |
734 | 271 back = malloc(len); |
746 | 272 |
273 #ifdef USE_POSIX | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
274 snprintf(back, len, "%s/t%x-%x-%x.tmp", tmp_dir, getpid(), rand(), ++genTempFileNameCount); |
746 | 275 #else |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
276 snprintf(back, len, "%s\\t%x-%x-%x.tmp", tmp_dir, getpid(), rand(), ++genTempFileNameCount); |
746 | 277 #endif |
734 | 278 |
279 return back; | |
280 } | |
281 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
282 /* cleanup "/" versus "\" in filenames */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
283 char* cleanPathSeperator(char* filename){ |
697 | 284 char* pos = NULL; |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
285 #ifdef USE_POSIX |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
286 for(pos=strchr(filename, '\\'); pos; pos=strchr(filename, '\\')){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
287 *pos='/'; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
288 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
289 #else |
633 | 290 #if USE_WINDOWS |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
291 for(pos=strchr(filename, '/'); pos; pos=strchr(filename, '/')){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
292 *pos='\\'; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
293 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
294 #else |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
295 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
296 #error no cleanPathSeperator implementation available for this system |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
297 |
633 | 298 #endif /* USE_WINDOWS else */ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
299 #endif /* USE_POSIX else */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
300 return filename; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
301 } |
490 | 302 |
902 | 303 char* loadFile(char* filename, size_t* len){ |
490 | 304 #ifdef USE_POSIX |
697 | 305 char* back; |
251 | 306 struct stat fileInfo; |
307 int file = open(filename, O_RDONLY); | |
697 | 308 |
309 back = NULL; | |
310 | |
251 | 311 if(errno == 0 && file != 0 && file != -1){ |
312 if(0==fstat(file, &fileInfo)){ | |
313 back=malloc(fileInfo.st_size+1); | |
314 fileInfo.st_size = read(file, back, fileInfo.st_size); | |
440 | 315 if(fileInfo.st_size>=0){ |
697 | 316 *(back+fileInfo.st_size) = '\x00'; |
902 | 317 *len = fileInfo.st_size; |
251 | 318 }else{ |
436 | 319 back = NULL; |
902 | 320 *len = 0; |
251 | 321 } |
322 } | |
323 close(file); | |
324 } | |
436 | 325 |
326 if(back){ | |
327 return back; | |
328 } | |
329 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
330 fprintf(stderr, "File not found \"%s\" (%s)\n", filename, strerror(errno)); |
436 | 331 exit(EXIT_FAILURE); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
332 #else /* USE_POSIX */ |
633 | 333 #ifdef USE_WINDOWS |
734 | 334 /* @todo@ check for 32bit/64bit */ |
697 | 335 char* back; |
254 | 336 DWORD size, numread; |
337 HANDLE file=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, | |
338 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); | |
697 | 339 |
340 back = NULL; | |
341 size = 0; | |
342 numread = 0; | |
254 | 343 if (file != INVALID_HANDLE_VALUE){ |
344 size = GetFileSize(file, NULL); | |
345 if (size != INVALID_FILE_SIZE){ | |
346 back=malloc((size+1)*sizeof(char)); | |
292 | 347 if (ReadFile(file,back,size,&numread,NULL) == 1){ |
348 if (numread==size){ | |
697 | 349 *(back+size) = '\x00'; |
904 | 350 *len = size; |
292 | 351 }else{ |
438 | 352 back = NULL; |
904 | 353 *len = 0; |
292 | 354 } |
355 }else{ | |
438 | 356 back = NULL; |
904 | 357 *len = 0; |
292 | 358 } |
254 | 359 } |
360 CloseHandle(file); | |
361 } | |
438 | 362 if(back){ |
363 errno = 0; | |
364 return back; | |
365 } | |
366 | |
367 fprintf(stderr, "File not found \"%s\"\n", filename); | |
368 exit(EXIT_FAILURE); | |
633 | 369 #else /* USE_WINDOWS */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
370 |
707 | 371 #error no loadFile implementation present |
361 | 372 |
633 | 373 #endif /* USE_WINDOWS */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
374 #endif /* USE_POSIX else */ |
490 | 375 } |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
376 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
377 void writeFile(const char* filename, const char* content){ |
697 | 378 size_t len; |
379 FILE* file; | |
380 | |
381 len = strlen(content); | |
382 errno = 0; | |
383 file = fopen(filename, "w+"); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
384 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
385 if(errno == 0 && file != NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
386 if((fwrite(content, sizeof(char), len, file) != len) || (errno != 0)){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
387 fprintf(stderr, "failed to write file \"%s\" (%s)\n", filename, strerror(errno)); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
388 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
389 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
390 if(fclose(file) || (errno != 0)){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
391 fprintf(stderr, "failed to close file \"%s\" (%s)\n", filename, strerror(errno)); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
392 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
393 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
394 return; |
438 | 395 } |
499 | 396 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
397 fprintf(stderr, "couldn't open file \"%s\" for writing (%s)\n", filename, strerror(errno)); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
398 exit(EXIT_FAILURE); |
438 | 399 } |
400 | |
499 | 401 /* query the environment for the compiler name */ |
697 | 402 char* getCompiler(void){ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
403 char* back = getenv("DMD"); |
704 | 404 |
405 if(back==NULL){ | |
406 back = "dmd"; | |
407 } | |
408 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
409 return strip(cleanPathSeperator(back)); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
410 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
411 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
412 /* query the environment for the debugger name */ |
697 | 413 char* getGDB(void){ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
414 char* back = getenv("GDB"); |
704 | 415 |
416 if(back==NULL){ | |
417 back = "gdb"; | |
418 } | |
419 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
420 return strip(cleanPathSeperator(back)); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
421 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
422 |
734 | 423 char* getTortureBlock(void){ |
424 char* back = getenv("DSTRESS_TORTURE_BLOCK"); | |
425 | |
426 if(back!=NULL){ | |
427 back = strip(back); | |
428 if(strlen(back)<1){ | |
429 back = NULL; | |
430 } | |
431 } | |
432 | |
433 return back; | |
434 } | |
435 | |
499 | 436 /* extract the FIRST occurance of a given TAG until the next linebreak */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
437 char* getCaseFlag(const char* data, const char* tag){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
438 char* begin; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
439 char* end1; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
440 char* end2; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
441 char* back; |
438 | 442 |
697 | 443 begin = NULL; |
444 end1 = NULL; | |
445 end2 = NULL; | |
446 back = NULL; | |
447 | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
448 if(data!=NULL && tag!=NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
449 begin = strstr(data, tag); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
450 if(begin!=NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
451 begin = begin+strlen(tag); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
452 end1 = strstr(begin, "\n"); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
453 end2 = strstr(begin, "\r"); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
454 if(end2!=NULL && ((end1!=NULL && end2<end1) || end1==NULL)){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
455 end1=end2; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
456 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
457 if(end1==NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
458 end1 = begin + strlen(begin); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
459 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
460 back = malloc(end1-begin+1); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
461 strncpy(back, begin, end1-begin); |
697 | 462 back[end1-begin]='\x00'; |
968 | 463 return strip(back); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
464 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
465 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
466 |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
467 back = malloc(1); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
468 back[0] = 0; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
469 return back; |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
470 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
471 |
499 | 472 /* check compile-time error messages */ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
473 int checkErrorMessage(const char* file, const char* line, const char* buffer){ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
474 |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
475 char* dmd; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
476 char* gdc; |
697 | 477 size_t len; |
478 int back; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
479 |
697 | 480 dmd = NULL; |
481 gdc = NULL; | |
482 len = 0; | |
483 back = 0; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
484 |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
485 /* clean arguments */ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
486 if(file && !file[0]){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
487 file = NULL; |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
488 } |
438 | 489 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
490 if(line && !line[0]){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
491 line = NULL; |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
492 } |
438 | 493 |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
494 /* gen patterns*/ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
495 if(file!=NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
496 if(line!=NULL){ |
770 | 497 len = strlen(file)+strlen(line)+3; |
685 | 498 dmd = malloc(len); |
499 snprintf(dmd, len, "%s(%s)", file, line); | |
500 | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
501 gdc = malloc(--len); |
770 | 502 snprintf(gdc, len, "%s:%s", file, line); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
503 }else{ |
685 | 504 len = strlen(file)+2; |
505 dmd = malloc(len); | |
506 snprintf(dmd, len, "%s(", file); | |
622 | 507 |
685 | 508 gdc = malloc(len); |
509 snprintf(gdc, len, "%s:", file); | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
510 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
511 }else if(line!=NULL){ |
770 | 512 len = strlen(line)+3; |
685 | 513 dmd = malloc(len); |
770 | 514 snprintf(dmd, len, "(%s)", line); |
622 | 515 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
516 gdc = malloc(--len); |
770 | 517 snprintf(gdc, len, ":%s", line); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
518 }else{ |
432 | 519 return 1; |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
520 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
521 |
438 | 522 /* specific error messages */ |
676 | 523 #ifdef DEBUG |
524 fprintf(stderr, "pattern(dmd):\t%s\n", dmd); | |
525 fprintf(stderr, "pattern(gdc):\t%s\n", gdc); | |
526 #endif | |
251 | 527 |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
528 if( (dmd!=NULL && strstr(buffer, dmd)) |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
529 || (gdc!=NULL && strstr(buffer, gdc)) |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
530 || (dmd==NULL && gdc==NULL)){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
531 back=1; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
532 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
533 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
534 free(dmd); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
535 free(gdc); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
536 |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
537 return back; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
538 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
539 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
540 int checkRuntimeErrorMessage(const char* file, const char* line, const char* buffer){ |
438 | 541 /* PhobosLong dir/file.d(2) |
490 | 542 * Phobos package.module(2) |
438 | 543 */ |
432 | 544 |
545 char* phobos; | |
546 char* phobosLong; | |
547 | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
548 const char* begin; |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
549 const char* end; |
685 | 550 size_t len; |
432 | 551 |
552 int back=0; | |
553 | |
697 | 554 phobos = NULL; |
555 phobosLong = NULL; | |
556 | |
557 begin = NULL; | |
558 end = NULL; | |
559 len = 0; | |
560 | |
432 | 561 /* clean arguments */ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
562 if(file && !file[0]){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
563 file = NULL; |
432 | 564 } |
438 | 565 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
566 if(line && !line[0]){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
567 line = NULL; |
432 | 568 } |
438 | 569 |
432 | 570 /* gen patterns*/ |
571 if(file!=NULL){ | |
572 if(line!=NULL){ | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
573 len = strlen(file)+strlen(line)+3; |
685 | 574 phobos = malloc(len); |
438 | 575 begin=strrchr(file,'/'); |
576 if(begin){ | |
432 | 577 begin++; |
578 }else{ | |
438 | 579 begin=strrchr(file,'\\'); |
580 if(begin){ | |
581 begin++; | |
582 }else{ | |
583 begin=file; | |
584 } | |
432 | 585 } |
439 | 586 end=strrchr(file,'.'); |
587 strncat(phobos, begin, end-begin); | |
685 | 588 snprintf(phobos, len, "%.*s(%s)", |
589 (int)(end-begin), begin, | |
590 line); | |
432 | 591 |
685 | 592 phobosLong = malloc(len); |
593 snprintf(phobosLong, len, "%s(%s)", file, line); | |
432 | 594 }else{ |
685 | 595 len = strlen(file)+2; |
596 phobos = malloc(len); | |
438 | 597 begin=strrchr(file,'/'); |
598 if(begin){ | |
432 | 599 begin++; |
600 }else{ | |
438 | 601 begin=strrchr(file,'\\'); |
602 if(begin){ | |
603 begin++; | |
604 }else{ | |
605 begin=file; | |
606 } | |
432 | 607 } |
439 | 608 end=strrchr(file,'.'); |
685 | 609 snprintf(phobos, len, "%.*s(", (int)(end-begin), begin); |
432 | 610 |
685 | 611 phobosLong = malloc(len); |
612 snprintf(phobosLong, len, "%s(", file); | |
432 | 613 } |
614 }else if(line!=NULL){ | |
685 | 615 len = strlen(line)+3; |
616 phobos = malloc(len); | |
617 snprintf(phobos, len, "(%s)", line); | |
438 | 618 |
432 | 619 phobosLong=NULL; |
620 }else{ | |
621 return 1; | |
622 } | |
623 | |
438 | 624 /* specific error messages */ |
432 | 625 |
676 | 626 #ifdef DEBUG |
627 fprintf(stderr, "pattern(phobosShort):\t%s\n", phobos); | |
628 fprintf(stderr, "pattern(phobosLong):\t%s\n", phobosLong); | |
629 #endif | |
630 | |
432 | 631 if( (phobos && strstr(buffer, phobos)) |
632 || (phobosLong && strstr(buffer, phobosLong))) | |
633 { | |
634 back=1; | |
635 } | |
438 | 636 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
637 free(phobos); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
638 if(phobosLong){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
639 free(phobosLong); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
640 } |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
641 |
438 | 642 return back; |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
643 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
644 |
490 | 645 int hadExecCrash(const char* buffer){ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
646 if(strstr(buffer, "Segmentation fault") |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
647 || strstr(buffer, "Internal error") |
499 | 648 || strstr(buffer, "gcc.gnu.org/bugs") |
774 | 649 || strstr(buffer, "EXIT CODE: signal") |
650 || strstr(buffer, "Assertion failure") | |
968 | 651 || strstr(buffer, "Access Violation") |
652 || strstr(buffer, "Invalid read of size") | |
653 || strstr(buffer, "Conditional jump or move depends on uninitialised value") | |
654 || strstr(buffer, "Use of uninitialised value of size")) | |
490 | 655 { |
656 return 1; | |
657 } | |
658 return 0; | |
659 } | |
660 | |
499 | 661 /* system call with time-out */ |
734 | 662 int crashRun(const char* cmd, char** logFile){ |
746 | 663 |
697 | 664 size_t len; |
665 char* buffer; | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
666 int back; |
697 | 667 |
734 | 668 *logFile = genTempFileName(); |
746 | 669 #ifdef USE_POSIX |
734 | 670 len = 20 + strlen(CRASH_RUN) + strlen(cmd) + strlen(*logFile); |
697 | 671 buffer = malloc(len); |
672 | |
940 | 673 snprintf(buffer, len, "%s %s > %s 2>&1", CRASH_RUN, cmd, *logFile); |
697 | 674 |
490 | 675 system(buffer); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
676 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
677 |
902 | 678 buffer=loadFile(*logFile, &len); |
490 | 679 |
902 | 680 /* @todo@ use: len */ |
490 | 681 if(strstr(buffer, "EXIT CODE: 0")){ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
682 back = EXIT_SUCCESS; |
490 | 683 }else if(strstr(buffer, "EXIT CODE: 256") |
684 || strstr(buffer, "EXIT CODE: timeout")) | |
685 { | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
686 back = EXIT_FAILURE; |
490 | 687 }else{ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
688 back = RAND_MAX; |
490 | 689 } |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
690 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
691 |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
692 return back; |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
693 #elif defined USE_WINDOWS |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
694 PROCESS_INFORMATION processInfo; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
695 STARTUPINFO startupInfo; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
696 SECURITY_ATTRIBUTES sa = { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
697 sizeof(SECURITY_ATTRIBUTES), NULL, TRUE |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
698 }; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
699 HANDLE tLogFile; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
700 unsigned long exitCode; |
902 | 701 int timeLeft = 600; /* time limit in iterations of WFX loop */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
702 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
703 memset(&processInfo, 0, sizeof(PROCESS_INFORMATION)); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
704 memset(&startupInfo, 0, sizeof(STARTUPINFO)); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
705 startupInfo.cb = sizeof(STARTUPINFO); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
706 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
707 tLogFile = CreateFile(*logFile, GENERIC_WRITE, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
708 0, &sa, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
709 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
710 if (tLogFile == NULL) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
711 printf("ERROR: could not open log file"); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
712 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
713 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
714 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
715 SetStdHandle(STD_OUTPUT_HANDLE, tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
716 SetStdHandle(STD_ERROR_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
717 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
718 if (!CreateProcess(NULL, (char*) cmd, NULL, NULL, TRUE, 0, NULL, NULL, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
719 &startupInfo, &processInfo)) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
720 void *message; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
721 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
722 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
723 | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
724 (char*) &message, 0, NULL); |
490 | 725 |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
726 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
727 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
728 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
729 |
902 | 730 /* this should never happen */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
731 fprintf(stderr, "ERROR running %s:\n", cmd); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
732 fprintf(stderr, "%s\n", message); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
733 LocalFree((HLOCAL) message); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
734 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
735 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
736 |
902 | 737 /* wait for exit */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
738 while (TRUE) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
739 GetExitCodeProcess(processInfo.hProcess, &exitCode); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
740 if (exitCode == 0x103) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
741 if (--timeLeft == 0) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
742 TerminateProcess(processInfo.hProcess, EXIT_FAILURE); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
743 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
744 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
745 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
746 printf("EXIT CODE: timeout\n"); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
747 Sleep(100); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
748 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
749 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
750 Sleep(100); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
751 } else { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
752 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
753 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
754 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
755 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
756 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
757 printf("EXIT CODE: %i\n", exitCode); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
758 return exitCode; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
759 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
760 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
761 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
762 #else /* USE_WINDOWS */ |
704 | 763 #error comment me out, if your test cases produce neither eternal loops nor Access Violations |
746 | 764 |
765 len = 10 + strlen(cmd) + strlen(*logFile); | |
766 buffer = malloc(len); | |
767 | |
768 snprintf(buffer, len, "%s > %s 2>&1", cmd, *logFile); | |
769 | |
770 int i = system(buffer); | |
902 | 771 printf("EXIT CODE: %i\n", i); |
746 | 772 |
697 | 773 return i; |
490 | 774 #endif /* USE_POSIX else */ |
775 } | |
776 | |
734 | 777 int target_compile(int modus, char* compiler, char* arguments, char* case_file, |
778 char* error_file, char* error_line) | |
779 { | |
780 size_t bufferLen; | |
781 char* buffer; | |
782 int res; | |
783 int testResult; | |
784 int good_error; | |
785 char* logFile; | |
786 | |
787 bufferLen = 0; | |
788 buffer = NULL; | |
789 res = -1; | |
790 testResult = -1; | |
791 good_error = 0; | |
792 logFile = NULL; | |
793 | |
794 if(!(modus & MODE_COMPILE) && !(modus & MODE_NOCOMPILE)){ | |
795 fprintf(stderr, "BUG: badly handled mode %i (->compile)\n", | |
796 modus); | |
797 exit(EXIT_FAILURE); | |
798 } | |
799 | |
800 /* gen command */ | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
801 bufferLen = strlen(compiler) + strlen(arguments) + strlen(tmp_dir) |
734 | 802 + strlen(case_file) + 21; |
803 buffer = malloc(bufferLen); | |
804 snprintf(buffer, bufferLen, "%s %s ", compiler, arguments); | |
805 | |
806 if(NULL == strstr(buffer, "-od")){ | |
807 snprintf(buffer, bufferLen, "%s %s -od%s -c %s", | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
808 compiler, arguments, tmp_dir, case_file); |
734 | 809 }else{ |
810 snprintf(buffer, bufferLen, "%s %s -c %s", | |
811 compiler, arguments, case_file); | |
812 } | |
813 | |
814 /* test */ | |
815 if(modus & MODE_COMPILE){ | |
902 | 816 printf("compile: %s\n", buffer); |
734 | 817 }else{ |
902 | 818 printf("nocompile: %s\n", buffer); |
734 | 819 } |
820 res = crashRun(buffer, &logFile); | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
821 free(buffer); |
734 | 822 |
823 /* diagnostic */ | |
902 | 824 buffer = loadFile(logFile, &bufferLen); |
825 printf("%.*s\n", (int)bufferLen, buffer); | |
734 | 826 remove(logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
827 free(logFile); |
734 | 828 good_error = checkErrorMessage(error_file, error_line, buffer); |
829 | |
830 if(hadExecCrash(buffer)){ | |
831 testResult = RES_ERROR; | |
832 }else if(modus & MODE_COMPILE){ | |
833 if(res == EXIT_SUCCESS){ | |
834 testResult = RES_PASS; | |
835 }else if(res == EXIT_FAILURE){ | |
836 testResult = RES_FAIL | (good_error ? 0 : RES_BAD_MSG); | |
837 }else{ | |
838 testResult = RES_ERROR | (good_error ? 0 : RES_BAD_MSG); | |
839 } | |
840 }else{ | |
841 if(res == EXIT_FAILURE){ | |
842 if(good_error){ | |
843 testResult = RES_XFAIL; | |
844 }else{ | |
845 testResult = RES_FAIL | RES_BAD_MSG; | |
846 } | |
847 }else if(res == EXIT_SUCCESS){ | |
848 testResult = RES_XPASS; | |
849 }else{ | |
850 testResult = RES_ERROR; | |
851 } | |
852 } | |
853 | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
854 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
855 |
734 | 856 return testResult; |
857 } | |
858 | |
859 int target_run(int modus, char* compiler, char* arguments, char* case_file, | |
860 char* error_file, char* error_line | |
861 #ifdef REG_EXTENDED | |
862 , char* gdb, char* gdb_script, regex_t* gdb_pattern | |
863 #endif | |
864 ) | |
865 { | |
866 size_t bufferLen; | |
867 char* buffer; | |
868 int res; | |
869 int testResult; | |
870 int good_error; | |
871 char* logFile; | |
872 char* gdb_scripter; | |
873 int good_gdb; | |
874 | |
875 bufferLen = 0; | |
876 buffer = NULL; | |
877 res = -1; | |
878 testResult = -1; | |
879 good_error = 0; | |
880 logFile = NULL; | |
881 good_gdb = 0; | |
882 gdb_scripter = NULL; | |
883 | |
884 if(!(modus & MODE_RUN) && !(modus & MODE_NORUN)){ | |
885 fprintf(stderr, "BUG: badly handled mode %i (->run)\n", modus); | |
886 exit(EXIT_FAILURE); | |
887 } | |
746 | 888 |
734 | 889 /* gen command */ |
890 | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
891 bufferLen = strlen(compiler) + strlen(arguments) + strlen(tmp_dir) |
734 | 892 + strlen(case_file) * 2 + 64; |
893 buffer = malloc(bufferLen); | |
894 snprintf(buffer, bufferLen, "%s %s ", compiler, arguments); | |
895 | |
896 if(NULL == strstr(buffer, "-od")){ | |
897 if(NULL == strstr(buffer, "-of")){ | |
898 snprintf(buffer, bufferLen, | |
899 "%s %s -od%s -of%s.exe %s", | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
900 compiler, arguments, tmp_dir, case_file, |
734 | 901 case_file); |
902 }else{ | |
903 snprintf(buffer, bufferLen, | |
904 "%s %s -od%s %s", | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
905 compiler, arguments, tmp_dir, case_file); |
734 | 906 } |
907 }else if(NULL == strstr(buffer, "-of")){ | |
908 snprintf(buffer, bufferLen, | |
909 "%s %s -of%s.exe %s", | |
910 compiler, arguments, case_file, case_file); | |
911 }else{ | |
912 snprintf(buffer, bufferLen, "%s %s %s", | |
913 compiler, arguments, case_file); | |
914 } | |
915 | |
916 /* test 1/3 - compile */ | |
917 if(modus & MODE_RUN){ | |
902 | 918 printf("run: %s\n", buffer); |
734 | 919 }else{ |
902 | 920 printf("norun: %s\n", buffer); |
734 | 921 } |
922 res = crashRun(buffer, &logFile); | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
923 free(buffer); |
734 | 924 |
925 /* diagnostic 1/3 */ | |
902 | 926 buffer = loadFile(logFile, &bufferLen); |
927 printf("%.*s", (int)bufferLen, buffer); | |
734 | 928 remove(logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
929 free(logFile); |
746 | 930 |
734 | 931 if(modus & MODE_RUN){ |
932 good_error = checkErrorMessage(error_file, error_line, | |
933 buffer); | |
934 }else{ | |
935 good_error = 1; | |
936 } | |
937 | |
938 if(hadExecCrash(buffer)){ | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
939 free(buffer); |
734 | 940 return RES_ERROR; |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
941 }else{ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
942 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
943 if((res == EXIT_FAILURE) && good_error){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
944 return RES_FAIL; |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
945 }else if(res!=EXIT_SUCCESS){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
946 return RES_ERROR | (good_error ? 0 : RES_BAD_MSG); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
947 } |
734 | 948 } |
949 | |
950 /* test 2/3 - run */ | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
951 if(VALGRIND && VALGRIND[0]){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
952 bufferLen = strlen(VALGRIND) + strlen(case_file) + 8; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
953 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
954 snprintf(buffer, bufferLen, "%s %s.exe", VALGRIND, case_file); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
955 }else{ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
956 bufferLen = strlen(case_file) + 8; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
957 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
958 snprintf(buffer, bufferLen, "%s.exe", case_file); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
959 } |
902 | 960 printf("%s\n", buffer); |
734 | 961 res=crashRun(buffer, &logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
962 free(buffer); |
734 | 963 |
964 /* diagnostic 2/3 */ | |
902 | 965 buffer = loadFile(logFile, &bufferLen); |
966 printf("%.*s\n", (int) bufferLen, buffer); | |
734 | 967 remove(logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
968 free(logFile); |
734 | 969 |
970 if(modus & MODE_NORUN){ | |
971 good_error = checkRuntimeErrorMessage(error_file, error_line, | |
972 buffer); | |
973 }else{ | |
974 good_error = 1; | |
975 } | |
976 | |
977 #ifdef REG_EXTENDED | |
968 | 978 if(((res==EXIT_SUCCESS && (modus & MODE_RUN)) |
979 ||(res==EXIT_SUCCESS && (modus & MODE_RUN))) | |
980 && gdb_script != NULL) | |
981 { | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
982 free(buffer); |
734 | 983 good_gdb = 0; |
984 /* test 3/3 - gdb */ | |
985 gdb_scripter = genTempFileName(); | |
986 writeFile(gdb_scripter, gdb_script); | |
987 bufferLen = strlen(gdb) + strlen(case_file) | |
988 + strlen(gdb_scripter) + 20; | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
989 buffer = malloc(bufferLen); |
734 | 990 snprintf(buffer, bufferLen, "%s %s.exe < %s", |
991 gdb, case_file, gdb_scripter); | |
902 | 992 printf("%s\n", buffer); |
734 | 993 if(EXIT_SUCCESS==crashRun(buffer, &logFile)){ |
994 /* diagnostic 3/3 */ | |
902 | 995 buffer = loadFile(logFile, &bufferLen); |
996 printf("%.*s\n", (int)bufferLen, buffer); | |
734 | 997 good_gdb = (regexec(gdb_pattern, buffer, 0, NULL, 0)==0); |
998 } | |
999 remove(logFile); | |
1000 remove(gdb_scripter); | |
1001 }else{ | |
1002 good_gdb = 1; | |
1003 } | |
746 | 1004 #else |
1005 good_gdb = 1; | |
902 | 1006 #endif /* REG_EXTENDED else */ |
734 | 1007 |
1008 if(modus & MODE_RUN){ | |
1009 if(hadExecCrash(buffer)){ | |
746 | 1010 testResult = RES_ERROR; |
734 | 1011 }else if((res==EXIT_SUCCESS) && good_gdb){ |
1012 testResult = RES_PASS; | |
1013 }else if((res==EXIT_FAILURE) && good_error && good_gdb){ | |
1014 testResult = RES_FAIL; | |
1015 }else{ | |
1016 testResult = RES_ERROR | (good_error ? 0 : RES_BAD_MSG) | |
1017 | (good_gdb ? 0 : RES_BAD_GDB); | |
1018 } | |
1019 }else{ | |
1020 if(res==EXIT_SUCCESS){ | |
1021 testResult = RES_XPASS; | |
1022 }else if(good_error && good_gdb){ | |
1023 testResult = RES_XFAIL; | |
1024 }else{ | |
1025 testResult = RES_FAIL | (good_error ? 0 : RES_BAD_MSG) | |
1026 | (good_gdb ? 0 : RES_BAD_GDB); | |
1027 } | |
1028 } | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1029 free(buffer); |
734 | 1030 |
1031 return testResult; | |
1032 } | |
254 | 1033 |
251 | 1034 int main(int argc, char* arg[]){ |
746 | 1035 |
438 | 1036 char* compiler; /* the compiler - from enviroment flag "DMD" */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1037 char* cmd_arg_case; /* additional arguments - from the testcase file */ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1038 char* buffer; /* general purpose buffer */ |
685 | 1039 size_t bufferLen; |
734 | 1040 int index; |
438 | 1041 int modus; /* test modus: RUN NORUN COMPILE NOCOMPILE */ |
1042 char* case_file; | |
734 | 1043 int case_result; |
1044 int torture_result[sizeof(torture)/sizeof(char*)]; | |
1045 char* torture_block_global; | |
1046 char* torture_block_case; | |
1047 char* torture_require; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1048 char* error_file; /* expected sourcefile containing the error */ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1049 char* error_line; /* expected error line */ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1050 char* gdb; /* the debugger - from environment flag "GDB" */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1051 char* gdb_script; /* gdb command sequence */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1052 char* gdb_pattern_raw; /* POSIX regexp expected in GDB's output */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1053 #ifdef REG_EXTENDED |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1054 regex_t* gdb_pattern; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1055 #endif |
438 | 1056 |
697 | 1057 compiler = NULL; |
1058 cmd_arg_case = NULL; | |
1059 buffer = NULL; | |
1060 bufferLen = 0; | |
1061 modus = -1; | |
1062 case_file = NULL; | |
734 | 1063 torture_block_global = NULL; |
1064 torture_block_case = NULL; | |
1065 torture_require = NULL; | |
697 | 1066 error_file = NULL; |
1067 error_line = NULL; | |
1068 gdb = NULL; | |
1069 gdb_script = NULL; | |
1070 gdb_pattern_raw = NULL; | |
1071 #ifdef REG_EXTENDED | |
1072 gdb_pattern = NULL; | |
1073 #endif | |
1074 | |
251 | 1075 /* check arguments */ |
1076 if(argc != 3){ | |
438 | 1077 err: |
902 | 1078 fprintf(stderr, "DStress test executer (revision 1083)\n" |
1079 "Copyright by Thomas Kuehne <thomas@kuehne.cn> 2005, 2006\n" | |
704 | 1080 "\n"); |
1081 | |
734 | 1082 if(argc!=0){ |
704 | 1083 fprintf(stderr, |
1084 "%s <run|norun|compile|nocompile> <source>\n", | |
1085 arg[0]); | |
734 | 1086 }else{ |
704 | 1087 fprintf(stderr, |
1088 "dstress <run|norun|compile|nocompile>" | |
1089 " <source>\n"); | |
734 | 1090 } |
704 | 1091 |
734 | 1092 fprintf(stderr, "\n" |
704 | 1093 "== eniroment settings (usually $NAME or %%NAME%%) ==\n" |
1094 "* DMD - compiler (including standard arguments)\n" | |
734 | 1095 "* GDB - debugger (including standard arguments)\n"); |
1096 fprintf(stderr, "\n" | |
704 | 1097 "== case setting (line in the case source) ==\n" |
1098 "* __DSTRESS_DFLAGS__ - additional compiler arguments\n" | |
1099 "only evaluated if it is a \"nocompile\" or \"norun\" test:\n" | |
1100 "* __DSTRESS_ELINE__ - expected source line to throw an error message\n" | |
1101 "* __DSTRESS_EFILE__ - expected source file to throw an error message\n" | |
734 | 1102 " (defaults to the case file)\n"); |
1103 fprintf(stderr, | |
704 | 1104 "only evaluated if it is a \"run\" or \"norun\" test:\n" |
1105 "* __GDB_SCRIPT__ - command sequence to feed to the debugger\n" | |
1106 " (use \\n to encode a line break)\n" | |
1107 "* __GDB_PATTERN__ - expected regular expression in the debugger's\n" | |
734 | 1108 " output\n"); |
1109 fprintf(stderr, "\n" | |
704 | 1110 "== note ==\n" |
710 | 1111 "* the current directory is required to contain the sub-directory \"obj\"\n" |
704 | 1112 " (used for temporary files)\n" |
1113 ); | |
438 | 1114 exit(EXIT_FAILURE); |
251 | 1115 } |
438 | 1116 |
734 | 1117 modus = 0; |
1118 if(0==strncmp(arg[1], TORTURE_PREFIX, strlen(TORTURE_PREFIX))){ | |
1119 modus |= MODE_TORTURE; | |
1120 arg[1] += strlen(TORTURE_PREFIX); | |
1121 } | |
704 | 1122 if(0==strcmp(arg[1], "run")){ |
734 | 1123 modus |= MODE_RUN; |
704 | 1124 }else if(0==strcmp(arg[1], "norun")){ |
734 | 1125 modus |= MODE_NORUN; |
704 | 1126 }else if(0==strcmp(arg[1], "compile")){ |
734 | 1127 modus |= MODE_COMPILE; |
704 | 1128 }else if(0==strcmp(arg[1], "nocompile")){ |
734 | 1129 modus |= MODE_NOCOMPILE; |
251 | 1130 }else{ |
1131 goto err; | |
1132 } | |
1133 | |
1134 /* gen flags */ | |
902 | 1135 case_file = cleanPathSeperator(arg[2]); |
251 | 1136 compiler = getCompiler(); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1137 gdb = getGDB(); |
734 | 1138 torture_block_global = getTortureBlock(); |
902 | 1139 buffer = loadFile(case_file, &bufferLen); |
1140 bufferLen = 0; | |
438 | 1141 |
968 | 1142 cmd_arg_case = cleanPathSeperator(getCaseFlag(buffer, "__DSTRESS_DFLAGS__")); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1143 error_line = getCaseFlag(buffer, "__DSTRESS_ELINE__"); |
968 | 1144 error_file = cleanPathSeperator(getCaseFlag(buffer, "__DSTRESS_EFILE__")); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1145 gdb_script = getCaseFlag(buffer, "__GDB_SCRIPT__"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1146 gdb_pattern_raw = getCaseFlag(buffer, "__GDB_PATTERN__"); |
734 | 1147 torture_block_case = getCaseFlag(buffer, "__DSTRESS_TORTURE_BLOCK__"); |
1148 torture_require = getCaseFlag(buffer, "__DSTRESS_TORTURE_REQUIRE__"); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1149 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1150 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1151 |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1152 /* tmp_dir */ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1153 if(!cmd_arg_case || !cmd_arg_case[0]){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1154 tmp_dir = TMP_DIR; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1155 }else{ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1156 pid_t pid; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1157 pid = getpid(); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1158 bufferLen = strlen(TMP_DIR) + 4 + sizeof(pid_t) * 4; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1159 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1160 snprintf(buffer, bufferLen, "%s/_%X", TMP_DIR, pid); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1161 tmp_dir = cleanPathSeperator(buffer); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1162 if(mkdir(tmp_dir, 0770)){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1163 fprintf(stderr, "failed to create tmp dir: %s (%d, %s)\n", |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1164 tmp_dir, errno, strerror(errno)); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1165 return EXIT_FAILURE; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1166 } |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1167 } |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1168 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1169 /* set implicit source file */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1170 if(strcmp(error_line, "")!=0 && strcmp(error_file, "")==0){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1171 error_file=case_file; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1172 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1173 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1174 /* gdb pattern */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1175 #ifdef REG_EXTENDED |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1176 if(gdb_pattern_raw!=NULL && gdb_pattern_raw[0]!='\x00'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1177 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1178 gdb_pattern = malloc(sizeof(regex_t)); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1179 if(regcomp(gdb_pattern, gdb_pattern_raw, REG_EXTENDED | REG_NOSUB)){ |
704 | 1180 fprintf(stderr, "failed to compile regular expression:" |
1181 "\n\t%s\n", gdb_pattern_raw); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1182 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1183 }else if(gdb_script==NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1184 fprintf(stderr, "GDB pattern without GDB script\n"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1185 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1186 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1187 }else{ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1188 gdb_pattern = NULL; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1189 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1190 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1191 /* gdb script */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1192 if(gdb_script!=NULL && gdb_script[0]!='\x00'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1193 if(gdb_pattern==NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1194 fprintf(stderr, "GDB script without GDB pattern\n"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1195 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1196 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1197 buffer=gdb_script; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1198 for(; *buffer; buffer++){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1199 if(buffer[0]=='\\'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1200 if(buffer[1]=='n'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1201 buffer[0]=' '; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1202 buffer[1]='\n'; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1203 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1204 buffer++; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1205 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1206 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1207 |
685 | 1208 bufferLen = strlen(gdb_script)+11; |
1209 buffer=malloc(bufferLen); | |
1210 snprintf(buffer, bufferLen, "%s\n\nquit\ny\n\n", gdb_script); | |
1211 gdb_script=buffer; | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1212 }else if(gdb_script){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1213 free(gdb_script); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1214 gdb_script = NULL; |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1215 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1216 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1217 #else |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1218 |
704 | 1219 if(gdb_script && strlen(gdb_script)){ |
1220 if(gdb_pattern_raw && strlen(gdb_pattern_raw)){ | |
734 | 1221 fprintf(stderr, "WARNING: GDB/regex support inactive\n"); |
704 | 1222 }else{ |
734 | 1223 fprintf(stderr, "GDB script without GDB pattern\n"); |
704 | 1224 exit(EXIT_FAILURE); |
1225 } | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1226 }else if(gdb_pattern_raw && strlen(gdb_pattern_raw)){ |
734 | 1227 fprintf(stderr, "GDB pattern without GDB script\n"); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1228 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1229 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1230 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1231 #endif /* REG_EXTENDED else */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1232 |
493 | 1233 #ifdef DEBUG |
902 | 1234 fprintf(stderr, "case : \"%s\"\n", case_file); |
438 | 1235 fprintf(stderr, "compiler: \"%s\"\n", compiler); |
1236 fprintf(stderr, "DFLAGS C: \"%s\"\n", cmd_arg_case); | |
1237 fprintf(stderr, "ELINE : \"%s\"\n", error_line); | |
1238 fprintf(stderr, "EFILE : \"%s\"\n", error_file); | |
734 | 1239 #ifdef REG_EXTENDED |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1240 fprintf(stderr, "GDB Scri: \"%s\"\n", gdb_script); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1241 fprintf(stderr, "GDB Patt: \"%s\"\n", gdb_pattern_raw); |
438 | 1242 #endif |
734 | 1243 fprintf(stderr, "block G : \"%s\"\n", torture_block_global); |
1244 fprintf(stderr, "block C : \"%s\"\n", torture_block_case); | |
1245 fprintf(stderr, "modus : %x\n", modus); | |
1246 #endif | |
685 | 1247 |
251 | 1248 |
734 | 1249 /* let's get serious */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1250 #ifdef USE_WINDOWS |
902 | 1251 originalStdout = GetStdHandle(STD_OUTPUT_HANDLE); |
1252 originalStderr = GetStdHandle(STD_ERROR_HANDLE); | |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1253 #endif |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1254 |
734 | 1255 if(modus & MODE_TORTURE){ |
746 | 1256 if((modus & (MODE_COMPILE | MODE_NOCOMPILE)) |
734 | 1257 && (modus & (MODE_RUN | MODE_NORUN))) |
1258 { | |
1259 fprintf(stderr, "BUG: unhandled torture modus %x\n", modus); | |
902 | 1260 exit(EXIT_FAILURE); |
734 | 1261 }else if(!(modus & (MODE_COMPILE | MODE_NOCOMPILE | MODE_RUN | MODE_NORUN))){ |
1262 fprintf(stderr, "BUG: unhandled torture modus %x\n", modus); | |
902 | 1263 exit(EXIT_FAILURE); |
251 | 1264 } |
1265 | |
734 | 1266 bufferLen = strlen(torture[(sizeof(torture) / sizeof(char*))-1]) |
1267 + strlen(cmd_arg_case) + 3; | |
746 | 1268 |
734 | 1269 if(torture_block_case!=NULL && strlen(torture_block_case)<1){ |
1270 torture_block_case=NULL; | |
676 | 1271 } |
746 | 1272 |
734 | 1273 buffer = malloc(bufferLen); |
1274 for(index=0; index < sizeof(torture)/sizeof(char*); index++){ | |
1275 if((torture_block_global && strstr(torture[index], torture_block_global)) | |
1276 || (torture_block_case && strstr(torture[index], torture_block_case)) | |
959 | 1277 || (torture_require && !strstr(torture[index], torture_require))) |
734 | 1278 { |
1279 torture_result[index]=RES_UNTESTED; | |
1280 continue; | |
1281 } | |
746 | 1282 |
734 | 1283 buffer[0]=0; |
1284 snprintf(buffer, bufferLen, "%s %s", torture[index], cmd_arg_case); | |
746 | 1285 |
734 | 1286 if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){ |
1287 torture_result[index] = target_compile(modus, | |
1288 compiler, buffer, case_file, | |
1289 error_file, error_line); | |
1290 }else if(modus & (MODE_RUN | MODE_NORUN)){ | |
1291 torture_result[index] = target_run(modus, | |
1292 compiler, buffer, case_file, | |
1293 error_file, error_line | |
1294 #ifdef REG_EXTENDED | |
1295 , gdb, gdb_script, gdb_pattern | |
1296 #endif | |
1297 ); | |
1298 } | |
438 | 1299 |
902 | 1300 printf("Torture-Sub-%i/" ZU "-", index+1, |
734 | 1301 sizeof(torture)/sizeof(char*)); |
1302 printResult(torture_result[index], modus, case_file, | |
902 | 1303 stdout); |
1304 printf("--------\n"); | |
685 | 1305 } |
251 | 1306 }else{ |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1307 if(torture_require && !torture_require[0]){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1308 if(!cmd_arg_case || !cmd_arg_case[0]){ |
968 | 1309 torture_require = cmd_arg_case; |
1310 }else{ | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1311 bufferLen = strlen(cmd_arg_case); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1312 bufferLen += strlen(torture_require); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1313 bufferLen += 2; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1314 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1315 snprintf(buffer, bufferLen, "%s %s", cmd_arg_case, torture_require); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1316 cmd_arg_case = buffer; |
968 | 1317 } |
1318 } | |
734 | 1319 if(modus & (MODE_RUN | MODE_NORUN)){ |
1320 case_result = target_run(modus, compiler, cmd_arg_case, | |
1321 case_file, error_file, error_line | |
1322 #ifdef REG_EXTENDED | |
1323 , gdb, gdb_script, gdb_pattern | |
1324 #endif | |
1325 ); | |
880 | 1326 }else if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){ |
734 | 1327 case_result = target_compile(modus, compiler, |
1328 cmd_arg_case, case_file, error_file, | |
1329 error_line); | |
881 | 1330 }else{ |
1331 fprintf(stderr, "BUG: unhandled non-torture modus %x\n", modus); | |
902 | 1332 exit(EXIT_FAILURE); |
734 | 1333 } |
904 | 1334 |
902 | 1335 printf("Torture-Sub-1/" ZU "-", |
880 | 1336 sizeof(torture)/sizeof(char*)); |
1337 printResult(case_result, modus, case_file, stdout); | |
251 | 1338 } |
734 | 1339 |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1340 if(strcmp(TMP_DIR, tmp_dir)){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1341 bufferLen = strlen(tmp_dir); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1342 bufferLen += strlen(RM_DIR); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1343 bufferLen += 2; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1344 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1345 snprintf(buffer, bufferLen, "%s %s", RM_DIR, tmp_dir); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1346 system(buffer); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1347 } |
902 | 1348 exit(EXIT_SUCCESS); |
251 | 1349 } |