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