Mercurial > projects > dstress
annotate dstress.c @ 888:a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
Stewart Gordon <smjg_1998@yahoo.com>
2005-12-06
news:dn3r9u$kfo$1@digitaldaemon.com
author | thomask |
---|---|
date | Sun, 05 Mar 2006 21:57:33 +0000 |
parents | 996d9134bf80 |
children | 58966fea59f7 |
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 |
251 | 258 char* loadFile(char* filename){ |
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'; |
251 | 272 }else{ |
436 | 273 back = NULL; |
251 | 274 } |
275 } | |
276 close(file); | |
277 } | |
436 | 278 |
279 if(back){ | |
280 return back; | |
281 } | |
282 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
283 fprintf(stderr, "File not found \"%s\" (%s)\n", filename, strerror(errno)); |
436 | 284 exit(EXIT_FAILURE); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
285 #else /* USE_POSIX */ |
633 | 286 #ifdef USE_WINDOWS |
734 | 287 /* @todo@ check for 32bit/64bit */ |
697 | 288 char* back; |
254 | 289 DWORD size, numread; |
290 HANDLE file=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, | |
291 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); | |
697 | 292 |
293 back = NULL; | |
294 size = 0; | |
295 numread = 0; | |
254 | 296 if (file != INVALID_HANDLE_VALUE){ |
297 size = GetFileSize(file, NULL); | |
298 if (size != INVALID_FILE_SIZE){ | |
299 back=malloc((size+1)*sizeof(char)); | |
292 | 300 if (ReadFile(file,back,size,&numread,NULL) == 1){ |
301 if (numread==size){ | |
697 | 302 *(back+size) = '\x00'; |
292 | 303 }else{ |
438 | 304 back = NULL; |
292 | 305 } |
306 }else{ | |
438 | 307 back = NULL; |
292 | 308 } |
254 | 309 } |
310 CloseHandle(file); | |
311 } | |
438 | 312 if(back){ |
313 errno = 0; | |
314 return back; | |
315 } | |
316 | |
317 fprintf(stderr, "File not found \"%s\"\n", filename); | |
318 exit(EXIT_FAILURE); | |
633 | 319 #else /* USE_WINDOWS */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
320 |
707 | 321 #error no loadFile implementation present |
361 | 322 |
633 | 323 #endif /* USE_WINDOWS */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
324 #endif /* USE_POSIX else */ |
490 | 325 } |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
326 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
327 void writeFile(const char* filename, const char* content){ |
697 | 328 size_t len; |
329 FILE* file; | |
330 | |
331 len = strlen(content); | |
332 errno = 0; | |
333 file = fopen(filename, "w+"); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
334 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
335 if(errno == 0 && file != NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
336 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
|
337 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
|
338 exit(EXIT_FAILURE); |
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(fclose(file) || (errno != 0)){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
341 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
|
342 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
343 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
344 return; |
438 | 345 } |
499 | 346 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
347 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
|
348 exit(EXIT_FAILURE); |
438 | 349 } |
350 | |
499 | 351 /* query the environment for the compiler name */ |
697 | 352 char* getCompiler(void){ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
353 char* back = getenv("DMD"); |
704 | 354 |
355 if(back==NULL){ | |
356 back = "dmd"; | |
357 } | |
358 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
359 return strip(cleanPathSeperator(back)); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
360 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
361 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
362 /* query the environment for the debugger name */ |
697 | 363 char* getGDB(void){ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
364 char* back = getenv("GDB"); |
704 | 365 |
366 if(back==NULL){ | |
367 back = "gdb"; | |
368 } | |
369 | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
370 return strip(cleanPathSeperator(back)); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
371 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
372 |
734 | 373 char* getTortureBlock(void){ |
374 char* back = getenv("DSTRESS_TORTURE_BLOCK"); | |
375 | |
376 if(back!=NULL){ | |
377 back = strip(back); | |
378 if(strlen(back)<1){ | |
379 back = NULL; | |
380 } | |
381 } | |
382 | |
383 return back; | |
384 } | |
385 | |
499 | 386 /* 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
|
387 char* getCaseFlag(const char* data, const char* tag){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
388 char* begin; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
389 char* end1; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
390 char* end2; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
391 char* back; |
438 | 392 |
697 | 393 begin = NULL; |
394 end1 = NULL; | |
395 end2 = NULL; | |
396 back = NULL; | |
397 | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
398 if(data!=NULL && tag!=NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
399 begin = strstr(data, tag); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
400 if(begin!=NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
401 begin = begin+strlen(tag); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
402 end1 = strstr(begin, "\n"); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
403 end2 = strstr(begin, "\r"); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
404 if(end2!=NULL && ((end1!=NULL && end2<end1) || end1==NULL)){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
405 end1=end2; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
406 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
407 if(end1==NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
408 end1 = begin + strlen(begin); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
409 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
410 back = malloc(end1-begin+1); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
411 strncpy(back, begin, end1-begin); |
697 | 412 back[end1-begin]='\x00'; |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
413 return strip(cleanPathSeperator(back)); |
339
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 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
416 |
429 | 417 return calloc(1,1); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
418 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
419 |
499 | 420 /* check compile-time error messages */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
421 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
|
422 |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
423 char* file; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
424 char* line; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
425 char* dmd; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
426 char* gdc; |
697 | 427 size_t len; |
428 int back; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
429 |
697 | 430 file = NULL; |
431 line = NULL; | |
432 dmd = NULL; | |
433 gdc = NULL; | |
434 len = 0; | |
435 back = 0; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
436 |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
437 /* clean arguments */ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
438 if(strcmp(file_, "")!=0){ |
685 | 439 len = strlen(file_)+1; |
440 file = malloc(len); | |
441 strncpy(file, file_, len); | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
442 } |
438 | 443 |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
444 if(strcmp(line_, "")!=0){ |
685 | 445 len = strlen(line_)+1; |
446 line = malloc(len); | |
447 strncpy(line, line_, len); | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
448 } |
438 | 449 |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
450 /* gen patterns*/ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
451 if(file!=NULL){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
452 if(line!=NULL){ |
770 | 453 len = strlen(file)+strlen(line)+3; |
685 | 454 dmd = malloc(len); |
455 snprintf(dmd, len, "%s(%s)", file, line); | |
456 | |
457 gdc = malloc(len); | |
770 | 458 snprintf(gdc, len, "%s:%s", file, line); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
459 }else{ |
685 | 460 len = strlen(file)+2; |
461 dmd = malloc(len); | |
462 snprintf(dmd, len, "%s(", file); | |
622 | 463 |
685 | 464 gdc = malloc(len); |
465 snprintf(gdc, len, "%s:", file); | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
466 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
467 }else if(line!=NULL){ |
770 | 468 len = strlen(line)+3; |
685 | 469 dmd = malloc(len); |
770 | 470 snprintf(dmd, len, "(%s)", line); |
622 | 471 |
685 | 472 gdc = malloc(len); |
770 | 473 snprintf(gdc, len, ":%s", line); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
474 }else{ |
432 | 475 return 1; |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
476 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
477 |
438 | 478 /* specific error messages */ |
676 | 479 #ifdef DEBUG |
480 fprintf(stderr, "pattern(dmd):\t%s\n", dmd); | |
481 fprintf(stderr, "pattern(gdc):\t%s\n", gdc); | |
482 #endif | |
251 | 483 |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
484 if( (dmd!=NULL && strstr(buffer, dmd)) |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
485 || (gdc!=NULL && strstr(buffer, gdc)) |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
486 || (dmd==NULL && gdc==NULL)){ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
487 back=1; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
488 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
489 |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
490 return back; |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
491 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
492 |
432 | 493 int checkRuntimeErrorMessage(const char* file_, const char* line_, const char* buffer){ |
438 | 494 /* PhobosLong dir/file.d(2) |
490 | 495 * Phobos package.module(2) |
438 | 496 */ |
432 | 497 |
498 char* file; | |
499 char* line; | |
500 char* phobos; | |
501 char* phobosLong; | |
502 | |
503 char* begin; | |
439 | 504 char* end; |
685 | 505 size_t len; |
432 | 506 |
507 int back=0; | |
508 | |
697 | 509 file = NULL; |
510 line = NULL; | |
511 phobos = NULL; | |
512 phobosLong = NULL; | |
513 | |
514 begin = NULL; | |
515 end = NULL; | |
516 len = 0; | |
517 | |
432 | 518 /* clean arguments */ |
519 if(strcmp(file_, "")!=0){ | |
685 | 520 len = strlen(file_)+1; |
521 file = malloc(len); | |
522 strncpy(file, file_, len); | |
432 | 523 } |
438 | 524 |
432 | 525 if(strcmp(line_, "")!=0){ |
685 | 526 len = strlen(line_)+1; |
527 line = malloc(len); | |
528 strncpy(line, line_, len); | |
432 | 529 } |
438 | 530 |
432 | 531 /* gen patterns*/ |
532 if(file!=NULL){ | |
533 if(line!=NULL){ | |
685 | 534 len = strlen(file)+strlen(line)+5; |
535 phobos = malloc(len); | |
438 | 536 begin=strrchr(file,'/'); |
537 if(begin){ | |
432 | 538 begin++; |
539 }else{ | |
438 | 540 begin=strrchr(file,'\\'); |
541 if(begin){ | |
542 begin++; | |
543 }else{ | |
544 begin=file; | |
545 } | |
432 | 546 } |
439 | 547 end=strrchr(file,'.'); |
548 strncat(phobos, begin, end-begin); | |
685 | 549 snprintf(phobos, len, "%.*s(%s)", |
550 (int)(end-begin), begin, | |
551 line); | |
432 | 552 |
685 | 553 phobosLong = malloc(len); |
554 snprintf(phobosLong, len, "%s(%s)", file, line); | |
432 | 555 }else{ |
685 | 556 len = strlen(file)+2; |
557 phobos = malloc(len); | |
438 | 558 begin=strrchr(file,'/'); |
559 if(begin){ | |
432 | 560 begin++; |
561 }else{ | |
438 | 562 begin=strrchr(file,'\\'); |
563 if(begin){ | |
564 begin++; | |
565 }else{ | |
566 begin=file; | |
567 } | |
432 | 568 } |
439 | 569 end=strrchr(file,'.'); |
685 | 570 snprintf(phobos, len, "%.*s(", (int)(end-begin), begin); |
432 | 571 |
685 | 572 phobosLong = malloc(len); |
573 snprintf(phobosLong, len, "%s(", file); | |
432 | 574 } |
575 }else if(line!=NULL){ | |
685 | 576 len = strlen(line)+3; |
577 phobos = malloc(len); | |
578 snprintf(phobos, len, "(%s)", line); | |
438 | 579 |
432 | 580 phobosLong=NULL; |
581 }else{ | |
582 return 1; | |
583 } | |
584 | |
438 | 585 /* specific error messages */ |
432 | 586 |
676 | 587 #ifdef DEBUG |
588 fprintf(stderr, "pattern(phobosShort):\t%s\n", phobos); | |
589 fprintf(stderr, "pattern(phobosLong):\t%s\n", phobosLong); | |
590 #endif | |
591 | |
432 | 592 if( (phobos && strstr(buffer, phobos)) |
593 || (phobosLong && strstr(buffer, phobosLong))) | |
594 { | |
595 back=1; | |
596 } | |
438 | 597 |
598 return back; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
599 } |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
600 |
490 | 601 int hadExecCrash(const char* buffer){ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
602 if(strstr(buffer, "Segmentation fault") |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
603 || strstr(buffer, "Internal error") |
499 | 604 || strstr(buffer, "gcc.gnu.org/bugs") |
774 | 605 || strstr(buffer, "EXIT CODE: signal") |
606 || strstr(buffer, "Assertion failure") | |
607 || strstr(buffer, "Access Violation")) | |
490 | 608 { |
609 return 1; | |
610 } | |
611 return 0; | |
612 } | |
613 | |
499 | 614 /* system call with time-out */ |
734 | 615 int crashRun(const char* cmd, char** logFile){ |
746 | 616 |
697 | 617 size_t len; |
618 char* buffer; | |
619 | |
734 | 620 *logFile = genTempFileName(); |
746 | 621 #ifdef USE_POSIX |
734 | 622 len = 20 + strlen(CRASH_RUN) + strlen(cmd) + strlen(*logFile); |
697 | 623 buffer = malloc(len); |
624 | |
734 | 625 snprintf(buffer, len, "\"%s\" %s > %s 2>&1", CRASH_RUN, cmd, *logFile); |
697 | 626 |
490 | 627 system(buffer); |
734 | 628 buffer=loadFile(*logFile); |
490 | 629 |
630 if(strstr(buffer, "EXIT CODE: 0")){ | |
631 return EXIT_SUCCESS; | |
632 }else if(strstr(buffer, "EXIT CODE: 256") | |
633 || strstr(buffer, "EXIT CODE: timeout")) | |
634 { | |
635 return EXIT_FAILURE; | |
636 }else{ | |
637 return RAND_MAX; | |
638 } | |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
639 #elif defined USE_WINDOWS |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
640 PROCESS_INFORMATION processInfo; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
641 STARTUPINFO startupInfo; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
642 SECURITY_ATTRIBUTES sa = { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
643 sizeof(SECURITY_ATTRIBUTES), NULL, TRUE |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
644 }; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
645 HANDLE tLogFile; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
646 unsigned long exitCode; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
647 int timeLeft = 600; // time limit in iterations of WFX loop |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
648 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
649 memset(&processInfo, 0, sizeof(PROCESS_INFORMATION)); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
650 memset(&startupInfo, 0, sizeof(STARTUPINFO)); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
651 startupInfo.cb = sizeof(STARTUPINFO); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
652 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
653 tLogFile = CreateFile(*logFile, GENERIC_WRITE, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
654 0, &sa, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
655 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
656 if (tLogFile == NULL) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
657 printf("ERROR: could not open log file"); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
658 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
659 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
660 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
661 SetStdHandle(STD_OUTPUT_HANDLE, tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
662 SetStdHandle(STD_ERROR_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
663 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
664 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
|
665 &startupInfo, &processInfo)) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
666 void *message; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
667 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
668 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
669 | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
670 (char*) &message, 0, NULL); |
490 | 671 |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
672 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
673 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
674 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
675 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
676 // this should never happen |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
677 fprintf(stderr, "ERROR running %s:\n", cmd); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
678 fprintf(stderr, "%s\n", message); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
679 LocalFree((HLOCAL) message); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
680 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
681 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
682 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
683 // wait for exit |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
684 while (TRUE) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
685 GetExitCodeProcess(processInfo.hProcess, &exitCode); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
686 if (exitCode == 0x103) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
687 if (--timeLeft == 0) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
688 TerminateProcess(processInfo.hProcess, EXIT_FAILURE); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
689 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
690 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
691 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
692 printf("EXIT CODE: timeout\n"); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
693 Sleep(100); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
694 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
695 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
696 Sleep(100); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
697 } else { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
698 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
699 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
700 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
701 CloseHandle(tLogFile); |
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 printf("EXIT CODE: %i\n", exitCode); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
704 return exitCode; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
705 } |
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 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
708 #else /* USE_WINDOWS */ |
704 | 709 #error comment me out, if your test cases produce neither eternal loops nor Access Violations |
746 | 710 |
711 len = 10 + strlen(cmd) + strlen(*logFile); | |
712 buffer = malloc(len); | |
713 | |
714 snprintf(buffer, len, "%s > %s 2>&1", cmd, *logFile); | |
715 | |
716 int i = system(buffer); | |
703 | 717 fprintf(stderr, "EXIT CODE: %i\n", i); |
746 | 718 |
697 | 719 return i; |
490 | 720 #endif /* USE_POSIX else */ |
721 } | |
722 | |
734 | 723 int target_compile(int modus, char* compiler, char* arguments, char* case_file, |
724 char* error_file, char* error_line) | |
725 { | |
726 size_t bufferLen; | |
727 char* buffer; | |
728 int res; | |
729 int testResult; | |
730 int good_error; | |
731 char* logFile; | |
732 | |
733 bufferLen = 0; | |
734 buffer = NULL; | |
735 res = -1; | |
736 testResult = -1; | |
737 good_error = 0; | |
738 logFile = NULL; | |
739 | |
740 if(!(modus & MODE_COMPILE) && !(modus & MODE_NOCOMPILE)){ | |
741 fprintf(stderr, "BUG: badly handled mode %i (->compile)\n", | |
742 modus); | |
743 exit(EXIT_FAILURE); | |
744 } | |
745 | |
746 /* gen command */ | |
747 bufferLen = strlen(compiler) + strlen(arguments) + strlen(TMP_DIR) | |
748 + strlen(case_file) + 21; | |
749 buffer = malloc(bufferLen); | |
750 snprintf(buffer, bufferLen, "%s %s ", compiler, arguments); | |
751 | |
752 if(NULL == strstr(buffer, "-od")){ | |
753 snprintf(buffer, bufferLen, "%s %s -od%s -c %s", | |
754 compiler, arguments, TMP_DIR, case_file); | |
755 }else{ | |
756 snprintf(buffer, bufferLen, "%s %s -c %s", | |
757 compiler, arguments, case_file); | |
758 } | |
759 | |
760 /* test */ | |
761 if(modus & MODE_COMPILE){ | |
762 fprintf(stderr, "compile: %s\n", buffer); | |
763 }else{ | |
764 fprintf(stderr, "nocompile: %s\n", buffer); | |
765 } | |
766 res = crashRun(buffer, &logFile); | |
767 | |
768 /* diagnostic */ | |
769 buffer = loadFile(logFile); | |
770 fprintf(stderr, "%s\n", buffer); | |
771 remove(logFile); | |
772 good_error = checkErrorMessage(error_file, error_line, buffer); | |
773 | |
774 if(hadExecCrash(buffer)){ | |
775 testResult = RES_ERROR; | |
776 }else if(modus & MODE_COMPILE){ | |
777 if(res == EXIT_SUCCESS){ | |
778 testResult = RES_PASS; | |
779 }else if(res == EXIT_FAILURE){ | |
780 testResult = RES_FAIL | (good_error ? 0 : RES_BAD_MSG); | |
781 }else{ | |
782 testResult = RES_ERROR | (good_error ? 0 : RES_BAD_MSG); | |
783 } | |
784 }else{ | |
785 if(res == EXIT_FAILURE){ | |
786 if(good_error){ | |
787 testResult = RES_XFAIL; | |
788 }else{ | |
789 testResult = RES_FAIL | RES_BAD_MSG; | |
790 } | |
791 }else if(res == EXIT_SUCCESS){ | |
792 testResult = RES_XPASS; | |
793 }else{ | |
794 testResult = RES_ERROR; | |
795 } | |
796 } | |
797 | |
798 return testResult; | |
799 } | |
800 | |
801 int target_run(int modus, char* compiler, char* arguments, char* case_file, | |
802 char* error_file, char* error_line | |
803 #ifdef REG_EXTENDED | |
804 , char* gdb, char* gdb_script, regex_t* gdb_pattern | |
805 #endif | |
806 ) | |
807 { | |
808 size_t bufferLen; | |
809 char* buffer; | |
810 int res; | |
811 int testResult; | |
812 int good_error; | |
813 char* logFile; | |
814 char* gdb_scripter; | |
815 int good_gdb; | |
816 | |
817 bufferLen = 0; | |
818 buffer = NULL; | |
819 res = -1; | |
820 testResult = -1; | |
821 good_error = 0; | |
822 logFile = NULL; | |
823 good_gdb = 0; | |
824 gdb_scripter = NULL; | |
825 | |
826 if(!(modus & MODE_RUN) && !(modus & MODE_NORUN)){ | |
827 fprintf(stderr, "BUG: badly handled mode %i (->run)\n", modus); | |
828 exit(EXIT_FAILURE); | |
829 } | |
746 | 830 |
734 | 831 /* gen command */ |
832 | |
833 bufferLen = strlen(compiler) + strlen(arguments) + strlen(TMP_DIR) | |
834 + strlen(case_file) * 2 + 64; | |
835 buffer = malloc(bufferLen); | |
836 snprintf(buffer, bufferLen, "%s %s ", compiler, arguments); | |
837 | |
838 if(NULL == strstr(buffer, "-od")){ | |
839 if(NULL == strstr(buffer, "-of")){ | |
840 snprintf(buffer, bufferLen, | |
841 "%s %s -od%s -of%s.exe %s", | |
842 compiler, arguments, TMP_DIR, case_file, | |
843 case_file); | |
844 }else{ | |
845 snprintf(buffer, bufferLen, | |
846 "%s %s -od%s %s", | |
847 compiler, arguments, TMP_DIR, case_file); | |
848 } | |
849 }else if(NULL == strstr(buffer, "-of")){ | |
850 snprintf(buffer, bufferLen, | |
851 "%s %s -of%s.exe %s", | |
852 compiler, arguments, case_file, case_file); | |
853 }else{ | |
854 snprintf(buffer, bufferLen, "%s %s %s", | |
855 compiler, arguments, case_file); | |
856 } | |
857 | |
858 /* test 1/3 - compile */ | |
859 if(modus & MODE_RUN){ | |
860 fprintf(stderr, "run: %s\n", buffer); | |
861 }else{ | |
862 fprintf(stderr, "norun: %s\n", buffer); | |
863 } | |
864 res = crashRun(buffer, &logFile); | |
865 | |
866 /* diagnostic 1/3 */ | |
867 buffer = loadFile(logFile); | |
868 fprintf(stderr, "%s", buffer); | |
869 remove(logFile); | |
746 | 870 |
734 | 871 if(modus & MODE_RUN){ |
872 good_error = checkErrorMessage(error_file, error_line, | |
873 buffer); | |
874 }else{ | |
875 good_error = 1; | |
876 } | |
877 | |
878 if(hadExecCrash(buffer)){ | |
879 return RES_ERROR; | |
880 }else if((res == EXIT_FAILURE) && good_error){ | |
881 return RES_FAIL; | |
882 }else if(res!=EXIT_SUCCESS){ | |
883 return RES_ERROR | (good_error ? 0 : RES_BAD_MSG); | |
884 } | |
885 | |
886 /* test 2/3 - run */ | |
887 bufferLen = strlen(case_file) + 30; | |
888 buffer = malloc(bufferLen); | |
889 snprintf(buffer, bufferLen, "%s.exe", case_file); | |
890 fprintf(stderr, "%s\n", buffer); | |
891 res=crashRun(buffer, &logFile); | |
892 | |
893 /* diagnostic 2/3 */ | |
894 buffer = loadFile(logFile); | |
895 fprintf(stderr, "%s\n", buffer); | |
896 remove(logFile); | |
897 | |
898 if(modus & MODE_NORUN){ | |
899 good_error = checkRuntimeErrorMessage(error_file, error_line, | |
900 buffer); | |
901 }else{ | |
902 good_error = 1; | |
903 } | |
904 | |
905 #ifdef REG_EXTENDED | |
906 if(gdb_script != NULL){ | |
907 good_gdb = 0; | |
908 /* test 3/3 - gdb */ | |
909 gdb_scripter = genTempFileName(); | |
910 writeFile(gdb_scripter, gdb_script); | |
911 bufferLen = strlen(gdb) + strlen(case_file) | |
912 + strlen(gdb_scripter) + 20; | |
913 snprintf(buffer, bufferLen, "%s %s.exe < %s", | |
914 gdb, case_file, gdb_scripter); | |
915 fprintf(stderr, "%s\n", buffer); | |
916 if(EXIT_SUCCESS==crashRun(buffer, &logFile)){ | |
917 /* diagnostic 3/3 */ | |
918 buffer = loadFile(logFile); | |
919 fprintf(stderr, "%s\n", buffer); | |
920 good_gdb = (regexec(gdb_pattern, buffer, 0, NULL, 0)==0); | |
921 } | |
922 remove(logFile); | |
923 remove(gdb_scripter); | |
924 }else{ | |
925 good_gdb = 1; | |
926 } | |
746 | 927 #else |
928 good_gdb = 1; | |
734 | 929 #endif /* REG_EXTENDED */ |
930 | |
931 if(modus & MODE_RUN){ | |
932 if(hadExecCrash(buffer)){ | |
746 | 933 testResult = RES_ERROR; |
734 | 934 }else if((res==EXIT_SUCCESS) && good_gdb){ |
935 testResult = RES_PASS; | |
936 }else if((res==EXIT_FAILURE) && good_error && good_gdb){ | |
937 testResult = RES_FAIL; | |
938 }else{ | |
939 testResult = RES_ERROR | (good_error ? 0 : RES_BAD_MSG) | |
940 | (good_gdb ? 0 : RES_BAD_GDB); | |
941 } | |
942 }else{ | |
943 if(res==EXIT_SUCCESS){ | |
944 testResult = RES_XPASS; | |
945 }else if(good_error && good_gdb){ | |
946 testResult = RES_XFAIL; | |
947 }else{ | |
948 testResult = RES_FAIL | (good_error ? 0 : RES_BAD_MSG) | |
949 | (good_gdb ? 0 : RES_BAD_GDB); | |
950 } | |
951 } | |
952 | |
953 return testResult; | |
954 } | |
254 | 955 |
251 | 956 int main(int argc, char* arg[]){ |
746 | 957 |
438 | 958 char* compiler; /* the compiler - from enviroment flag "DMD" */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
959 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
|
960 char* buffer; /* general purpose buffer */ |
685 | 961 size_t bufferLen; |
734 | 962 int index; |
438 | 963 int modus; /* test modus: RUN NORUN COMPILE NOCOMPILE */ |
964 char* case_file; | |
734 | 965 int case_result; |
966 int torture_result[sizeof(torture)/sizeof(char*)]; | |
967 char* torture_block_global; | |
968 char* torture_block_case; | |
969 char* torture_require; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
970 char* error_file; /* expected sourcefile containing the error */ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
971 char* error_line; /* expected error line */ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
972 char* gdb; /* the debugger - from environment flag "GDB" */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
973 char* gdb_script; /* gdb command sequence */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
974 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
|
975 #ifdef REG_EXTENDED |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
976 regex_t* gdb_pattern; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
977 #endif |
438 | 978 |
697 | 979 compiler = NULL; |
980 cmd_arg_case = NULL; | |
981 buffer = NULL; | |
982 bufferLen = 0; | |
983 modus = -1; | |
984 case_file = NULL; | |
734 | 985 torture_block_global = NULL; |
986 torture_block_case = NULL; | |
987 torture_require = NULL; | |
697 | 988 error_file = NULL; |
989 error_line = NULL; | |
990 gdb = NULL; | |
991 gdb_script = NULL; | |
992 gdb_pattern_raw = NULL; | |
993 #ifdef REG_EXTENDED | |
994 gdb_pattern = NULL; | |
995 #endif | |
996 | |
251 | 997 /* check arguments */ |
998 if(argc != 3){ | |
438 | 999 err: |
704 | 1000 fprintf(stderr, "DStress test executer (revision 853)\n" |
1001 "Copyright by Thomas Kuehne <thomas@kuehne.cn> 2005\n" | |
1002 "\n"); | |
1003 | |
734 | 1004 if(argc!=0){ |
704 | 1005 fprintf(stderr, |
1006 "%s <run|norun|compile|nocompile> <source>\n", | |
1007 arg[0]); | |
734 | 1008 }else{ |
704 | 1009 fprintf(stderr, |
1010 "dstress <run|norun|compile|nocompile>" | |
1011 " <source>\n"); | |
734 | 1012 } |
704 | 1013 |
734 | 1014 fprintf(stderr, "\n" |
704 | 1015 "== eniroment settings (usually $NAME or %%NAME%%) ==\n" |
1016 "* DMD - compiler (including standard arguments)\n" | |
734 | 1017 "* GDB - debugger (including standard arguments)\n"); |
1018 fprintf(stderr, "\n" | |
704 | 1019 "== case setting (line in the case source) ==\n" |
1020 "* __DSTRESS_DFLAGS__ - additional compiler arguments\n" | |
1021 "only evaluated if it is a \"nocompile\" or \"norun\" test:\n" | |
1022 "* __DSTRESS_ELINE__ - expected source line to throw an error message\n" | |
1023 "* __DSTRESS_EFILE__ - expected source file to throw an error message\n" | |
734 | 1024 " (defaults to the case file)\n"); |
1025 fprintf(stderr, | |
704 | 1026 "only evaluated if it is a \"run\" or \"norun\" test:\n" |
1027 "* __GDB_SCRIPT__ - command sequence to feed to the debugger\n" | |
1028 " (use \\n to encode a line break)\n" | |
1029 "* __GDB_PATTERN__ - expected regular expression in the debugger's\n" | |
734 | 1030 " output\n"); |
1031 fprintf(stderr, "\n" | |
704 | 1032 "== note ==\n" |
710 | 1033 "* the current directory is required to contain the sub-directory \"obj\"\n" |
704 | 1034 " (used for temporary files)\n" |
1035 ); | |
438 | 1036 exit(EXIT_FAILURE); |
251 | 1037 } |
438 | 1038 |
734 | 1039 modus = 0; |
1040 if(0==strncmp(arg[1], TORTURE_PREFIX, strlen(TORTURE_PREFIX))){ | |
1041 modus |= MODE_TORTURE; | |
1042 arg[1] += strlen(TORTURE_PREFIX); | |
1043 } | |
704 | 1044 if(0==strcmp(arg[1], "run")){ |
734 | 1045 modus |= MODE_RUN; |
704 | 1046 }else if(0==strcmp(arg[1], "norun")){ |
734 | 1047 modus |= MODE_NORUN; |
704 | 1048 }else if(0==strcmp(arg[1], "compile")){ |
734 | 1049 modus |= MODE_COMPILE; |
704 | 1050 }else if(0==strcmp(arg[1], "nocompile")){ |
734 | 1051 modus |= MODE_NOCOMPILE; |
251 | 1052 }else{ |
1053 goto err; | |
1054 } | |
1055 | |
1056 /* gen flags */ | |
438 | 1057 case_file = cleanPathSeperator(strdup(arg[2])); |
251 | 1058 compiler = getCompiler(); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1059 gdb = getGDB(); |
734 | 1060 torture_block_global = getTortureBlock(); |
438 | 1061 buffer = loadFile(case_file); |
1062 | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1063 cmd_arg_case = getCaseFlag(buffer, "__DSTRESS_DFLAGS__"); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1064 error_line = getCaseFlag(buffer, "__DSTRESS_ELINE__"); |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1065 error_file = getCaseFlag(buffer, "__DSTRESS_EFILE__"); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1066 gdb_script = getCaseFlag(buffer, "__GDB_SCRIPT__"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1067 gdb_pattern_raw = getCaseFlag(buffer, "__GDB_PATTERN__"); |
734 | 1068 torture_block_case = getCaseFlag(buffer, "__DSTRESS_TORTURE_BLOCK__"); |
1069 torture_require = getCaseFlag(buffer, "__DSTRESS_TORTURE_REQUIRE__"); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1070 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1071 /* set implicit source file */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1072 if(strcmp(error_line, "")!=0 && strcmp(error_file, "")==0){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1073 error_file=case_file; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1074 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1075 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1076 /* gdb pattern */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1077 #ifdef REG_EXTENDED |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1078 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
|
1079 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1080 gdb_pattern = malloc(sizeof(regex_t)); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1081 if(regcomp(gdb_pattern, gdb_pattern_raw, REG_EXTENDED)){ |
704 | 1082 fprintf(stderr, "failed to compile regular expression:" |
1083 "\n\t%s\n", gdb_pattern_raw); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1084 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1085 }else if(gdb_script==NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1086 fprintf(stderr, "GDB pattern without GDB script\n"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1087 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1088 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1089 }else{ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1090 gdb_pattern = NULL; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1091 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1092 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1093 /* gdb script */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1094 if(gdb_script!=NULL && gdb_script[0]!='\x00'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1095 if(gdb_pattern==NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1096 fprintf(stderr, "GDB script without GDB pattern\n"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1097 exit(EXIT_FAILURE); |
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 buffer=gdb_script; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1100 for(; *buffer; buffer++){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1101 if(buffer[0]=='\\'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1102 if(buffer[1]=='n'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1103 buffer[0]=' '; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1104 buffer[1]='\n'; |
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++; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1107 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1108 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1109 |
685 | 1110 bufferLen = strlen(gdb_script)+11; |
1111 buffer=malloc(bufferLen); | |
1112 snprintf(buffer, bufferLen, "%s\n\nquit\ny\n\n", gdb_script); | |
1113 gdb_script=buffer; | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1114 }else{ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1115 gdb_script = NULL; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1116 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1117 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1118 #else |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1119 |
704 | 1120 if(gdb_script && strlen(gdb_script)){ |
1121 if(gdb_pattern_raw && strlen(gdb_pattern_raw)){ | |
734 | 1122 fprintf(stderr, "WARNING: GDB/regex support inactive\n"); |
704 | 1123 }else{ |
734 | 1124 fprintf(stderr, "GDB script without GDB pattern\n"); |
704 | 1125 exit(EXIT_FAILURE); |
1126 } | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1127 }else if(gdb_pattern_raw && strlen(gdb_pattern_raw)){ |
734 | 1128 fprintf(stderr, "GDB pattern without GDB script\n"); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1129 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1130 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1131 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1132 #endif /* REG_EXTENDED else */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1133 |
493 | 1134 #ifdef DEBUG |
438 | 1135 fprintf(stderr, "case: \"%s\"\n", case_file); |
1136 fprintf(stderr, "compiler: \"%s\"\n", compiler); | |
1137 fprintf(stderr, "DFLAGS C: \"%s\"\n", cmd_arg_case); | |
1138 fprintf(stderr, "ELINE : \"%s\"\n", error_line); | |
1139 fprintf(stderr, "EFILE : \"%s\"\n", error_file); | |
734 | 1140 #ifdef REG_EXTENDED |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1141 fprintf(stderr, "GDB Scri: \"%s\"\n", gdb_script); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1142 fprintf(stderr, "GDB Patt: \"%s\"\n", gdb_pattern_raw); |
438 | 1143 #endif |
734 | 1144 fprintf(stderr, "block G : \"%s\"\n", torture_block_global); |
1145 fprintf(stderr, "block C : \"%s\"\n", torture_block_case); | |
1146 fprintf(stderr, "modus : %x\n", modus); | |
1147 #endif | |
685 | 1148 |
251 | 1149 |
734 | 1150 /* let's get serious */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1151 #ifdef USE_WINDOWS |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1152 originalStdout = GetStdHandle(STD_OUTPUT_HANDLE); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1153 originalStderr = GetStdHandle(STD_ERROR_HANDLE); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1154 #endif |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1155 |
734 | 1156 if(modus & MODE_TORTURE){ |
746 | 1157 if((modus & (MODE_COMPILE | MODE_NOCOMPILE)) |
734 | 1158 && (modus & (MODE_RUN | MODE_NORUN))) |
1159 { | |
1160 fprintf(stderr, "BUG: unhandled torture modus %x\n", modus); | |
1161 }else if(!(modus & (MODE_COMPILE | MODE_NOCOMPILE | MODE_RUN | MODE_NORUN))){ | |
1162 fprintf(stderr, "BUG: unhandled torture modus %x\n", modus); | |
251 | 1163 } |
1164 | |
734 | 1165 bufferLen = strlen(torture[(sizeof(torture) / sizeof(char*))-1]) |
1166 + strlen(cmd_arg_case) + 3; | |
746 | 1167 |
734 | 1168 if(torture_block_case!=NULL && strlen(torture_block_case)<1){ |
1169 torture_block_case=NULL; | |
676 | 1170 } |
746 | 1171 |
734 | 1172 buffer = malloc(bufferLen); |
1173 for(index=0; index < sizeof(torture)/sizeof(char*); index++){ | |
1174 if((torture_block_global && strstr(torture[index], torture_block_global)) | |
1175 || (torture_block_case && strstr(torture[index], torture_block_case)) | |
1176 || (torture_block_case && !strstr(torture[index], torture_require))) | |
1177 { | |
1178 torture_result[index]=RES_UNTESTED; | |
1179 continue; | |
1180 } | |
746 | 1181 |
734 | 1182 buffer[0]=0; |
1183 snprintf(buffer, bufferLen, "%s %s", torture[index], cmd_arg_case); | |
746 | 1184 |
734 | 1185 if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){ |
1186 torture_result[index] = target_compile(modus, | |
1187 compiler, buffer, case_file, | |
1188 error_file, error_line); | |
1189 }else if(modus & (MODE_RUN | MODE_NORUN)){ | |
1190 torture_result[index] = target_run(modus, | |
1191 compiler, buffer, case_file, | |
1192 error_file, error_line | |
1193 #ifdef REG_EXTENDED | |
1194 , gdb, gdb_script, gdb_pattern | |
1195 #endif | |
1196 ); | |
1197 } | |
438 | 1198 |
734 | 1199 fprintf(stderr, "Torture-Sub-%i/" ZU "-", index+1, |
1200 sizeof(torture)/sizeof(char*)); | |
1201 printResult(torture_result[index], modus, case_file, | |
1202 stderr); | |
1203 fprintf(stderr, "--------\n"); | |
685 | 1204 } |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1205 |
734 | 1206 printf("Torture:\t%s\t{", case_file); |
1207 for(index=0; index < sizeof(torture)/sizeof(char*); index++){ | |
1208 case_result = 0; | |
1209 switch(torture_result[index] & RES_BASE_MASK){ | |
1210 case RES_UNTESTED: case_result = 0; break; | |
1211 case RES_PASS: case_result = 1 << 2; break; | |
1212 case RES_XFAIL: case_result = 2 << 2; break; | |
1213 case RES_XPASS: case_result = 3 << 2; break; | |
1214 case RES_FAIL: case_result = 4 << 2; break; | |
1215 case RES_ERROR: case_result = 5 << 2; break; | |
1216 default: | |
1217 fprintf(stderr, "BUG: unexpected case result %i\n", | |
1218 torture_result[index]); | |
1219 exit(EXIT_FAILURE); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1220 } |
746 | 1221 |
734 | 1222 if(torture_result[index] & RES_BAD_MSG){ |
1223 case_result |= 1; | |
1224 } | |
1225 if(torture_result[index] & RES_BAD_GDB){ | |
1226 case_result |= 2; | |
1227 } | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1228 |
734 | 1229 printf("%c", 'A' + case_result); |
251 | 1230 } |
734 | 1231 printf("}\n"); |
251 | 1232 }else{ |
734 | 1233 /* start working */ |
1234 if(modus & (MODE_RUN | MODE_NORUN)){ | |
1235 case_result = target_run(modus, compiler, cmd_arg_case, | |
1236 case_file, error_file, error_line | |
1237 #ifdef REG_EXTENDED | |
1238 , gdb, gdb_script, gdb_pattern | |
1239 #endif | |
1240 ); | |
880 | 1241 }else if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){ |
734 | 1242 case_result = target_compile(modus, compiler, |
1243 cmd_arg_case, case_file, error_file, | |
1244 error_line); | |
881 | 1245 }else{ |
1246 fprintf(stderr, "BUG: unhandled non-torture modus %x\n", modus); | |
734 | 1247 } |
880 | 1248 |
1249 fprintf(stdout, "Torture-Sub-1/" ZU "-", | |
1250 sizeof(torture)/sizeof(char*)); | |
1251 printResult(case_result, modus, case_file, stdout); | |
251 | 1252 } |
734 | 1253 |
746 | 1254 |
436 | 1255 return EXIT_SUCCESS; |
251 | 1256 } |