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