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
|
|
77 #ifdef USE_POSIX_LOAD
|
254
|
78
|
|
79 #define RETURN_OK 0
|
|
80 #define RETURN_FAIL 256
|
|
81
|
251
|
82 #include <sys/types.h>
|
|
83 #include <sys/stat.h>
|
|
84 #include <fcntl.h>
|
|
85 #include <unistd.h>
|
|
86 char* loadFile(char* filename){
|
|
87 char* back = NULL;
|
|
88 struct stat fileInfo;
|
|
89 int file = open(filename, O_RDONLY);
|
|
90 if(errno == 0 && file != 0 && file != -1){
|
|
91 if(0==fstat(file, &fileInfo)){
|
|
92 back=malloc(fileInfo.st_size+1);
|
|
93 fileInfo.st_size = read(file, back, fileInfo.st_size);
|
254
|
94 if(fileInfo.st_size>0){
|
251
|
95 *(back+fileInfo.st_size+1) = '\x00';
|
|
96 }else{
|
254
|
97 back = "\x00";
|
251
|
98 }
|
|
99 }
|
|
100 close(file);
|
|
101 }
|
|
102 errno = 0;
|
|
103 return back;
|
|
104 }
|
|
105 #else
|
254
|
106
|
|
107 #ifdef WIN32
|
|
108
|
|
109 #define RETURN_OK 0
|
|
110 #define RETURN_FAIL 1
|
|
111
|
|
112 #include <windows.h>
|
|
113 char* loadFile(char* filename){
|
|
114 char* back=NULL;
|
|
115 DWORD size, numread;
|
|
116 HANDLE file=CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
117 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
118 if (file != INVALID_HANDLE_VALUE){
|
|
119 size = GetFileSize(file, NULL);
|
|
120 if (size != INVALID_FILE_SIZE){
|
|
121 back=malloc((size+1)*sizeof(char));
|
|
122 if (ReadFile(file,back,size,&numread,NULL) == 0){
|
|
123 if (numread==size)
|
|
124 *(back+size+1) = '\x00';
|
|
125 else
|
|
126 back = "\x00";
|
|
127 }else
|
|
128 back = "\x00";
|
|
129 }
|
|
130 CloseHandle(file);
|
|
131 }
|
|
132 errno = 0;
|
|
133 return back;
|
|
134 }
|
|
135 #else
|
251
|
136 #error no loadFile adaptation for this system available
|
|
137 #endif
|
|
138
|
254
|
139 #endif
|
|
140
|
251
|
141 int main(int argc, char* arg[]){
|
|
142
|
|
143 char* compiler;
|
|
144 char* general;
|
|
145 char* spezial;
|
|
146 char* cmd;
|
|
147 int modus;
|
|
148 int res;
|
|
149
|
|
150 /* check arguments */
|
|
151 if(argc != 3){
|
|
152 err: if(argc!=0)
|
|
153 fprintf(stderr,"%s <run|norun|compile|nocompile> <source>\n", arg[0]);
|
|
154 else
|
|
155 fprintf(stderr,"dstress.exe <run|norun|compile|nocompile> <source>\n");
|
|
156 exit(-1);
|
|
157 }
|
|
158
|
|
159 if(0==strcmp(arg[1], "run") || 0==strcmp(arg[1], "RUN")){
|
|
160 modus = RUN;
|
|
161 }else if(0==strcmp(arg[1], "norun") || 0==strcmp(arg[1], "NORUN")){
|
|
162 modus = NORUN;
|
|
163 }else if(0==strcmp(arg[1], "compile") || 0==strcmp(arg[1], "COMPILE")){
|
|
164 modus = COMPILE;
|
|
165 }else if(0==strcmp(arg[1], "nocompile") || 0==strcmp(arg[1], "NOCOMPILE")){
|
|
166 modus = NOCOMPILE;
|
|
167 }else{
|
|
168 goto err;
|
|
169 }
|
|
170
|
|
171 /* gen flags */
|
|
172 compiler = getCompiler();
|
|
173 general = getGeneralFlags();
|
|
174 cmd = loadFile(arg[2]);
|
|
175 if(cmd==NULL){
|
|
176 spezial="";
|
|
177 }else{
|
|
178 cmd = strstr(cmd, TAG);
|
|
179 if(cmd==NULL){
|
|
180 spezial="";
|
|
181 }else{
|
|
182 spezial = cmd + strlen(TAG);
|
|
183 cmd = strstr(spezial, "\n");
|
|
184 if(cmd!=NULL){
|
|
185 *cmd='\x00';
|
|
186 }
|
|
187 cmd = strstr(spezial, "\r");
|
|
188 if(cmd!=NULL){
|
|
189 *cmd='\x00';
|
|
190 }
|
|
191 }
|
|
192 }
|
|
193
|
|
194 if(modus==COMPILE || modus==NOCOMPILE){
|
|
195 /* gen command */
|
|
196 cmd = malloc(strlen(compiler)+strlen(general)+strlen(spezial)+strlen(OBJ)
|
|
197 +strlen(arg[2])+strlen(TLOG)+64);
|
|
198 cmd[0]='\x00';
|
|
199 strcat(cmd, compiler);
|
|
200 strcat(cmd, " ");
|
|
201 strcat(cmd, general);
|
|
202 strcat(cmd, " ");
|
|
203 strcat(cmd, spezial);
|
|
204 strcat(cmd, " -c ");
|
|
205 if(NULL==strstr(cmd, "-od")){
|
|
206 strcat(cmd, OBJ);
|
|
207 strcat(cmd, " ");
|
|
208 }
|
|
209 strcat(cmd, arg[2]);
|
|
210 strcat(cmd, " 1> ");
|
|
211 strcat(cmd, TLOG);
|
|
212 strcat(cmd, " 2>&1");
|
|
213
|
|
214 /* test */
|
|
215 if(modus==COMPILE){
|
|
216 fprintf(stderr, "compile: %s\n", cmd);
|
|
217 }else{
|
|
218 fprintf(stderr, "nocompile: %s\n", cmd);
|
|
219 }
|
|
220 res = system(cmd);
|
|
221
|
|
222 /* diagnostic output */
|
|
223 cmd = loadFile(TLOG);
|
|
224 fprintf(stderr, "%s\n", cmd);
|
|
225 if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){
|
|
226 printf("ERROR:\t%s (Internal compiler error)\n", arg[2]);
|
|
227 }else if(modus==COMPILE){
|
254
|
228 if(res==RETURN_OK){
|
251
|
229 printf("PASS: \t%s\n", arg[2]);
|
254
|
230 }else if(res==RETURN_FAIL){
|
251
|
231 printf("FAIL: \t%s [%d]\n", arg[2], res);
|
|
232 }else{
|
|
233 printf("ERROR:\t%s [%d]\n", arg[2], res);
|
|
234 }
|
|
235 }else{
|
254
|
236 if(res==RETURN_FAIL){
|
251
|
237 printf("XFAIL:\t%s\n", arg[2]);
|
254
|
238 }else if(res==RETURN_OK){
|
251
|
239 printf("XPASS:\t%s\n", arg[2]);
|
|
240 }else{
|
|
241 printf("ERROR:\t%s [%d]\n", arg[2], res);
|
|
242 }
|
|
243 }
|
|
244 fprintf(stderr,"--------\n");
|
|
245 }else if(modus==RUN || modus==NORUN){
|
|
246 /* gen command */
|
|
247 cmd = malloc(strlen(compiler)+strlen(general)+strlen(spezial)+strlen(OBJ)
|
|
248 +strlen(arg[2])*2+strlen(TLOG)+64);
|
|
249 cmd[0]='\x00';
|
|
250 strcat(cmd, compiler);
|
|
251 strcat(cmd, " ");
|
|
252 strcat(cmd, general);
|
|
253 strcat(cmd, " ");
|
|
254 strcat(cmd, spezial);
|
|
255 strcat(cmd, " ");
|
|
256 if(NULL==strstr(cmd, "-od")){
|
|
257 strcat(cmd, OBJ);
|
|
258 strcat(cmd, " ");
|
|
259 }
|
|
260 if(NULL==strstr(cmd, "-of")){
|
|
261 strcat(cmd, "-of");
|
|
262 strcat(cmd, arg[2]);
|
|
263 strcat(cmd, ".exe ");
|
|
264 }
|
|
265 strcat(cmd, arg[2]);
|
|
266 strcat(cmd, " 1> ");
|
|
267 strcat(cmd, TLOG);
|
|
268 strcat(cmd, " 2>&1");
|
|
269
|
|
270 /* test 1/2 */
|
|
271 if(modus==RUN){
|
|
272 fprintf(stderr, "run: %s\n", cmd);
|
|
273 }else{
|
|
274 fprintf(stderr, "norun: %s\n", cmd);
|
|
275 }
|
|
276 res = system(cmd);
|
|
277
|
|
278 /* diagnostic 1/2 */
|
|
279 cmd = loadFile(TLOG);
|
|
280 fprintf(stderr, "%s", cmd);
|
|
281 if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){
|
|
282 printf("ERROR:\t%s (Internal compiler error)\n", arg[2]);
|
|
283 fprintf(stderr, "\n--------\n");
|
|
284 return 0;
|
254
|
285 }else if(res==RETURN_FAIL){
|
251
|
286 printf("FAIL: \t%s [%d]\n", arg[2], res);
|
|
287 fprintf(stderr, "\n--------\n");
|
|
288 return 0;
|
254
|
289 }else if(res!=RETURN_OK){
|
251
|
290 printf("ERROR:\t%s [%d]\n", arg[2], res);
|
|
291 fprintf(stderr, "\n--------\n");
|
|
292 return 0;
|
|
293 }
|
|
294
|
|
295 /* test 2/2 */
|
|
296 *cmd = '\x00';
|
|
297 strcat(cmd, arg[2]);
|
|
298 strcat(cmd, ".exe 1> ");
|
|
299 strcat(cmd, TLOG);
|
|
300 strcat(cmd, " 2>&1");
|
|
301 fprintf(stderr, "%s\n", cmd);
|
|
302 res=system(cmd);
|
|
303
|
|
304 /* diagnostic 2/2 */
|
|
305 cmd = loadFile(TLOG);
|
|
306 if(cmd==NULL || strlen(cmd)<2){
|
|
307 cmd="";
|
|
308 }
|
|
309 fprintf(stderr, "%s\n", cmd);
|
|
310 if(modus==RUN){
|
254
|
311 if(res==RETURN_OK){
|
251
|
312 printf("PASS: \t%s\n", arg[2]);
|
254
|
313 }else if(res==RETURN_FAIL){
|
251
|
314 printf("FAIL: \t%s [run: %d]\n", arg[2], res);
|
|
315 }else{
|
|
316 printf("ERROR:\t%s [run: %d]\n", arg[2], res);
|
|
317 }
|
|
318 }else{
|
254
|
319 if(res==RETURN_FAIL){
|
251
|
320 printf("XFAIL:\t%s\n", arg[2]);
|
254
|
321 }else if(res==RETURN_OK){
|
251
|
322 printf("XPASS:\t%s [norun: %d]\n", arg[2], res);
|
|
323 }else{
|
|
324 printf("ERROR:\t%s [norun: %d]\n", arg[2], res);
|
|
325 }
|
|
326 }
|
|
327 fprintf(stderr, "--------\n");
|
|
328 }else{
|
|
329 printf("@toto@ %d (%s)\n", modus, arg[2]);
|
|
330 }
|
|
331 return 0;
|
|
332 }
|