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