Mercurial > projects > dstress
annotate dstress.c @ 999:69f95c134121
added conditional result capabilities
author | thomask |
---|---|
date | Wed, 17 May 2006 04:57:35 +0000 |
parents | 94714c219f3b |
children | ab5680607b8d |
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 | |
999 | 691 int conditionalResult(const char* buffer){ |
692 if(strstr(buffer, "DSTRESS{XFAIL}")){ | |
693 return RES_XFAIL; | |
694 }else if(strstr(buffer, "DSTRESS{XPASS}")){ | |
695 return RES_XPASS; | |
696 }else if(strstr(buffer, "DSTRESS{FAIL}")){ | |
697 return RES_FAIL; | |
698 }else if(strstr(buffer, "DSTRESS{PASS}")){ | |
699 return RES_PASS; | |
700 }else if(strstr(buffer, "DSTRESS{ERROR}")){ | |
701 return RES_ERROR; | |
702 }else{ | |
703 return 0; | |
704 } | |
705 | |
706 } | |
707 | |
499 | 708 /* system call with time-out */ |
734 | 709 int crashRun(const char* cmd, char** logFile){ |
746 | 710 |
697 | 711 size_t len; |
712 char* buffer; | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
713 int back; |
986 | 714 #ifdef USE_WINDOWS |
715 PROCESS_INFORMATION processInfo; | |
716 STARTUPINFO startupInfo; | |
717 SECURITY_ATTRIBUTES sa = { | |
718 sizeof(SECURITY_ATTRIBUTES), NULL, TRUE | |
719 }; | |
720 HANDLE tLogFile; | |
721 unsigned long exitCode; | |
722 int timeLeft = 600; /* time limit in iterations of WFX loop */ | |
723 #endif | |
697 | 724 |
734 | 725 *logFile = genTempFileName(); |
746 | 726 #ifdef USE_POSIX |
734 | 727 len = 20 + strlen(CRASH_RUN) + strlen(cmd) + strlen(*logFile); |
697 | 728 buffer = malloc(len); |
729 | |
940 | 730 snprintf(buffer, len, "%s %s > %s 2>&1", CRASH_RUN, cmd, *logFile); |
697 | 731 |
490 | 732 system(buffer); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
733 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
734 |
902 | 735 buffer=loadFile(*logFile, &len); |
490 | 736 |
902 | 737 /* @todo@ use: len */ |
490 | 738 if(strstr(buffer, "EXIT CODE: 0")){ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
739 back = EXIT_SUCCESS; |
490 | 740 }else if(strstr(buffer, "EXIT CODE: 256") |
741 || strstr(buffer, "EXIT CODE: timeout")) | |
742 { | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
743 back = EXIT_FAILURE; |
490 | 744 }else{ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
745 back = RAND_MAX; |
490 | 746 } |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
747 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
748 |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
749 return back; |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
750 #elif defined USE_WINDOWS |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
751 memset(&processInfo, 0, sizeof(PROCESS_INFORMATION)); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
752 memset(&startupInfo, 0, sizeof(STARTUPINFO)); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
753 startupInfo.cb = sizeof(STARTUPINFO); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
754 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
755 tLogFile = CreateFile(*logFile, GENERIC_WRITE, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
756 0, &sa, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
757 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
758 if (tLogFile == NULL) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
759 printf("ERROR: could not open log file"); |
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 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
763 SetStdHandle(STD_OUTPUT_HANDLE, tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
764 SetStdHandle(STD_ERROR_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
765 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
766 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
|
767 &startupInfo, &processInfo)) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
768 void *message; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
769 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
770 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
771 | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
772 (char*) &message, 0, NULL); |
490 | 773 |
888
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 |
902 | 778 /* this should never happen */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
779 fprintf(stderr, "ERROR running %s:\n", cmd); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
780 fprintf(stderr, "%s\n", message); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
781 LocalFree((HLOCAL) message); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
782 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
783 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
784 |
902 | 785 /* wait for exit */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
786 while (TRUE) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
787 GetExitCodeProcess(processInfo.hProcess, &exitCode); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
788 if (exitCode == 0x103) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
789 if (--timeLeft == 0) { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
790 TerminateProcess(processInfo.hProcess, EXIT_FAILURE); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
791 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
792 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
793 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
794 printf("EXIT CODE: timeout\n"); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
795 Sleep(100); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
796 return RAND_MAX; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
797 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
798 Sleep(100); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
799 } else { |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
800 SetStdHandle(STD_OUTPUT_HANDLE, originalStdout); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
801 SetStdHandle(STD_ERROR_HANDLE, originalStderr); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
802 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
803 CloseHandle(tLogFile); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
804 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
805 printf("EXIT CODE: %i\n", exitCode); |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
806 return exitCode; |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
807 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
808 } |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
809 |
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
810 #else /* USE_WINDOWS */ |
704 | 811 #error comment me out, if your test cases produce neither eternal loops nor Access Violations |
746 | 812 |
813 len = 10 + strlen(cmd) + strlen(*logFile); | |
814 buffer = malloc(len); | |
815 | |
816 snprintf(buffer, len, "%s > %s 2>&1", cmd, *logFile); | |
817 | |
818 int i = system(buffer); | |
902 | 819 printf("EXIT CODE: %i\n", i); |
746 | 820 |
697 | 821 return i; |
490 | 822 #endif /* USE_POSIX else */ |
823 } | |
824 | |
734 | 825 int target_compile(int modus, char* compiler, char* arguments, char* case_file, |
826 char* error_file, char* error_line) | |
827 { | |
828 size_t bufferLen; | |
829 char* buffer; | |
830 int res; | |
831 int testResult; | |
832 int good_error; | |
833 char* logFile; | |
834 | |
835 bufferLen = 0; | |
836 buffer = NULL; | |
837 res = -1; | |
838 testResult = -1; | |
839 good_error = 0; | |
840 logFile = NULL; | |
841 | |
842 if(!(modus & MODE_COMPILE) && !(modus & MODE_NOCOMPILE)){ | |
843 fprintf(stderr, "BUG: badly handled mode %i (->compile)\n", | |
844 modus); | |
845 exit(EXIT_FAILURE); | |
846 } | |
847 | |
848 /* gen command */ | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
849 bufferLen = strlen(compiler) + strlen(arguments) + strlen(tmp_dir) |
734 | 850 + strlen(case_file) + 21; |
851 buffer = malloc(bufferLen); | |
852 snprintf(buffer, bufferLen, "%s %s ", compiler, arguments); | |
853 | |
854 if(NULL == strstr(buffer, "-od")){ | |
855 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
|
856 compiler, arguments, tmp_dir, case_file); |
734 | 857 }else{ |
858 snprintf(buffer, bufferLen, "%s %s -c %s", | |
859 compiler, arguments, case_file); | |
860 } | |
861 | |
862 /* test */ | |
863 if(modus & MODE_COMPILE){ | |
902 | 864 printf("compile: %s\n", buffer); |
734 | 865 }else{ |
902 | 866 printf("nocompile: %s\n", buffer); |
734 | 867 } |
868 res = crashRun(buffer, &logFile); | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
869 free(buffer); |
734 | 870 |
871 /* diagnostic */ | |
902 | 872 buffer = loadFile(logFile, &bufferLen); |
873 printf("%.*s\n", (int)bufferLen, buffer); | |
734 | 874 remove(logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
875 free(logFile); |
734 | 876 good_error = checkErrorMessage(error_file, error_line, buffer); |
877 | |
999 | 878 testResult = conditionalResult(buffer); |
879 | |
880 if(testResult){ | |
881 /* conditional result */ | |
882 }else if(hadExecCrash(buffer)){ | |
734 | 883 testResult = RES_ERROR; |
884 }else if(modus & MODE_COMPILE){ | |
885 if(res == EXIT_SUCCESS){ | |
886 testResult = RES_PASS; | |
887 }else if(res == EXIT_FAILURE){ | |
888 testResult = RES_FAIL | (good_error ? 0 : RES_BAD_MSG); | |
889 }else{ | |
890 testResult = RES_ERROR | (good_error ? 0 : RES_BAD_MSG); | |
891 } | |
892 }else{ | |
893 if(res == EXIT_FAILURE){ | |
894 if(good_error){ | |
895 testResult = RES_XFAIL; | |
896 }else{ | |
897 testResult = RES_FAIL | RES_BAD_MSG; | |
898 } | |
899 }else if(res == EXIT_SUCCESS){ | |
900 testResult = RES_XPASS; | |
901 }else{ | |
902 testResult = RES_ERROR; | |
903 } | |
904 } | |
905 | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
906 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
907 |
734 | 908 return testResult; |
909 } | |
910 | |
911 int target_run(int modus, char* compiler, char* arguments, char* case_file, | |
912 char* error_file, char* error_line | |
913 #ifdef REG_EXTENDED | |
914 , char* gdb, char* gdb_script, regex_t* gdb_pattern | |
915 #endif | |
916 ) | |
917 { | |
918 size_t bufferLen; | |
919 char* buffer; | |
920 int res; | |
921 int testResult; | |
922 int good_error; | |
923 char* logFile; | |
924 char* gdb_scripter; | |
925 int good_gdb; | |
926 | |
927 bufferLen = 0; | |
928 buffer = NULL; | |
929 res = -1; | |
930 testResult = -1; | |
931 good_error = 0; | |
932 logFile = NULL; | |
933 good_gdb = 0; | |
934 gdb_scripter = NULL; | |
935 | |
936 if(!(modus & MODE_RUN) && !(modus & MODE_NORUN)){ | |
937 fprintf(stderr, "BUG: badly handled mode %i (->run)\n", modus); | |
938 exit(EXIT_FAILURE); | |
939 } | |
746 | 940 |
734 | 941 /* gen command */ |
942 | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
943 bufferLen = strlen(compiler) + strlen(arguments) + strlen(tmp_dir) |
734 | 944 + strlen(case_file) * 2 + 64; |
945 buffer = malloc(bufferLen); | |
946 snprintf(buffer, bufferLen, "%s %s ", compiler, arguments); | |
947 | |
948 if(NULL == strstr(buffer, "-od")){ | |
949 if(NULL == strstr(buffer, "-of")){ | |
950 snprintf(buffer, bufferLen, | |
951 "%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
|
952 compiler, arguments, tmp_dir, case_file, |
734 | 953 case_file); |
954 }else{ | |
955 snprintf(buffer, bufferLen, | |
956 "%s %s -od%s %s", | |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
957 compiler, arguments, tmp_dir, case_file); |
734 | 958 } |
959 }else if(NULL == strstr(buffer, "-of")){ | |
960 snprintf(buffer, bufferLen, | |
961 "%s %s -of%s.exe %s", | |
962 compiler, arguments, case_file, case_file); | |
963 }else{ | |
964 snprintf(buffer, bufferLen, "%s %s %s", | |
965 compiler, arguments, case_file); | |
966 } | |
967 | |
968 /* test 1/3 - compile */ | |
969 if(modus & MODE_RUN){ | |
902 | 970 printf("run: %s\n", buffer); |
734 | 971 }else{ |
902 | 972 printf("norun: %s\n", buffer); |
734 | 973 } |
974 res = crashRun(buffer, &logFile); | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
975 free(buffer); |
734 | 976 |
977 /* diagnostic 1/3 */ | |
902 | 978 buffer = loadFile(logFile, &bufferLen); |
979 printf("%.*s", (int)bufferLen, buffer); | |
734 | 980 remove(logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
981 free(logFile); |
746 | 982 |
734 | 983 if(modus & MODE_RUN){ |
984 good_error = checkErrorMessage(error_file, error_line, | |
985 buffer); | |
986 }else{ | |
987 good_error = 1; | |
988 } | |
989 | |
999 | 990 testResult = conditionalResult(buffer); |
734 | 991 if(hadExecCrash(buffer)){ |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
992 free(buffer); |
734 | 993 return RES_ERROR; |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
994 }else{ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
995 free(buffer); |
999 | 996 if(testResult){ |
997 return testResult; | |
998 }else if((res == EXIT_FAILURE) && good_error){ | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
999 return RES_FAIL; |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1000 }else if(res!=EXIT_SUCCESS){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1001 return RES_ERROR | (good_error ? 0 : RES_BAD_MSG); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1002 } |
734 | 1003 } |
1004 | |
1005 /* test 2/3 - run */ | |
985 | 1006 if((modus & MODE_NORUN) && (strstr(case_file, "/asm_") |
991 | 1007 || strstr(case_file, "\\asm_") |
1008 || (case_file == strstr(case_file, "asm_")))) | |
985 | 1009 { |
1010 /* Valgrind doesn't support privileged instructions */ | |
1011 goto no_valgrind; | |
991 | 1012 }else if(strstr(case_file, "/asm_") || strstr(case_file, "\\asm_") |
1013 || (case_file == strstr(case_file, "asm_"))) | |
1014 { | |
985 | 1015 /* FIXME asm workaround due to Valgrind bugs (mainly SSE3) */ |
1016 goto no_valgrind; | |
991 | 1017 }else if(VALGRIND){ |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1018 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
|
1019 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1020 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
|
1021 }else{ |
985 | 1022 no_valgrind: |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1023 bufferLen = strlen(case_file) + 8; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1024 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1025 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
|
1026 } |
902 | 1027 printf("%s\n", buffer); |
734 | 1028 res=crashRun(buffer, &logFile); |
999 | 1029 testResult = conditionalResult(buffer); |
1030 if(testResult){ | |
1031 free(buffer); | |
1032 return testResult; | |
1033 } | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1034 free(buffer); |
734 | 1035 |
1036 /* diagnostic 2/3 */ | |
902 | 1037 buffer = loadFile(logFile, &bufferLen); |
1038 printf("%.*s\n", (int) bufferLen, buffer); | |
734 | 1039 remove(logFile); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1040 free(logFile); |
734 | 1041 |
1042 if(modus & MODE_NORUN){ | |
1043 good_error = checkRuntimeErrorMessage(error_file, error_line, | |
1044 buffer); | |
1045 }else{ | |
1046 good_error = 1; | |
1047 } | |
1048 | |
1049 #ifdef REG_EXTENDED | |
968 | 1050 if(((res==EXIT_SUCCESS && (modus & MODE_RUN)) |
1051 ||(res==EXIT_SUCCESS && (modus & MODE_RUN))) | |
1052 && gdb_script != NULL) | |
1053 { | |
999 | 1054 testResult = conditionalResult(buffer); |
1055 if(testResult){ | |
1056 return testResult; | |
1057 } | |
1058 | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1059 free(buffer); |
734 | 1060 good_gdb = 0; |
1061 /* test 3/3 - gdb */ | |
1062 gdb_scripter = genTempFileName(); | |
1063 writeFile(gdb_scripter, gdb_script); | |
1064 bufferLen = strlen(gdb) + strlen(case_file) | |
1065 + strlen(gdb_scripter) + 20; | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1066 buffer = malloc(bufferLen); |
734 | 1067 snprintf(buffer, bufferLen, "%s %s.exe < %s", |
1068 gdb, case_file, gdb_scripter); | |
902 | 1069 printf("%s\n", buffer); |
734 | 1070 if(EXIT_SUCCESS==crashRun(buffer, &logFile)){ |
1071 /* diagnostic 3/3 */ | |
902 | 1072 buffer = loadFile(logFile, &bufferLen); |
1073 printf("%.*s\n", (int)bufferLen, buffer); | |
734 | 1074 good_gdb = (regexec(gdb_pattern, buffer, 0, NULL, 0)==0); |
1075 } | |
1076 remove(logFile); | |
1077 remove(gdb_scripter); | |
1078 }else{ | |
1079 good_gdb = 1; | |
1080 } | |
746 | 1081 #else |
1082 good_gdb = 1; | |
902 | 1083 #endif /* REG_EXTENDED else */ |
734 | 1084 |
999 | 1085 testResult = conditionalResult(buffer); |
1086 if(testResult){ | |
1087 return testResult; | |
1088 } | |
1089 | |
734 | 1090 if(modus & MODE_RUN){ |
1091 if(hadExecCrash(buffer)){ | |
746 | 1092 testResult = RES_ERROR; |
734 | 1093 }else if((res==EXIT_SUCCESS) && good_gdb){ |
1094 testResult = RES_PASS; | |
1095 }else if((res==EXIT_FAILURE) && good_error && good_gdb){ | |
1096 testResult = RES_FAIL; | |
1097 }else{ | |
1098 testResult = RES_ERROR | (good_error ? 0 : RES_BAD_MSG) | |
1099 | (good_gdb ? 0 : RES_BAD_GDB); | |
1100 } | |
1101 }else{ | |
1102 if(res==EXIT_SUCCESS){ | |
1103 testResult = RES_XPASS; | |
1104 }else if(good_error && good_gdb){ | |
1105 testResult = RES_XFAIL; | |
1106 }else{ | |
1107 testResult = RES_FAIL | (good_error ? 0 : RES_BAD_MSG) | |
1108 | (good_gdb ? 0 : RES_BAD_GDB); | |
1109 } | |
1110 } | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1111 free(buffer); |
734 | 1112 |
1113 return testResult; | |
1114 } | |
254 | 1115 |
251 | 1116 int main(int argc, char* arg[]){ |
746 | 1117 |
438 | 1118 char* compiler; /* the compiler - from enviroment flag "DMD" */ |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1119 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
|
1120 char* buffer; /* general purpose buffer */ |
685 | 1121 size_t bufferLen; |
734 | 1122 int index; |
438 | 1123 int modus; /* test modus: RUN NORUN COMPILE NOCOMPILE */ |
1124 char* case_file; | |
734 | 1125 int case_result; |
1126 int torture_result[sizeof(torture)/sizeof(char*)]; | |
1127 char* torture_block_global; | |
1128 char* torture_block_case; | |
1129 char* torture_require; | |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1130 char* error_file; /* expected sourcefile containing the error */ |
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1131 char* error_line; /* expected error line */ |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1132 char* gdb; /* the debugger - from environment flag "GDB" */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1133 char* gdb_script; /* gdb command sequence */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1134 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
|
1135 #ifdef REG_EXTENDED |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1136 regex_t* gdb_pattern; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1137 #endif |
438 | 1138 |
697 | 1139 compiler = NULL; |
1140 cmd_arg_case = NULL; | |
1141 buffer = NULL; | |
1142 bufferLen = 0; | |
1143 modus = -1; | |
1144 case_file = NULL; | |
734 | 1145 torture_block_global = NULL; |
1146 torture_block_case = NULL; | |
1147 torture_require = NULL; | |
697 | 1148 error_file = NULL; |
1149 error_line = NULL; | |
1150 gdb = NULL; | |
1151 gdb_script = NULL; | |
1152 gdb_pattern_raw = NULL; | |
1153 #ifdef REG_EXTENDED | |
1154 gdb_pattern = NULL; | |
1155 #endif | |
1156 | |
251 | 1157 /* check arguments */ |
1158 if(argc != 3){ | |
438 | 1159 err: |
902 | 1160 fprintf(stderr, "DStress test executer (revision 1083)\n" |
1161 "Copyright by Thomas Kuehne <thomas@kuehne.cn> 2005, 2006\n" | |
704 | 1162 "\n"); |
1163 | |
734 | 1164 if(argc!=0){ |
704 | 1165 fprintf(stderr, |
1166 "%s <run|norun|compile|nocompile> <source>\n", | |
1167 arg[0]); | |
734 | 1168 }else{ |
704 | 1169 fprintf(stderr, |
1170 "dstress <run|norun|compile|nocompile>" | |
1171 " <source>\n"); | |
734 | 1172 } |
704 | 1173 |
734 | 1174 fprintf(stderr, "\n" |
704 | 1175 "== eniroment settings (usually $NAME or %%NAME%%) ==\n" |
1176 "* DMD - compiler (including standard arguments)\n" | |
734 | 1177 "* GDB - debugger (including standard arguments)\n"); |
1178 fprintf(stderr, "\n" | |
704 | 1179 "== case setting (line in the case source) ==\n" |
1180 "* __DSTRESS_DFLAGS__ - additional compiler arguments\n" | |
1181 "only evaluated if it is a \"nocompile\" or \"norun\" test:\n" | |
1182 "* __DSTRESS_ELINE__ - expected source line to throw an error message\n" | |
1183 "* __DSTRESS_EFILE__ - expected source file to throw an error message\n" | |
734 | 1184 " (defaults to the case file)\n"); |
1185 fprintf(stderr, | |
704 | 1186 "only evaluated if it is a \"run\" or \"norun\" test:\n" |
1187 "* __GDB_SCRIPT__ - command sequence to feed to the debugger\n" | |
1188 " (use \\n to encode a line break)\n" | |
1189 "* __GDB_PATTERN__ - expected regular expression in the debugger's\n" | |
734 | 1190 " output\n"); |
1191 fprintf(stderr, "\n" | |
704 | 1192 "== note ==\n" |
710 | 1193 "* the current directory is required to contain the sub-directory \"obj\"\n" |
704 | 1194 " (used for temporary files)\n" |
1195 ); | |
438 | 1196 exit(EXIT_FAILURE); |
251 | 1197 } |
438 | 1198 |
734 | 1199 modus = 0; |
1200 if(0==strncmp(arg[1], TORTURE_PREFIX, strlen(TORTURE_PREFIX))){ | |
1201 modus |= MODE_TORTURE; | |
1202 arg[1] += strlen(TORTURE_PREFIX); | |
1203 } | |
704 | 1204 if(0==strcmp(arg[1], "run")){ |
734 | 1205 modus |= MODE_RUN; |
704 | 1206 }else if(0==strcmp(arg[1], "norun")){ |
734 | 1207 modus |= MODE_NORUN; |
704 | 1208 }else if(0==strcmp(arg[1], "compile")){ |
734 | 1209 modus |= MODE_COMPILE; |
704 | 1210 }else if(0==strcmp(arg[1], "nocompile")){ |
734 | 1211 modus |= MODE_NOCOMPILE; |
251 | 1212 }else{ |
1213 goto err; | |
1214 } | |
1215 | |
1216 /* gen flags */ | |
902 | 1217 case_file = cleanPathSeperator(arg[2]); |
251 | 1218 compiler = getCompiler(); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1219 gdb = getGDB(); |
734 | 1220 torture_block_global = getTortureBlock(); |
902 | 1221 buffer = loadFile(case_file, &bufferLen); |
1222 bufferLen = 0; | |
438 | 1223 |
968 | 1224 cmd_arg_case = cleanPathSeperator(getCaseFlag(buffer, "__DSTRESS_DFLAGS__")); |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1225 error_line = getCaseFlag(buffer, "__DSTRESS_ELINE__"); |
968 | 1226 error_file = cleanPathSeperator(getCaseFlag(buffer, "__DSTRESS_EFILE__")); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1227 gdb_script = getCaseFlag(buffer, "__GDB_SCRIPT__"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1228 gdb_pattern_raw = getCaseFlag(buffer, "__GDB_PATTERN__"); |
734 | 1229 torture_block_case = getCaseFlag(buffer, "__DSTRESS_TORTURE_BLOCK__"); |
1230 torture_require = getCaseFlag(buffer, "__DSTRESS_TORTURE_REQUIRE__"); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1231 |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1232 free(buffer); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1233 |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1234 /* tmp_dir */ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1235 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
|
1236 tmp_dir = TMP_DIR; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1237 }else{ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1238 pid_t pid; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1239 pid = getpid(); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1240 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
|
1241 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1242 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
|
1243 tmp_dir = cleanPathSeperator(buffer); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1244 if(mkdir(tmp_dir, 0770)){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1245 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
|
1246 tmp_dir, errno, strerror(errno)); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1247 return EXIT_FAILURE; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1248 } |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1249 } |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1250 |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1251 /* set implicit source file */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1252 if(strcmp(error_line, "")!=0 && strcmp(error_file, "")==0){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1253 error_file=case_file; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1254 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1255 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1256 /* gdb pattern */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1257 #ifdef REG_EXTENDED |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1258 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
|
1259 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1260 gdb_pattern = malloc(sizeof(regex_t)); |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1261 if(regcomp(gdb_pattern, gdb_pattern_raw, REG_EXTENDED | REG_NOSUB)){ |
704 | 1262 fprintf(stderr, "failed to compile regular expression:" |
1263 "\n\t%s\n", gdb_pattern_raw); | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1264 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1265 }else if(gdb_script==NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1266 fprintf(stderr, "GDB pattern without GDB script\n"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1267 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1268 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1269 }else{ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1270 gdb_pattern = NULL; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1271 } |
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 /* gdb script */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1274 if(gdb_script!=NULL && gdb_script[0]!='\x00'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1275 if(gdb_pattern==NULL){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1276 fprintf(stderr, "GDB script without GDB pattern\n"); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1277 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1278 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1279 buffer=gdb_script; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1280 for(; *buffer; buffer++){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1281 if(buffer[0]=='\\'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1282 if(buffer[1]=='n'){ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1283 buffer[0]=' '; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1284 buffer[1]='\n'; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1285 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1286 buffer++; |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1287 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1288 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1289 |
685 | 1290 bufferLen = strlen(gdb_script)+11; |
1291 buffer=malloc(bufferLen); | |
1292 snprintf(buffer, bufferLen, "%s\n\nquit\ny\n\n", gdb_script); | |
1293 gdb_script=buffer; | |
922
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1294 }else if(gdb_script){ |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1295 free(gdb_script); |
95160f4d06f8
minimized memory leaks in repeatedly called functions
thomask
parents:
904
diff
changeset
|
1296 gdb_script = NULL; |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1297 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1298 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1299 #else |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1300 |
704 | 1301 if(gdb_script && strlen(gdb_script)){ |
1302 if(gdb_pattern_raw && strlen(gdb_pattern_raw)){ | |
734 | 1303 fprintf(stderr, "WARNING: GDB/regex support inactive\n"); |
704 | 1304 }else{ |
734 | 1305 fprintf(stderr, "GDB script without GDB pattern\n"); |
704 | 1306 exit(EXIT_FAILURE); |
1307 } | |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1308 }else if(gdb_pattern_raw && strlen(gdb_pattern_raw)){ |
734 | 1309 fprintf(stderr, "GDB pattern without GDB script\n"); |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1310 exit(EXIT_FAILURE); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1311 } |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1312 |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1313 #endif /* REG_EXTENDED else */ |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1314 |
493 | 1315 #ifdef DEBUG |
902 | 1316 fprintf(stderr, "case : \"%s\"\n", case_file); |
438 | 1317 fprintf(stderr, "compiler: \"%s\"\n", compiler); |
1318 fprintf(stderr, "DFLAGS C: \"%s\"\n", cmd_arg_case); | |
1319 fprintf(stderr, "ELINE : \"%s\"\n", error_line); | |
1320 fprintf(stderr, "EFILE : \"%s\"\n", error_file); | |
734 | 1321 #ifdef REG_EXTENDED |
620
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1322 fprintf(stderr, "GDB Scri: \"%s\"\n", gdb_script); |
03ad4005cd8e
POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents:
499
diff
changeset
|
1323 fprintf(stderr, "GDB Patt: \"%s\"\n", gdb_pattern_raw); |
438 | 1324 #endif |
734 | 1325 fprintf(stderr, "block G : \"%s\"\n", torture_block_global); |
1326 fprintf(stderr, "block C : \"%s\"\n", torture_block_case); | |
1327 fprintf(stderr, "modus : %x\n", modus); | |
1328 #endif | |
685 | 1329 |
251 | 1330 |
734 | 1331 /* let's get serious */ |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1332 #ifdef USE_WINDOWS |
902 | 1333 originalStdout = GetStdHandle(STD_OUTPUT_HANDLE); |
1334 originalStderr = GetStdHandle(STD_ERROR_HANDLE); | |
888
a995eae8e75c
blind: partial merger of Stewart's crashRun for Windows
thomask
parents:
881
diff
changeset
|
1335 #endif |
339
a74c84e75682
added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents:
292
diff
changeset
|
1336 |
734 | 1337 if(modus & MODE_TORTURE){ |
746 | 1338 if((modus & (MODE_COMPILE | MODE_NOCOMPILE)) |
734 | 1339 && (modus & (MODE_RUN | MODE_NORUN))) |
1340 { | |
1341 fprintf(stderr, "BUG: unhandled torture modus %x\n", modus); | |
902 | 1342 exit(EXIT_FAILURE); |
734 | 1343 }else if(!(modus & (MODE_COMPILE | MODE_NOCOMPILE | MODE_RUN | MODE_NORUN))){ |
1344 fprintf(stderr, "BUG: unhandled torture modus %x\n", modus); | |
902 | 1345 exit(EXIT_FAILURE); |
251 | 1346 } |
1347 | |
734 | 1348 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
|
1349 + 128 + strlen(cmd_arg_case) + 3; |
746 | 1350 |
734 | 1351 if(torture_block_case!=NULL && strlen(torture_block_case)<1){ |
1352 torture_block_case=NULL; | |
676 | 1353 } |
746 | 1354 |
734 | 1355 buffer = malloc(bufferLen); |
1356 for(index=0; index < sizeof(torture)/sizeof(char*); index++){ | |
1357 if((torture_block_global && strstr(torture[index], torture_block_global)) | |
1358 || (torture_block_case && strstr(torture[index], torture_block_case)) | |
959 | 1359 || (torture_require && !strstr(torture[index], torture_require))) |
734 | 1360 { |
1361 torture_result[index]=RES_UNTESTED; | |
1362 continue; | |
1363 } | |
746 | 1364 |
734 | 1365 buffer[0]=0; |
1366 snprintf(buffer, bufferLen, "%s %s", torture[index], cmd_arg_case); | |
746 | 1367 |
734 | 1368 if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){ |
1369 torture_result[index] = target_compile(modus, | |
1370 compiler, buffer, case_file, | |
1371 error_file, error_line); | |
1372 }else if(modus & (MODE_RUN | MODE_NORUN)){ | |
1373 torture_result[index] = target_run(modus, | |
1374 compiler, buffer, case_file, | |
1375 error_file, error_line | |
1376 #ifdef REG_EXTENDED | |
1377 , gdb, gdb_script, gdb_pattern | |
1378 #endif | |
1379 ); | |
1380 } | |
438 | 1381 |
902 | 1382 printf("Torture-Sub-%i/" ZU "-", index+1, |
734 | 1383 sizeof(torture)/sizeof(char*)); |
1384 printResult(torture_result[index], modus, case_file, | |
902 | 1385 stdout); |
1386 printf("--------\n"); | |
685 | 1387 } |
251 | 1388 }else{ |
998
94714c219f3b
fixed handling of __DSTRESS_TORTURE_REQUIRE__ for non-torture tests
thomask
parents:
991
diff
changeset
|
1389 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
|
1390 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
|
1391 cmd_arg_case = torture_require; |
968 | 1392 }else{ |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1393 bufferLen = strlen(cmd_arg_case); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1394 bufferLen += strlen(torture_require); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1395 bufferLen += 2; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1396 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1397 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
|
1398 cmd_arg_case = buffer; |
968 | 1399 } |
1400 } | |
734 | 1401 if(modus & (MODE_RUN | MODE_NORUN)){ |
1402 case_result = target_run(modus, compiler, cmd_arg_case, | |
1403 case_file, error_file, error_line | |
1404 #ifdef REG_EXTENDED | |
1405 , gdb, gdb_script, gdb_pattern | |
1406 #endif | |
1407 ); | |
880 | 1408 }else if(modus & (MODE_COMPILE | MODE_NOCOMPILE)){ |
734 | 1409 case_result = target_compile(modus, compiler, |
1410 cmd_arg_case, case_file, error_file, | |
1411 error_line); | |
881 | 1412 }else{ |
1413 fprintf(stderr, "BUG: unhandled non-torture modus %x\n", modus); | |
902 | 1414 exit(EXIT_FAILURE); |
734 | 1415 } |
904 | 1416 |
902 | 1417 printf("Torture-Sub-1/" ZU "-", |
880 | 1418 sizeof(torture)/sizeof(char*)); |
1419 printResult(case_result, modus, case_file, stdout); | |
251 | 1420 } |
734 | 1421 |
971
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1422 if(strcmp(TMP_DIR, tmp_dir)){ |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1423 bufferLen = strlen(tmp_dir); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1424 bufferLen += strlen(RM_DIR); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1425 bufferLen += 2; |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1426 buffer = malloc(bufferLen); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1427 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
|
1428 system(buffer); |
8da09834526d
* Valgrind support is now part of dstress.c instead of crashRun.c
thomask
parents:
968
diff
changeset
|
1429 } |
902 | 1430 exit(EXIT_SUCCESS); |
251 | 1431 } |