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