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