annotate dstress.c @ 703:8dc894322ce8

repos maintenance
author thomask
date Wed, 12 Oct 2005 18:24:50 +0000
parents fbee62becd2c
children 3e690f0d2cbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
1 /*
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
2 * core test tool for the DStress test suite
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
3 * http://dstress.kuehne.cn
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
4 *
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
5 * Copyright (C) 2005 Thomas Kuehne <thomas@kuehne.cn>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
6 *
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
10 * (at your option) any later version.
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
11 *
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
15 * GNU General Public License for more details.
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
16 *
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
20 *
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
21 * $HeadURL$
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
22 * $Date$
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
23 * $Author$
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
24 *
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
25 */
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
26
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
27 /* Beware: the code doesn't care about freeing allocated memory etc. . .. */
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
28
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
29 #include <stdlib.h>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
30 #include <stdio.h>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
31 #include <string.h>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
32 #include <errno.h>
681
be27bc9d0d28 gentoo fixes
thomask
parents: 676
diff changeset
33 #include <ctype.h>
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
34
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
35 #define RUN 1
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
36 #define NORUN 2
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
37 #define COMPILE 4
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
38 #define NOCOMPILE 8
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
39
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
40 /* secure malloc */
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
41 void *xmalloc(size_t size){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
42 void *p = malloc(size);
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
43 if (p == NULL){
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
44 fprintf(stderr,"Failed to allocate %zd bytes!\n", size);
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
45 exit(EXIT_FAILURE);
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
46 }
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
47 return p;
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
48 }
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
49 #define malloc xmalloc
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
50
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
51 #if defined(__GNU_LIBRARY__) || defined(__GLIBC__)
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
52 #define USE_POSIX 1
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
53 #endif
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
54
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
55 #if defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__)
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
56 #define USE_POSIX 1
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
57 #endif
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
58
273
68b883fe4fad added *BSD support to the test framework
thomask
parents: 261
diff changeset
59 #if defined(__APPLE__) && defined(__MACH__)
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
60 #define USE_POSIX 1
273
68b883fe4fad added *BSD support to the test framework
thomask
parents: 261
diff changeset
61 #endif
68b883fe4fad added *BSD support to the test framework
thomask
parents: 261
diff changeset
62
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
63 #if defined(WIN) || defined(WIN32)
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
64 #define USE_WINDOWS 1
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
65 #endif
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
66
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
67 #ifdef USE_POSIX
254
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
68
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
69 #include <sys/types.h>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
70 #include <sys/stat.h>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
71 #include <fcntl.h>
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
72 #include <unistd.h>
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
73 #include <regex.h>
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
74
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
75 #else
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
76 #ifdef USE_WINDOWS
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
77
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
78 #include <windows.h>
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
79 #define snprintf _snprintf
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
80 #ifndef INVALID_FILE_SIZE
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
81 #define INVALID_FILE_SIZE -1
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
82 #endif
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
83
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
84 #else
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
85 #error neither POSIX nor MSWindows detected
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
86 #endif /* USE_WINDOWS else */
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
87 #endif /* USE_POSIX else */
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
88
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
89 #define OBJ "obj "
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
90
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
91 #ifdef USE_WINDOWS
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
92 #define TLOG ".\\obj\\log.tmp"
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
93 #define CRASH_RUN ".\\crashRun"
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
94 #define GDB_SCRIPTER ".\\obj\\gdb.tmp"
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
95 #else
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
96 #ifdef USE_POSIX
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
97 #define TLOG "./obj/log.tmp"
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
98 #define CRASH_RUN "./crashRun"
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
99 #define GDB_SCRIPTER "./obj/gdb.tmp"
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
100 #endif
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
101 #endif
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
102
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
103 char* errorMsg(int good_error){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
104 return (good_error) ? ("") : " [bad error message]";
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
105 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
106
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
107 char* gdbMsg(int good_gdb){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
108 return (good_gdb) ? ("") : " [bad debugger message]";
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
109 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
110
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
111 char* strip(char* buffer){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
112 char* tmp = NULL;
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
113
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
114 if(buffer!=NULL){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
115 while(isspace(buffer[0])){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
116 buffer++;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
117 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
118
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
119 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
120 tmp[0]='\x00';
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
121 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
122 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
123 return buffer;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
124 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
125
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
126 /* cleanup "/" versus "\" in filenames */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
127 char* cleanPathSeperator(char* filename){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
128 char* pos = NULL;
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
129 #ifdef USE_POSIX
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
130 for(pos=strchr(filename, '\\'); pos; pos=strchr(filename, '\\')){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
131 *pos='/';
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
132 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
133 #else
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
134 #if USE_WINDOWS
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
135 for(pos=strchr(filename, '/'); pos; pos=strchr(filename, '/')){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
136 *pos='\\';
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
137 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
138 #else
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
139
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
140 #error no cleanPathSeperator available for this system
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
141
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
142 #endif /* USE_WINDOWS else */
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
143 #endif /* USE_POSIX else */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
144 return filename;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
145 }
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
146
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
147 char* loadFile(char* filename){
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
148 #ifdef USE_POSIX
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
149 char* back;
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
150 struct stat fileInfo;
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
151 int file = open(filename, O_RDONLY);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
152
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
153 back = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
154
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
155 if(errno == 0 && file != 0 && file != -1){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
156 if(0==fstat(file, &fileInfo)){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
157 back=malloc(fileInfo.st_size+1);
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
158 fileInfo.st_size = read(file, back, fileInfo.st_size);
440
dc186d1266ba fixed handling of empty files
thomask
parents: 439
diff changeset
159 if(fileInfo.st_size>=0){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
160 *(back+fileInfo.st_size) = '\x00';
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
161 }else{
436
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
162 back = NULL;
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
163 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
164 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
165 close(file);
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
166 }
436
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
167
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
168 if(back){
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
169 return back;
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
170 }
440
dc186d1266ba fixed handling of empty files
thomask
parents: 439
diff changeset
171 if(0==strcmp(filename, TLOG)){
dc186d1266ba fixed handling of empty files
thomask
parents: 439
diff changeset
172 return calloc(1,sizeof(char));
dc186d1266ba fixed handling of empty files
thomask
parents: 439
diff changeset
173 }
436
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
174
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
175 fprintf(stderr, "File not found \"%s\" (%s)\n", filename, strerror(errno));
436
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
176 exit(EXIT_FAILURE);
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
177 #else /* USE_POSIX */
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
178 #ifdef USE_WINDOWS
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
179 // @todo@ check for 32bit/64bit
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
180 char* back;
254
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
181 DWORD size, numread;
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
182 HANDLE file=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
183 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
184
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
185 back = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
186 size = 0;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
187 numread = 0;
254
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
188 if (file != INVALID_HANDLE_VALUE){
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
189 size = GetFileSize(file, NULL);
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
190 if (size != INVALID_FILE_SIZE){
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
191 back=malloc((size+1)*sizeof(char));
292
7e28d437d6d7 fixed Windows loadFile return code bug
thomask
parents: 273
diff changeset
192 if (ReadFile(file,back,size,&numread,NULL) == 1){
7e28d437d6d7 fixed Windows loadFile return code bug
thomask
parents: 273
diff changeset
193 if (numread==size){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
194 *(back+size) = '\x00';
292
7e28d437d6d7 fixed Windows loadFile return code bug
thomask
parents: 273
diff changeset
195 }else{
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
196 back = NULL;
292
7e28d437d6d7 fixed Windows loadFile return code bug
thomask
parents: 273
diff changeset
197 }
7e28d437d6d7 fixed Windows loadFile return code bug
thomask
parents: 273
diff changeset
198 }else{
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
199 back = NULL;
292
7e28d437d6d7 fixed Windows loadFile return code bug
thomask
parents: 273
diff changeset
200 }
254
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
201 }
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
202 CloseHandle(file);
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
203 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
204 if(back){
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
205 errno = 0;
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
206 return back;
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
207 }
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
208
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
209 fprintf(stderr, "File not found \"%s\"\n", filename);
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
210 exit(EXIT_FAILURE);
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
211 #else /* USE_WINDOWS */
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
212
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
213 #error "no loadFile implementation present"
361
0147a35cbeb7 dif. fixes 5
thomask
parents: 340
diff changeset
214
633
653cbe20c878 updated location of tmp files
thomask
parents: 622
diff changeset
215 #endif /* USE_WINDOWS */
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
216 #endif /* USE_POSIX else */
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
217 }
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
218
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
219 void writeFile(const char* filename, const char* content){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
220 size_t len;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
221 FILE* file;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
222
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
223 len = strlen(content);
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
224 errno = 0;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
225 file = fopen(filename, "w+");
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
226
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
227 if(errno == 0 && file != NULL){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
228 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
229 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
230 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
231 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
232 if(fclose(file) || (errno != 0)){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
233 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
234 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
235 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
236 return;
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
237 }
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
238
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
239 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
240 exit(EXIT_FAILURE);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
241 }
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
242
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
243 /* query the environment for the compiler name */
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
244 char* getCompiler(void){
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
245 char* back = getenv("DMD");
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
246 if(back == NULL){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
247 back = getenv("dmd");
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
248 if(back==NULL){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
249 back = "dmd";
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
250 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
251 }
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
252 return strip(cleanPathSeperator(back));
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
253 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
254
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
255 /* query the environment for the debugger name */
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
256 char* getGDB(void){
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
257 char* back = getenv("GDB");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
258 if(back == NULL){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
259 back = getenv("gdb");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
260 if(back == NULL){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
261 back = "gdb";
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
262 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
263 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
264 return strip(cleanPathSeperator(back));
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
265 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
266
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
267 /* 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
268 char* getCaseFlag(const char* data, const char* tag){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
269 char* begin;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
270 char* end1;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
271 char* end2;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
272 char* back;
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
273
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
274 begin = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
275 end1 = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
276 end2 = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
277 back = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
278
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
279 if(data!=NULL && tag!=NULL){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
280 begin = strstr(data, tag);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
281 if(begin!=NULL){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
282 begin = begin+strlen(tag);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
283 end1 = strstr(begin, "\n");
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
284 end2 = strstr(begin, "\r");
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
285 if(end2!=NULL && ((end1!=NULL && end2<end1) || end1==NULL)){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
286 end1=end2;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
287 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
288 if(end1==NULL){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
289 end1 = begin + strlen(begin);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
290 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
291 back = malloc(end1-begin+1);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
292 strncpy(back, begin, end1-begin);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
293 back[end1-begin]='\x00';
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
294 return strip(cleanPathSeperator(back));
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
295 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
296 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
297
429
1185c50d4b08 fix dstress.c's memory handling
thomask
parents: 405
diff changeset
298 return calloc(1,1);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
299 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
300
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
301 /* check compile-time error messages */
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
302 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
303
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
304 char* file;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
305 char* line;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
306 char* dmd;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
307 char* gdc;
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
308 size_t len;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
309 int back;
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
310
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
311 file = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
312 line = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
313 dmd = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
314 gdc = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
315 len = 0;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
316 back = 0;
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
317
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
318 /* clean arguments */
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
319 if(strcmp(file_, "")!=0){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
320 len = strlen(file_)+1;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
321 file = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
322 strncpy(file, file_, len);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
323 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
324
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
325 if(strcmp(line_, "")!=0){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
326 len = strlen(line_)+1;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
327 line = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
328 strncpy(line, line_, len);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
329 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
330
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
331 /* gen patterns*/
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
332 if(file!=NULL){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
333 if(line!=NULL){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
334 len = strlen(file)+strlen(line)+5;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
335 dmd = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
336 snprintf(dmd, len, "%s(%s)", file, line);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
337
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
338 gdc = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
339 snprintf(gdc, len, "%s:%s: ", file, line);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
340 }else{
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
341 len = strlen(file)+2;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
342 dmd = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
343 snprintf(dmd, len, "%s(", file);
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
344
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
345 gdc = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
346 snprintf(gdc, len, "%s:", file);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
347 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
348 }else if(line!=NULL){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
349 len = strlen(line)+5;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
350 dmd = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
351 snprintf(dmd, len, "(%s): ", line);
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
352
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
353 gdc = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
354 snprintf(gdc, len, ":%s: ", line);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
355 }else{
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
356 return 1;
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
357 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
358
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
359 /* specific error messages */
676
f90958db522d extended debug output
thomask
parents: 639
diff changeset
360 #ifdef DEBUG
f90958db522d extended debug output
thomask
parents: 639
diff changeset
361 fprintf(stderr, "pattern(dmd):\t%s\n", dmd);
f90958db522d extended debug output
thomask
parents: 639
diff changeset
362 fprintf(stderr, "pattern(gdc):\t%s\n", gdc);
f90958db522d extended debug output
thomask
parents: 639
diff changeset
363 #endif
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
364
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
365 if( (dmd!=NULL && strstr(buffer, dmd))
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
366 || (gdc!=NULL && strstr(buffer, gdc))
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
367 || (dmd==NULL && gdc==NULL)){
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
368 back=1;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
369 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
370
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
371 return back;
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
372 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
373
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
374 int checkRuntimeErrorMessage(const char* file_, const char* line_, const char* buffer){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
375 /* PhobosLong dir/file.d(2)
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
376 * Phobos package.module(2)
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
377 */
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
378
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
379 char* file;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
380 char* line;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
381 char* phobos;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
382 char* phobosLong;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
383
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
384 char* begin;
439
edb0923c9159 cleanup for Linux(gcc)
thomask
parents: 438
diff changeset
385 char* end;
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
386 size_t len;
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
387
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
388 int back=0;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
389
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
390 file = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
391 line = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
392 phobos = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
393 phobosLong = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
394
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
395 begin = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
396 end = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
397 len = 0;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
398
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
399 /* clean arguments */
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
400 if(strcmp(file_, "")!=0){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
401 len = strlen(file_)+1;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
402 file = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
403 strncpy(file, file_, len);
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
404 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
405
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
406 if(strcmp(line_, "")!=0){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
407 len = strlen(line_)+1;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
408 line = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
409 strncpy(line, line_, len);
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
410 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
411
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
412 /* gen patterns*/
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
413 if(file!=NULL){
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
414 if(line!=NULL){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
415 len = strlen(file)+strlen(line)+5;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
416 phobos = malloc(len);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
417 begin=strrchr(file,'/');
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
418 if(begin){
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
419 begin++;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
420 }else{
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
421 begin=strrchr(file,'\\');
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
422 if(begin){
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
423 begin++;
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
424 }else{
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
425 begin=file;
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
426 }
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
427 }
439
edb0923c9159 cleanup for Linux(gcc)
thomask
parents: 438
diff changeset
428 end=strrchr(file,'.');
edb0923c9159 cleanup for Linux(gcc)
thomask
parents: 438
diff changeset
429 strncat(phobos, begin, end-begin);
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
430 snprintf(phobos, len, "%.*s(%s)",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
431 (int)(end-begin), begin,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
432 line);
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
433
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
434 phobosLong = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
435 snprintf(phobosLong, len, "%s(%s)", file, line);
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
436 }else{
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
437 len = strlen(file)+2;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
438 phobos = malloc(len);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
439 begin=strrchr(file,'/');
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
440 if(begin){
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
441 begin++;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
442 }else{
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
443 begin=strrchr(file,'\\');
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
444 if(begin){
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
445 begin++;
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
446 }else{
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
447 begin=file;
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
448 }
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
449 }
439
edb0923c9159 cleanup for Linux(gcc)
thomask
parents: 438
diff changeset
450 end=strrchr(file,'.');
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
451 snprintf(phobos, len, "%.*s(", (int)(end-begin), begin);
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
452
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
453 phobosLong = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
454 snprintf(phobosLong, len, "%s(", file);
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
455 }
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
456 }else if(line!=NULL){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
457 len = strlen(line)+3;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
458 phobos = malloc(len);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
459 snprintf(phobos, len, "(%s)", line);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
460
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
461 phobosLong=NULL;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
462 }else{
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
463 return 1;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
464 }
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
465
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
466 /* specific error messages */
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
467
676
f90958db522d extended debug output
thomask
parents: 639
diff changeset
468 #ifdef DEBUG
f90958db522d extended debug output
thomask
parents: 639
diff changeset
469 fprintf(stderr, "pattern(phobosShort):\t%s\n", phobos);
f90958db522d extended debug output
thomask
parents: 639
diff changeset
470 fprintf(stderr, "pattern(phobosLong):\t%s\n", phobosLong);
f90958db522d extended debug output
thomask
parents: 639
diff changeset
471 #endif
f90958db522d extended debug output
thomask
parents: 639
diff changeset
472
432
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
473 if( (phobos && strstr(buffer, phobos))
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
474 || (phobosLong && strstr(buffer, phobosLong)))
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
475 {
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
476 back=1;
db4b6169a99d 1) implemented checkRuntimeErrorMessage
thomask
parents: 429
diff changeset
477 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
478
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
479 return back;
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
480 }
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
481
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
482 int hadExecCrash(const char* buffer){
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
483 if(strstr(buffer, "Segmentation fault")
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
484 || strstr(buffer, "Internal error")
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
485 || strstr(buffer, "gcc.gnu.org/bugs")
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
486 || strstr(buffer, "EXIT CODE: signal"))
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
487 {
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
488 return 1;
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
489 }
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
490 return 0;
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
491 }
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
492
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
493 /* system call with time-out */
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
494 int crashRun(const char* cmd){
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
495 #ifdef USE_POSIX
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
496 size_t len;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
497 char* buffer;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
498
703
8dc894322ce8 repos maintenance
thomask
parents: 697
diff changeset
499 len = 4 + strlen(CRASH_RUN) + strlen(cmd);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
500 buffer = malloc(len);
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
501
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
502 snprintf(buffer, len, "\"%s\" %s", CRASH_RUN, cmd);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
503
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
504 system(buffer);
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
505 buffer=loadFile(TLOG);
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
506
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
507 if(strstr(buffer, "EXIT CODE: 0")){
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
508 return EXIT_SUCCESS;
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
509 }else if(strstr(buffer, "EXIT CODE: 256")
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
510 || strstr(buffer, "EXIT CODE: timeout"))
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
511 {
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
512 return EXIT_FAILURE;
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
513 }else{
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
514 return RAND_MAX;
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
515 }
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
516 #else
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
517
703
8dc894322ce8 repos maintenance
thomask
parents: 697
diff changeset
518 //#error comment me out, if your test cases produce neither eternal loops nor Access Violations
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
519 int i = system(cmd);
703
8dc894322ce8 repos maintenance
thomask
parents: 697
diff changeset
520 fprintf(stderr, "EXIT CODE: %i\n", i);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
521 return i;
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
522
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
523 #endif /* USE_POSIX else */
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
524 }
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
525
254
a39162afcc94 MSWindows port of "dstress.c"
thomask
parents: 251
diff changeset
526
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
527 int main(int argc, char* arg[]){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
528 char* compiler; /* the compiler - from enviroment flag "DMD" */
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
529 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
530 char* buffer; /* general purpose buffer */
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
531 size_t bufferLen;
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
532 int modus; /* test modus: RUN NORUN COMPILE NOCOMPILE */
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
533 int res; /* return code from external executions */
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
534 char* case_file;
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
535 char* error_file; /* expected sourcefile containing the error */
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
536 char* error_line; /* expected error line */
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
537 int good_error; /* error contained file and line and matched the expectations */
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
538 char* gdb; /* the debugger - from environment flag "GDB" */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
539 char* gdb_script; /* gdb command sequence */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
540 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
541 #ifdef REG_EXTENDED
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
542 regex_t* gdb_pattern;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
543 #endif
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
544 int good_gdb; /* (gdb test and positive) or (no gdb test)*/
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
545
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
546 compiler = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
547 cmd_arg_case = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
548 buffer = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
549 bufferLen = 0;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
550 modus = -1;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
551 res = -1;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
552 case_file = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
553 error_file = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
554 error_line = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
555 good_error = -1;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
556 gdb = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
557 gdb_script = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
558 gdb_pattern_raw = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
559 #ifdef REG_EXTENDED
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
560 gdb_pattern = NULL;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
561 #endif
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
562 good_gdb = -1;
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
563
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
564 /* check arguments */
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
565 if(argc != 3){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
566 err:
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
567 if(argc!=0)
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
568 fprintf(stderr,"%s <run|norun|compile|nocompile> <source>\n", arg[0]);
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
569 else
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
570 fprintf(stderr,"dstress <run|norun|compile|nocompile> <source>\n");
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
571 exit(EXIT_FAILURE);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
572 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
573
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
574 if(0==strcmp(arg[1], "run") || 0==strcmp(arg[1], "RUN")){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
575 modus = RUN;
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
576 }else if(0==strcmp(arg[1], "norun") || 0==strcmp(arg[1], "NORUN")){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
577 modus = NORUN;
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
578 }else if(0==strcmp(arg[1], "compile") || 0==strcmp(arg[1], "COMPILE")){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
579 modus = COMPILE;
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
580 }else if(0==strcmp(arg[1], "nocompile") || 0==strcmp(arg[1], "NOCOMPILE")){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
581 modus = NOCOMPILE;
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
582 }else{
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
583 goto err;
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
584 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
585
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
586 /* gen flags */
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
587 case_file = cleanPathSeperator(strdup(arg[2]));
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
588 compiler = getCompiler();
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
589 gdb = getGDB();
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
590 buffer = loadFile(case_file);
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
591
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
592 cmd_arg_case = getCaseFlag(buffer, "__DSTRESS_DFLAGS__");
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
593 error_line = getCaseFlag(buffer, "__DSTRESS_ELINE__");
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
594 error_file = getCaseFlag(buffer, "__DSTRESS_EFILE__");
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
595 gdb_script = getCaseFlag(buffer, "__GDB_SCRIPT__");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
596 gdb_pattern_raw = getCaseFlag(buffer, "__GDB_PATTERN__");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
597
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
598
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
599 /* set implicit source file */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
600 if(strcmp(error_line, "")!=0 && strcmp(error_file, "")==0){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
601 error_file=case_file;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
602 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
603
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
604 /* gdb pattern */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
605 #ifdef REG_EXTENDED
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
606 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
607
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
608 gdb_pattern = malloc(sizeof(regex_t));
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
609 if(regcomp(gdb_pattern, gdb_pattern_raw, REG_EXTENDED)){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
610 fprintf(stderr, "failed to compile regular expression:\n\t%s\n", gdb_pattern_raw);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
611 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
612 }else if(gdb_script==NULL){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
613 fprintf(stderr, "GDB pattern without GDB script\n");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
614 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
615 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
616 }else{
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
617 gdb_pattern = NULL;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
618 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
619
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
620 /* gdb script */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
621 if(gdb_script!=NULL && gdb_script[0]!='\x00'){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
622 if(gdb_pattern==NULL){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
623 fprintf(stderr, "GDB script without GDB pattern\n");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
624 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
625 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
626 buffer=gdb_script;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
627 for(; *buffer; buffer++){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
628 if(buffer[0]=='\\'){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
629 if(buffer[1]=='n'){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
630 buffer[0]=' ';
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
631 buffer[1]='\n';
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
632 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
633 buffer++;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
634 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
635 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
636
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
637 bufferLen = strlen(gdb_script)+11;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
638 buffer=malloc(bufferLen);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
639 snprintf(buffer, bufferLen, "%s\n\nquit\ny\n\n", gdb_script);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
640 gdb_script=buffer;
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
641 good_gdb = 0;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
642 }else{
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
643 good_gdb = 1;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
644 gdb_script = NULL;
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
645 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
646
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
647 #else
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
648
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
649 if(gdb_script && strlen(gdb_script) && gdb_pattern_raw && strlen(gdb_pattern_raw)){
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
650 fprintf(stderr, "WARNING: regex support inactive\n");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
651 }else if(gdb_script && strlen(gdb_script)){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
652 fprintf(stderr, "GDB script without GDB pattern\n");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
653 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
654 }else if(gdb_pattern_raw && strlen(gdb_pattern_raw)){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
655 fprintf(stderr, "GDB pattern without GDB script\n");
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
656 exit(EXIT_FAILURE);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
657 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
658
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
659 #endif /* REG_EXTENDED else */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
660
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
661
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
662
493
1418f225a81e disabled debug output
thomask
parents: 490
diff changeset
663 #ifdef DEBUG
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
664 fprintf(stderr, "case: \"%s\"\n", case_file);
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
665 fprintf(stderr, "compiler: \"%s\"\n", compiler);
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
666 fprintf(stderr, "DFLAGS C: \"%s\"\n", cmd_arg_case);
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
667 fprintf(stderr, "ELINE : \"%s\"\n", error_line);
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
668 fprintf(stderr, "EFILE : \"%s\"\n", error_file);
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
669 fprintf(stderr, "GDB Scri: \"%s\"\n", gdb_script);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
670 fprintf(stderr, "GDB Patt: \"%s\"\n", gdb_pattern_raw);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
671 #endif
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
672
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
673 /* start working */
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
674 if(modus==COMPILE || modus==NOCOMPILE){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
675 /* gen command */
693
cfe101f6f1f3 fixed snprintf statement (hrr....)
thomask
parents: 685
diff changeset
676 bufferLen = strlen(compiler)+strlen(cmd_arg_case)
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
677 +strlen(OBJ)+strlen(case_file)+strlen(TLOG)+21;
693
cfe101f6f1f3 fixed snprintf statement (hrr....)
thomask
parents: 685
diff changeset
678 buffer = malloc(bufferLen);
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
679 snprintf(buffer, bufferLen, "%s %s ", compiler, cmd_arg_case);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
680
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
681 if(NULL==strstr(buffer, "-od")){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
682 snprintf(buffer, bufferLen,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
683 "%s %s -od%s -c %s 1> %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
684 compiler, cmd_arg_case, OBJ, case_file, TLOG);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
685 }else{
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
686 snprintf(buffer, bufferLen, "%s %s -c %s 1> %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
687 compiler, cmd_arg_case, case_file, TLOG);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
688 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
689
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
690 /* test */
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
691 if(modus==COMPILE){
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
692 fprintf(stderr, "compile: %s\n", buffer);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
693 }else{
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
694 fprintf(stderr, "nocompile: %s\n", buffer);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
695 }
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
696 res = crashRun(buffer);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
697
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
698 /* diagnostic */
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
699 buffer = loadFile(TLOG);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
700 fprintf(stderr, "%s\n", buffer);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
701 good_error = checkErrorMessage(error_file, error_line, buffer);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
702
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
703 if(hadExecCrash(buffer)){
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
704 printf("ERROR:\t%s [internal compiler error]\n", case_file);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
705 }else if(modus==COMPILE){
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
706 if(res==EXIT_SUCCESS){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
707 printf("PASS: \t%s\n", case_file);
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
708 }else if(res==EXIT_FAILURE && good_error){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
709 if(checkErrorMessage(case_file, "", buffer)){
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
710 printf("FAIL: \t%s\n", case_file);
373
177ce8d13eac test cases that unexpectetly fail and in addition fail to provide file/line information are now treated as ERROR instead of FAIL
thomask
parents: 361
diff changeset
711 }else{
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
712 printf("ERROR:\t%s%s\n", case_file, errorMsg(good_error));
373
177ce8d13eac test cases that unexpectetly fail and in addition fail to provide file/line information are now treated as ERROR instead of FAIL
thomask
parents: 361
diff changeset
713 }
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
714 }else{
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
715 printf("ERROR:\t%s%s\n", case_file, errorMsg(good_error));
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
716 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
717 }else{
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
718 if(res==EXIT_FAILURE){
361
0147a35cbeb7 dif. fixes 5
thomask
parents: 340
diff changeset
719 if(good_error){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
720 printf("XFAIL:\t%s\n", case_file);
361
0147a35cbeb7 dif. fixes 5
thomask
parents: 340
diff changeset
721 }else{
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
722 printf("FAIL: \t%s%s\n", case_file, errorMsg(good_error));
361
0147a35cbeb7 dif. fixes 5
thomask
parents: 340
diff changeset
723 }
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
724 }else if(res==EXIT_SUCCESS){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
725 printf("XPASS:\t%s\n", case_file);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
726 }else{
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
727 printf("ERROR:\t%s\n", case_file);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
728 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
729 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
730 fprintf(stderr,"--------\n");
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
731 }else if(modus==RUN || modus==NORUN){
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
732 /* gen command */
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
733
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
734 bufferLen = strlen(compiler)+strlen(cmd_arg_case)
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
735 +strlen(OBJ)
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
736 +strlen(case_file)*2+strlen(TLOG)+64;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
737 buffer = malloc(bufferLen);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
738 snprintf(buffer, bufferLen, "%s %s ", compiler, cmd_arg_case);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
739
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
740 if(NULL==strstr(buffer, "-od")){
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
741 if(NULL==strstr(buffer, "-of")){
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
742 snprintf(buffer, bufferLen,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
743 "%s %s -od%s -of%s.exe %s 1> %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
744 compiler, cmd_arg_case, OBJ, case_file,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
745 case_file, TLOG);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
746 }else{
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
747 snprintf(buffer, bufferLen,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
748 "%s %s -od%s %s 1> %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
749 compiler, cmd_arg_case, OBJ, case_file,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
750 TLOG);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
751 }
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
752 }else if(NULL==strstr(buffer, "-of")){
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
753 snprintf(buffer, bufferLen,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
754 "%s %s -of%s.exe %s 1> %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
755 compiler, cmd_arg_case, case_file, case_file,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
756 TLOG);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
757 }else{
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
758 snprintf(buffer, bufferLen, "%s %s %s 1> %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
759 compiler, cmd_arg_case, case_file, TLOG);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
760 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
761
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
762 /* test 1/3 - compile */
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
763 if(modus==RUN){
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
764 fprintf(stderr, "run: %s\n", buffer);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
765 }else{
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
766 fprintf(stderr, "norun: %s\n", buffer);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
767 }
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
768 res = crashRun(buffer);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
769
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
770 /* diagnostic 1/3 */
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
771 buffer = loadFile(TLOG);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
772 fprintf(stderr, "%s", buffer);
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
773
676
f90958db522d extended debug output
thomask
parents: 639
diff changeset
774 if(modus==RUN){
f90958db522d extended debug output
thomask
parents: 639
diff changeset
775 good_error = checkErrorMessage(error_file, error_line, buffer);
f90958db522d extended debug output
thomask
parents: 639
diff changeset
776 }else{
f90958db522d extended debug output
thomask
parents: 639
diff changeset
777 good_error = 1;
f90958db522d extended debug output
thomask
parents: 639
diff changeset
778 }
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
779 if(hadExecCrash(buffer)){
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
780 printf("ERROR:\t%s [internal compiler error]\n", case_file);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
781 fprintf(stderr, "\n--------\n");
437
1b4034b27e93 added "[bad error message]" output
thomask
parents: 436
diff changeset
782 return EXIT_SUCCESS;
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
783 }else if(res==EXIT_FAILURE && good_error){
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
784 printf("FAIL: \t%s\n", case_file);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
785 fprintf(stderr, "\n--------\n");
437
1b4034b27e93 added "[bad error message]" output
thomask
parents: 436
diff changeset
786 return EXIT_SUCCESS;
490
d091ff903fa4 added crashRun for POSIX systems
thomask
parents: 476
diff changeset
787 }else if(res!=EXIT_SUCCESS){
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
788 printf("ERROR:\t%s%s\n", case_file, errorMsg(good_error));
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
789 fprintf(stderr, "\n--------\n");
437
1b4034b27e93 added "[bad error message]" output
thomask
parents: 436
diff changeset
790 return EXIT_SUCCESS;
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
791 }
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
792
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
793 /* test 2/3 - run */
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
794 bufferLen = strlen(case_file) + strlen(TLOG) + 30;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
795 buffer = malloc(bufferLen);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
796 snprintf(buffer, bufferLen, "%s.exe 1> %s 2>&1\n", case_file,
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
797 TLOG);
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
798 fprintf(stderr, "%s\n", buffer);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
799 res=crashRun(buffer);
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
800
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
801 /* diagnostic 2/3 */
339
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
802 buffer = loadFile(TLOG);
a74c84e75682 added error line tests (__DSTRESS_ELINE__ / __DSTRESS_EFILE__)
thomask
parents: 292
diff changeset
803 fprintf(stderr, "%s\n", buffer);
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
804 if(modus==NORUN){
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
805 good_error = checkRuntimeErrorMessage(error_file, error_line, buffer);
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
806 }else{
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
807 good_error = 1;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
808 }
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
809
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
810 #ifdef REG_EXTENDED
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
811 if(!good_gdb){
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
812 /* test 3/3 - gdb */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
813 writeFile(GDB_SCRIPTER, gdb_script);
685
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
814 bufferLen = strlen(gdb) + strlen(case_file)
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
815 + strlen(GDB_SCRIPTER) + strlen(TLOG) + 20;
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
816 snprintf(buffer, bufferLen, "%s %s.exe < %s > %s 2>&1",
4f97e51515d8 ported dstress.c to OpenBsd
thomask
parents: 681
diff changeset
817 gdb, case_file, GDB_SCRIPTER, TLOG);
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
818 fprintf(stderr, "%s\n", buffer);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
819 if(EXIT_SUCCESS==crashRun(buffer)){
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
820 /* diagnostic 3/3 */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
821 buffer = loadFile(TLOG);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
822 fprintf(stderr, "%s\n", buffer);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
823 good_gdb = (regexec(gdb_pattern, buffer, 0, NULL, 0)==0);
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
824 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
825 }
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
826 #endif /* REG_EXTENDED */
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
827
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
828 if(modus==RUN){
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
829 if(hadExecCrash(buffer)){
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
830 printf("ERROR:\t%s [test case crash]%s%s", case_file, errorMsg(good_error), gdbMsg(good_gdb));
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
831 }else if(res==EXIT_SUCCESS && good_gdb){
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
832 printf("PASS: \t%s\n", case_file);
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
833 }else if(res==EXIT_FAILURE && good_error && good_gdb){
499
0434764d4a66 removed redundancy in the output
thomask
parents: 493
diff changeset
834 printf("FAIL: \t%s\n", case_file);
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
835 }else{
620
03ad4005cd8e POSIX only: added __GDB_SCRIPT__ and __GDB__PATTERN__ support
thomask
parents: 499
diff changeset
836 printf("ERROR:\t%s%s%s\n", case_file, errorMsg(good_error), gdbMsg(good_gdb));
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
837 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
838 }else{
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
839 if(res==EXIT_SUCCESS && good_gdb){
697
fbee62becd2c partial repos review
thomask
parents: 693
diff changeset
840 printf("XPASS:\t%s%s\n", case_file, gdbMsg(good_gdb));
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
841 }else if(good_error && good_gdb){
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
842 printf("XFAIL:\t%s%s%s\n", case_file, errorMsg(good_error), gdbMsg(good_gdb));
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
843 }else{
622
7acb8b34c87a - fixed diagnostic 3/3
thomask
parents: 620
diff changeset
844 printf("FAIL:\t%s%s%s\n", case_file, errorMsg(good_error), gdbMsg(good_gdb));
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
845 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
846 }
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
847 fprintf(stderr, "--------\n");
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
848 }else{
438
27039d5cbe81 partial cleanup for Windows(dmc)
thomask
parents: 437
diff changeset
849 printf("@bug@ %d (%s)\n", modus, case_file);
436
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
850 return EXIT_FAILURE;
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
851 }
436
5e210bace0f1 added "File not found" clause
thomask
parents: 432
diff changeset
852 return EXIT_SUCCESS;
251
6cd84461e17b enabled new "dstress.c" test tool
thomask
parents:
diff changeset
853 }