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