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