251
|
1 /*
|
|
2 * core test tool for the DStress test suite
|
|
3 * http://dstress.kuehne.cn
|
|
4 *
|
|
5 * Copyright (C) 2005 Thomas Kuehne <thomas@kuehne.cn>
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 *
|
|
21 * $HeadURL$
|
|
22 * $Date$
|
|
23 * $Author$
|
|
24 *
|
|
25 */
|
|
26
|
|
27 #include <stdlib.h>
|
|
28 #include <stdio.h>
|
|
29 #include <string.h>
|
|
30 #include <errno.h>
|
|
31
|
|
32 #define TAG "__DSTRESS_DFLAGS__"
|
|
33 #define OBJ "-odobj "
|
|
34 #define TLOG "log.tmp"
|
|
35
|
|
36 #define RUN 1
|
|
37 #define NORUN 2
|
|
38 #define COMPILE 4
|
|
39 #define NOCOMPILE 8
|
|
40
|
|
41 /* Query the environment for the compiler name */
|
|
42 char* getCompiler(){
|
|
43 char* back = getenv("DMD");
|
|
44 if(back == NULL){
|
|
45 back = getenv("dmd");
|
|
46 if(back==NULL){
|
|
47 back = "dmd";
|
|
48 }
|
|
49 }
|
|
50 return back;
|
|
51 }
|
|
52
|
|
53 /* Query the environment for general flags */
|
|
54 char* getGeneralFlags(){
|
|
55 char* back = getenv("DFLAGS");
|
|
56 if(back == NULL){
|
|
57 back = getenv("dflags");
|
|
58 if(back==NULL){
|
|
59 back = "";
|
|
60 }
|
|
61 }
|
|
62 return back;
|
|
63 }
|
|
64
|
|
65 #ifdef __GNU_LIBRARY__
|
|
66 #define USE_POSIX_LOAD
|
|
67 #endif
|
|
68
|
|
69 #ifdef __GLIBC__
|
|
70 #define USE_POSIX_LOAD
|
|
71 #endif
|
|
72
|
|
73 #ifdef linux
|
|
74 #define USE_POSIX_LOAD
|
|
75 #endif
|
|
76
|
273
|
77 #if defined(__APPLE__) && defined(__MACH__)
|
|
78 #define USE_POSIX_LOAD
|
|
79 #endif
|
|
80
|
|
81 #ifdef __FreeBSD__
|
|
82 #define USE_POSIX_LOAD
|
|
83 #endif
|
|
84
|
251
|
85 #ifdef USE_POSIX_LOAD
|
254
|
86
|
|
87 #define RETURN_OK 0
|
|
88 #define RETURN_FAIL 256
|
|
89
|
251
|
90 #include <sys/types.h>
|
|
91 #include <sys/stat.h>
|
|
92 #include <fcntl.h>
|
|
93 #include <unistd.h>
|
|
94 char* loadFile(char* filename){
|
|
95 char* back = NULL;
|
|
96 struct stat fileInfo;
|
|
97 int file = open(filename, O_RDONLY);
|
|
98 if(errno == 0 && file != 0 && file != -1){
|
|
99 if(0==fstat(file, &fileInfo)){
|
|
100 back=malloc(fileInfo.st_size+1);
|
|
101 fileInfo.st_size = read(file, back, fileInfo.st_size);
|
254
|
102 if(fileInfo.st_size>0){
|
251
|
103 *(back+fileInfo.st_size+1) = '\x00';
|
|
104 }else{
|
254
|
105 back = "\x00";
|
251
|
106 }
|
|
107 }
|
|
108 close(file);
|
|
109 }
|
|
110 errno = 0;
|
|
111 return back;
|
|
112 }
|
|
113 #else
|
254
|
114
|
|
115 #ifdef WIN32
|
|
116
|
|
117 #define RETURN_OK 0
|
|
118 #define RETURN_FAIL 1
|
|
119
|
|
120 #include <windows.h>
|
|
121 char* loadFile(char* filename){
|
|
122 char* back=NULL;
|
|
123 DWORD size, numread;
|
|
124 HANDLE file=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
125 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
126 if (file != INVALID_HANDLE_VALUE){
|
|
127 size = GetFileSize(file, NULL);
|
|
128 if (size != INVALID_FILE_SIZE){
|
|
129 back=malloc((size+1)*sizeof(char));
|
292
|
130 if (ReadFile(file,back,size,&numread,NULL) == 1){
|
|
131 if (numread==size){
|
254
|
132 *(back+size+1) = '\x00';
|
292
|
133 }else{
|
254
|
134 back = "\x00";
|
292
|
135 }
|
|
136 }else{
|
254
|
137 back = "\x00";
|
292
|
138 }
|
254
|
139 }
|
|
140 CloseHandle(file);
|
|
141 }
|
|
142 errno = 0;
|
|
143 return back;
|
|
144 }
|
|
145 #else
|
251
|
146 #error no loadFile adaptation for this system available
|
|
147 #endif
|
|
148
|
254
|
149 #endif
|
|
150
|
251
|
151 int main(int argc, char* arg[]){
|
|
152
|
|
153 char* compiler;
|
|
154 char* general;
|
|
155 char* spezial;
|
|
156 char* cmd;
|
|
157 int modus;
|
|
158 int res;
|
|
159
|
|
160 /* check arguments */
|
|
161 if(argc != 3){
|
|
162 err: if(argc!=0)
|
|
163 fprintf(stderr,"%s <run|norun|compile|nocompile> <source>\n", arg[0]);
|
|
164 else
|
|
165 fprintf(stderr,"dstress.exe <run|norun|compile|nocompile> <source>\n");
|
|
166 exit(-1);
|
|
167 }
|
|
168
|
|
169 if(0==strcmp(arg[1], "run") || 0==strcmp(arg[1], "RUN")){
|
|
170 modus = RUN;
|
|
171 }else if(0==strcmp(arg[1], "norun") || 0==strcmp(arg[1], "NORUN")){
|
|
172 modus = NORUN;
|
|
173 }else if(0==strcmp(arg[1], "compile") || 0==strcmp(arg[1], "COMPILE")){
|
|
174 modus = COMPILE;
|
|
175 }else if(0==strcmp(arg[1], "nocompile") || 0==strcmp(arg[1], "NOCOMPILE")){
|
|
176 modus = NOCOMPILE;
|
|
177 }else{
|
|
178 goto err;
|
|
179 }
|
|
180
|
|
181 /* gen flags */
|
|
182 compiler = getCompiler();
|
|
183 general = getGeneralFlags();
|
|
184 cmd = loadFile(arg[2]);
|
|
185 if(cmd==NULL){
|
|
186 spezial="";
|
|
187 }else{
|
|
188 cmd = strstr(cmd, TAG);
|
|
189 if(cmd==NULL){
|
|
190 spezial="";
|
|
191 }else{
|
|
192 spezial = cmd + strlen(TAG);
|
|
193 cmd = strstr(spezial, "\n");
|
|
194 if(cmd!=NULL){
|
|
195 *cmd='\x00';
|
|
196 }
|
|
197 cmd = strstr(spezial, "\r");
|
|
198 if(cmd!=NULL){
|
|
199 *cmd='\x00';
|
|
200 }
|
|
201 }
|
|
202 }
|
|
203
|
|
204 if(modus==COMPILE || modus==NOCOMPILE){
|
|
205 /* gen command */
|
|
206 cmd = malloc(strlen(compiler)+strlen(general)+strlen(spezial)+strlen(OBJ)
|
|
207 +strlen(arg[2])+strlen(TLOG)+64);
|
|
208 cmd[0]='\x00';
|
|
209 strcat(cmd, compiler);
|
|
210 strcat(cmd, " ");
|
|
211 strcat(cmd, general);
|
|
212 strcat(cmd, " ");
|
|
213 strcat(cmd, spezial);
|
|
214 strcat(cmd, " -c ");
|
|
215 if(NULL==strstr(cmd, "-od")){
|
|
216 strcat(cmd, OBJ);
|
|
217 strcat(cmd, " ");
|
|
218 }
|
|
219 strcat(cmd, arg[2]);
|
|
220 strcat(cmd, " 1> ");
|
|
221 strcat(cmd, TLOG);
|
|
222 strcat(cmd, " 2>&1");
|
|
223
|
|
224 /* test */
|
|
225 if(modus==COMPILE){
|
|
226 fprintf(stderr, "compile: %s\n", cmd);
|
|
227 }else{
|
|
228 fprintf(stderr, "nocompile: %s\n", cmd);
|
|
229 }
|
|
230 res = system(cmd);
|
|
231
|
|
232 /* diagnostic output */
|
|
233 cmd = loadFile(TLOG);
|
|
234 fprintf(stderr, "%s\n", cmd);
|
|
235 if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){
|
|
236 printf("ERROR:\t%s (Internal compiler error)\n", arg[2]);
|
|
237 }else if(modus==COMPILE){
|
254
|
238 if(res==RETURN_OK){
|
251
|
239 printf("PASS: \t%s\n", arg[2]);
|
254
|
240 }else if(res==RETURN_FAIL){
|
251
|
241 printf("FAIL: \t%s [%d]\n", arg[2], res);
|
|
242 }else{
|
|
243 printf("ERROR:\t%s [%d]\n", arg[2], res);
|
|
244 }
|
|
245 }else{
|
254
|
246 if(res==RETURN_FAIL){
|
251
|
247 printf("XFAIL:\t%s\n", arg[2]);
|
254
|
248 }else if(res==RETURN_OK){
|
251
|
249 printf("XPASS:\t%s\n", arg[2]);
|
|
250 }else{
|
|
251 printf("ERROR:\t%s [%d]\n", arg[2], res);
|
|
252 }
|
|
253 }
|
|
254 fprintf(stderr,"--------\n");
|
|
255 }else if(modus==RUN || modus==NORUN){
|
|
256 /* gen command */
|
|
257 cmd = malloc(strlen(compiler)+strlen(general)+strlen(spezial)+strlen(OBJ)
|
|
258 +strlen(arg[2])*2+strlen(TLOG)+64);
|
|
259 cmd[0]='\x00';
|
|
260 strcat(cmd, compiler);
|
|
261 strcat(cmd, " ");
|
|
262 strcat(cmd, general);
|
|
263 strcat(cmd, " ");
|
|
264 strcat(cmd, spezial);
|
|
265 strcat(cmd, " ");
|
|
266 if(NULL==strstr(cmd, "-od")){
|
|
267 strcat(cmd, OBJ);
|
|
268 strcat(cmd, " ");
|
|
269 }
|
|
270 if(NULL==strstr(cmd, "-of")){
|
|
271 strcat(cmd, "-of");
|
|
272 strcat(cmd, arg[2]);
|
|
273 strcat(cmd, ".exe ");
|
|
274 }
|
|
275 strcat(cmd, arg[2]);
|
|
276 strcat(cmd, " 1> ");
|
|
277 strcat(cmd, TLOG);
|
|
278 strcat(cmd, " 2>&1");
|
|
279
|
|
280 /* test 1/2 */
|
|
281 if(modus==RUN){
|
|
282 fprintf(stderr, "run: %s\n", cmd);
|
|
283 }else{
|
|
284 fprintf(stderr, "norun: %s\n", cmd);
|
|
285 }
|
|
286 res = system(cmd);
|
|
287
|
|
288 /* diagnostic 1/2 */
|
|
289 cmd = loadFile(TLOG);
|
|
290 fprintf(stderr, "%s", cmd);
|
|
291 if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){
|
|
292 printf("ERROR:\t%s (Internal compiler error)\n", arg[2]);
|
|
293 fprintf(stderr, "\n--------\n");
|
|
294 return 0;
|
254
|
295 }else if(res==RETURN_FAIL){
|
251
|
296 printf("FAIL: \t%s [%d]\n", arg[2], res);
|
|
297 fprintf(stderr, "\n--------\n");
|
|
298 return 0;
|
254
|
299 }else if(res!=RETURN_OK){
|
251
|
300 printf("ERROR:\t%s [%d]\n", arg[2], res);
|
|
301 fprintf(stderr, "\n--------\n");
|
|
302 return 0;
|
|
303 }
|
|
304
|
|
305 /* test 2/2 */
|
261
|
306 cmd = malloc(strlen(arg[2]) + strlen(TLOG) + 24);
|
251
|
307 *cmd = '\x00';
|
|
308 strcat(cmd, arg[2]);
|
|
309 strcat(cmd, ".exe 1> ");
|
|
310 strcat(cmd, TLOG);
|
|
311 strcat(cmd, " 2>&1");
|
|
312 fprintf(stderr, "%s\n", cmd);
|
|
313 res=system(cmd);
|
|
314
|
|
315 /* diagnostic 2/2 */
|
|
316 cmd = loadFile(TLOG);
|
|
317 if(cmd==NULL || strlen(cmd)<2){
|
|
318 cmd="";
|
|
319 }
|
|
320 fprintf(stderr, "%s\n", cmd);
|
|
321 if(modus==RUN){
|
254
|
322 if(res==RETURN_OK){
|
251
|
323 printf("PASS: \t%s\n", arg[2]);
|
254
|
324 }else if(res==RETURN_FAIL){
|
251
|
325 printf("FAIL: \t%s [run: %d]\n", arg[2], res);
|
|
326 }else{
|
|
327 printf("ERROR:\t%s [run: %d]\n", arg[2], res);
|
|
328 }
|
|
329 }else{
|
254
|
330 if(res==RETURN_FAIL){
|
251
|
331 printf("XFAIL:\t%s\n", arg[2]);
|
254
|
332 }else if(res==RETURN_OK){
|
251
|
333 printf("XPASS:\t%s [norun: %d]\n", arg[2], res);
|
|
334 }else{
|
|
335 printf("ERROR:\t%s [norun: %d]\n", arg[2], res);
|
|
336 }
|
|
337 }
|
|
338 fprintf(stderr, "--------\n");
|
|
339 }else{
|
|
340 printf("@toto@ %d (%s)\n", modus, arg[2]);
|
|
341 }
|
|
342 return 0;
|
|
343 }
|