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