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