changeset 251:6cd84461e17b

enabled new "dstress.c" test tool
author thomask
date Tue, 25 Jan 2005 20:10:03 +0000
parents d2728b26695a
children 9241d98c43f9
files Makefile dstress.c extract__.c ifeq__.c return__.c
diffstat 5 files changed, 333 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Jan 25 20:04:05 2005 +0000
+++ b/Makefile	Tue Jan 25 20:10:03 2005 +0000
@@ -83,6 +83,7 @@
 return__	:= ./return__
 ifeq__		:= ./ifeq__
 extract__	:= ./extract__
+dstress__	:= ./dstress__
 
 # settings
 to_log 		:= >> $(LOG) 2>&1
@@ -97,7 +98,7 @@
 complex_done 	:= complex.done
 flag_pattern 	:= __DSTRESS_DFLAGS__
 
-.PHONY: all basic_tools compile nocompile run norun complex clean distclean clean_log log
+.PHONY: all basic_tools compile nocompile run norun complex clean distclean clean_log
 
 .SUFFIXES: $(ext_run) $(ext_norun) $(ext_nocompile) $(ext_compile) 
 #
@@ -117,7 +118,10 @@
 $(extract__) : extract__.c Makefile
 	$(CC) $(CFLAGS) $< -o $@
 
-basic_tools : $(ifeq__) $(return__) $(extract__)
+$(dstress__) : dstress.c Makefile
+	$(CC) $(CFLAGS) $< -o $@
+
+basic_tools : $(ifeq__) $(return__) $(extract__) $(dstress__)
 	
 
 #
@@ -136,8 +140,13 @@
 #
 # target should fail to compile
 #
-nocompile : Makefile $(sort $(subst .$(ext_source),.$(ext_nocompile),$(shell $(FIND) nocompile -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_nocompile),$(shell $(FIND) nocompile -regex ".*\\.$(ext_source_html)" ) ) )
+nocompile : $(dstress__)
+	rm -f nocompile/*.o nocompile/*.$(ext_nocompile)
+	find nocompile/ -maxdepth 1 -name "?*.?*" | grep "." | sort | xargs --max-procs=1 --max-lines=1 echo "$(dstress__) nocompile" > nocompile.sh
+	chmod +x nocompile.sh
+	./nocompile.sh 2>> $(LOG)
 
+# used in some complex test cases
 define analyse_nocompile
 	@if $(ifeq__) $(z_return) 0 ; then \
 		$(ECHO) "XPASS: $(z_name)"; $(RM) $@; \
@@ -154,29 +163,16 @@
 	fi
 endef
 
-%.$(ext_nocompile) : %.$(ext_source) basic_tools
-	$(eval z_name = $(subst .$(ext_nocompile),,$@))
-	$(extract_z_flags)
-	$(eval z_log = $(z_name).$(ext_log))
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -od$(OBJ_DIR) $< > $(z_log) 2>&1"))
-	@$(CAT) $(z_log) $(to_log)
-	$(analyse_nocompile)
-	@$(RM) $(z_log)
-
-%.$(ext_nocompile) : %.$(ext_source_html) basic_tools
-	$(eval z_name = $(subst .$(ext_nocompile),,$@))
-	$(extract_z_flags)
-	$(eval z_log = $(z_name).$(ext_log))
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -od$(OBJ_DIR) $< > $(z_log) 2>&1"))
-	@$(CAT) $(z_log) $(to_log)
-	$(analyse_nocompile)
-	@$(RM) $(z_log)
-
 #
 # target should compile (excludes linking)
 #
-compile : Makefile $(sort $(subst .$(ext_source),.$(ext_compile),$(shell $(FIND) compile -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_compile),$(shell $(FIND) compile -regex ".*\\.$(ext_source_html)" ) ) )
+compile : $(dstress__)
+	rm -f compile/*.o compile/*.$(ext_compile)
+	find compile/ -maxdepth 1 -name "?*.?*" | grep "." | sort | xargs --max-procs=1 --max-lines=1 echo "$(dstress__) compile" > compile.sh
+	chmod +x compile.sh
+	./compile.sh 2>> $(LOG)
 
+# used in some complex test cases
 define analyse_compile
 	@if $(ifeq__) $(z_return) 0 ; then \
 		$(ECHO) "PASS:  $(z_name)"; $(TOUCH) $@; \
@@ -189,24 +185,16 @@
 	fi
 endef
 
-%.$(ext_compile) : %.$(ext_source) basic_tools
-	$(eval z_name = $(subst .$(ext_compile),,$@))
-	$(extract_z_flags)
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -od$(OBJ_DIR) $< $(to_log)"))
-	$(analyse_compile)
-
-
-%.$(ext_compile) : %.$(ext_source_html) basic_tools
-	$(eval z_name = $(subst .$(ext_compile),,$@))
-	$(extract_z_flags)
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -od$(OBJ_DIR) $< $(to_log)"))
-	$(analyse_compile)
-
 # 
 # target should compile, link and run
 # 
-run : Makefile $(sort $(subst .$(ext_source),.$(ext_run),$(shell $(FIND) run -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_run),$(shell $(FIND) run -regex ".*\\.$(ext_source_html)" ) ) )
+run : $(dstress__)
+	rm -f run/*.exe run/*.$(ext_run)
+	find run/ -maxdepth 1 -name "?*.?*" | grep "." | sort | xargs --max-procs=1 --max-lines=1 echo "$(dstress__) run" > run.sh
+	chmod +x run.sh
+	./run.sh 2>> $(LOG)
 
+# used in some complex testcases
 define analyse_run
 	@if $(ifeq__) $(z_return) 0 ; then \
 		$(eval z_return2 = $(shell $(return__) "./$@ $(to_log)")) \
@@ -228,18 +216,6 @@
 	fi
 endef
 
-%.$(ext_run) : %.$(ext_source) basic_tools
-	$(eval z_name = $(subst .$(ext_run),,$@))
-	$(extract_z_flags)
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)"))
-	$(analyse_run)
-
-%.$(ext_run) : %.$(ext_source_html) basic_tools
-	$(eval z_name = $(subst .$(ext_run),,$@))
-	$(extract_z_flags)
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)"))
-	$(analyse_run)
-
 #
 # target should compile, link and run
 # (used for Makefile diagnosis)
@@ -277,8 +253,13 @@
 #
 # target should compile and link but fail to run
 # 
-norun : Makefile $(sort $(subst .$(ext_source),.$(ext_norun),$(shell $(FIND) norun -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_norun),$(shell $(FIND) norun -regex ".*\\.$(ext_source_html)" ) ) )
+norun : $(dstress__)
+	rm -f norun/*.exe norun/*.$(ext_norun)
+	find norun/ -maxdepth 1 -name "?*.?*" | grep "." | sort | xargs --max-procs=1 --max-lines=1 echo "$(dstress__) norun" > norun.sh
+	chmod +x norun.sh
+	./norun.sh 2>> $(LOG)
 
+# used in some complex test cases
 define analyse_norun
 	@if $(ifeq__) $(z_return) 0; then \
 		if ./$@ $(to_log); \
@@ -295,33 +276,17 @@
 	fi
 endef
 
-%.$(ext_norun) : %.$(ext_source) basic_tools
-	$(eval z_name = $(subst .$(ext_norun),,$@))
-	$(extract_z_flags)
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)"))
-	$(analyse_norun)
-
-%.$(ext_norun) : %.$(ext_source_html) Makefile 
-	$(eval z_name = $(subst .$(ext_norun),,$@))
-	$(extract_z_flags)
-	$(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)"))
-	$(analyse_norun)
-
-
 #
 # run all complex test cases
 #
-complex : $(sort $(subst $(complex_todo),$(complex_done),$(complex_makefiles)))
-
-
-log : distclean all
+complex : basic_tools $(sort $(subst $(complex_todo),$(complex_done),$(complex_makefiles)))
 
 #
 # 
 #
 distclean : clean_log clean
-	$(RM) $(shell $(FIND) . -regex ".*~") $(shell $(FIND) . -regex "\\..*\\.swp")
-	$(RM) return__ ifeq__ extract__ www/*.class
+	$(RM) $(shell $(FIND) . -regex ".*~") $(shell $(FIND) . -regex "\\..*\\.swp") $(shell $(FIND) . -regex "#.*#")
+	$(RM) $(return__) $(ifeq__) $(extract__) $(dstress__) www/*.class
 
 #
 # remove compiler and assertion messages
@@ -335,5 +300,6 @@
 clean : $(sort $(subst $(complex_todo),clean,$(complex_makefiles)))
 	$(RM) $(OBJ_DIR)/?*.?* nocompile/?*.$(ext_log)
 	$(RM) run/?*.$(ext_run) norun/?*.$(ext_norun) compile/?*.$(ext_compile) nocompile/?*.$(ext_nocompile)
+	$(RM) run.sh norun.sh compile.sh nocompile.sh
 
 # the empty line above has to remain, otherwise some weired problems can arise
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstress.c	Tue Jan 25 20:10:03 2005 +0000
@@ -0,0 +1,296 @@
+/* 
+ * core test tool for the DStress test suite 
+ * http://dstress.kuehne.cn
+ *
+ * Copyright (C) 2005 Thomas Kuehne <thomas@kuehne.cn>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * $HeadURL$
+ * $Date$
+ * $Author$
+ *
+ */                                             
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#define TAG 		"__DSTRESS_DFLAGS__"
+#define OBJ		"-odobj "
+#define TLOG		"log.tmp"
+
+#define RUN		1
+#define NORUN		2
+#define COMPILE		4
+#define NOCOMPILE	8
+
+/* Query the environment for the compiler name */
+char* getCompiler(){
+	char* back = getenv("DMD");
+	if(back == NULL){
+		back = getenv("dmd");
+		if(back==NULL){
+			back = "dmd";
+		}
+	}
+	return back;
+}
+
+/* Query the environment for general flags */
+char* getGeneralFlags(){
+	char* back = getenv("DFLAGS");
+	if(back == NULL){
+		back = getenv("dflags");
+		if(back==NULL){
+			back = "";
+		}
+	}
+	return back;
+}
+
+#ifdef __GNU_LIBRARY__
+#define USE_POSIX_LOAD
+#endif
+
+#ifdef __GLIBC__
+#define USE_POSIX_LOAD
+#endif
+
+#ifdef linux
+#define USE_POSIX_LOAD
+#endif
+
+#ifdef USE_POSIX_LOAD
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+char* loadFile(char* filename){
+	char* back = NULL;
+	struct stat fileInfo;
+	int file = open(filename, O_RDONLY);
+	if(errno == 0 && file != 0 && file != -1){
+		if(0==fstat(file, &fileInfo)){
+			back=malloc(fileInfo.st_size+1);
+			fileInfo.st_size = read(file, back, fileInfo.st_size);
+			if(fileInfo.st_size != -1){
+				*(back+fileInfo.st_size+1) = '\x00';
+			}else{
+				*back = '\x00';
+			}
+		}
+		close(file);
+	}
+	errno = 0;
+	return back;
+}
+#else
+#error no loadFile adaptation for this system available
+#endif
+
+int main(int argc, char* arg[]){
+
+	char* compiler;
+	char* general;
+	char* spezial;
+	char* cmd;
+	int modus;
+	int res;
+	
+	/* check arguments */
+	if(argc != 3){
+err:		if(argc!=0)		
+			fprintf(stderr,"%s <run|norun|compile|nocompile> <source>\n", arg[0]);
+		else
+			fprintf(stderr,"dstress.exe <run|norun|compile|nocompile> <source>\n");
+		exit(-1);
+	}
+	
+	if(0==strcmp(arg[1], "run") || 0==strcmp(arg[1], "RUN")){
+		modus = RUN;
+	}else if(0==strcmp(arg[1], "norun") || 0==strcmp(arg[1], "NORUN")){
+		modus = NORUN;
+	}else if(0==strcmp(arg[1], "compile") || 0==strcmp(arg[1], "COMPILE")){
+		modus = COMPILE;
+	}else if(0==strcmp(arg[1], "nocompile") || 0==strcmp(arg[1], "NOCOMPILE")){
+		modus = NOCOMPILE;
+	}else{
+		goto err;
+	}
+
+	/* gen flags */
+	compiler = getCompiler();
+	general = getGeneralFlags();
+	cmd = loadFile(arg[2]);
+	if(cmd==NULL){
+		spezial="";
+	}else{
+		cmd = strstr(cmd, TAG);
+		if(cmd==NULL){
+			spezial="";
+		}else{
+			spezial = cmd + strlen(TAG);
+			cmd = strstr(spezial, "\n");
+			if(cmd!=NULL){
+				*cmd='\x00';
+			}
+			cmd = strstr(spezial, "\r");
+			if(cmd!=NULL){
+				*cmd='\x00';
+			}
+		}
+	}
+
+	if(modus==COMPILE || modus==NOCOMPILE){
+		/* gen command */
+		cmd = malloc(strlen(compiler)+strlen(general)+strlen(spezial)+strlen(OBJ)
+			+strlen(arg[2])+strlen(TLOG)+64);
+		cmd[0]='\x00';
+		strcat(cmd, compiler);
+		strcat(cmd, " ");
+		strcat(cmd, general);
+		strcat(cmd, " ");
+		strcat(cmd, spezial);
+		strcat(cmd, " -c ");
+		if(NULL==strstr(cmd, "-od")){
+			strcat(cmd, OBJ);
+			strcat(cmd, " ");
+		}
+		strcat(cmd, arg[2]);
+		strcat(cmd, " 1> ");
+		strcat(cmd, TLOG);
+		strcat(cmd, " 2>&1");
+
+		/* test */
+		if(modus==COMPILE){
+			fprintf(stderr, "compile: %s\n", cmd);
+		}else{
+			fprintf(stderr, "nocompile: %s\n", cmd);
+		}
+		res = system(cmd);
+
+		/* diagnostic output */
+		cmd = loadFile(TLOG);
+		fprintf(stderr, "%s\n", cmd);
+		if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){
+			printf("ERROR:\t%s (Internal compiler error)\n", arg[2]);
+		}else if(modus==COMPILE){
+			if(res==0){
+				printf("PASS: \t%s\n", arg[2]);
+			}else if(res==256){
+				printf("FAIL: \t%s [%d]\n", arg[2], res);
+			}else{
+				printf("ERROR:\t%s [%d]\n", arg[2], res);
+			}
+		}else{
+			if(res==256){
+				printf("XFAIL:\t%s\n", arg[2]);
+			}else if(res==0){
+				printf("XPASS:\t%s\n", arg[2]);
+			}else{
+				printf("ERROR:\t%s [%d]\n", arg[2], res);
+			}
+		}
+		fprintf(stderr,"--------\n");
+	}else if(modus==RUN || modus==NORUN){
+		/* gen command */
+		cmd = malloc(strlen(compiler)+strlen(general)+strlen(spezial)+strlen(OBJ)
+			+strlen(arg[2])*2+strlen(TLOG)+64);
+		cmd[0]='\x00';
+		strcat(cmd, compiler);
+		strcat(cmd, " ");
+		strcat(cmd, general);
+		strcat(cmd, " ");
+		strcat(cmd, spezial);
+		strcat(cmd, " ");
+		if(NULL==strstr(cmd, "-od")){
+			strcat(cmd, OBJ);
+			strcat(cmd, " ");
+		}
+		if(NULL==strstr(cmd, "-of")){
+			strcat(cmd, "-of");
+			strcat(cmd, arg[2]);
+			strcat(cmd, ".exe ");
+		}
+		strcat(cmd, arg[2]);
+		strcat(cmd, " 1> ");
+		strcat(cmd, TLOG);
+		strcat(cmd, " 2>&1");
+
+		/* test 1/2 */
+		if(modus==RUN){
+			fprintf(stderr, "run: %s\n", cmd);
+		}else{
+			fprintf(stderr, "norun: %s\n", cmd);
+		}
+		res = system(cmd);
+		
+		/* diagnostic 1/2 */
+		cmd = loadFile(TLOG);
+		fprintf(stderr, "%s", cmd);
+		if(strstr(cmd, "Internal error")!= NULL || strstr(cmd, "gcc.gnu.org/bugs")!=NULL){
+			printf("ERROR:\t%s (Internal compiler error)\n", arg[2]);
+			fprintf(stderr, "\n--------\n");
+			return 0;
+		}else if(res==256){
+			printf("FAIL: \t%s [%d]\n", arg[2], res);
+			fprintf(stderr, "\n--------\n");
+			return 0;
+		}else if(res!=0){
+			printf("ERROR:\t%s [%d]\n", arg[2], res);
+			fprintf(stderr, "\n--------\n");
+			return 0;
+		}
+		
+		/* test 2/2 */
+		*cmd = '\x00';
+		strcat(cmd, arg[2]);
+		strcat(cmd, ".exe 1> ");
+		strcat(cmd, TLOG);
+		strcat(cmd, " 2>&1");
+		fprintf(stderr, "%s\n", cmd);
+		res=system(cmd);
+		
+		/* diagnostic 2/2 */
+		cmd = loadFile(TLOG);
+		if(cmd==NULL || strlen(cmd)<2){
+			cmd="";
+		}
+		fprintf(stderr, "%s\n", cmd);
+		if(modus==RUN){
+			if(res==0){
+				printf("PASS: \t%s\n", arg[2]);
+			}else if(res==256){
+				printf("FAIL: \t%s [run: %d]\n", arg[2], res);
+			}else{
+				printf("ERROR:\t%s [run: %d]\n", arg[2], res);
+			}
+		}else{
+			if(res==256){
+				printf("XFAIL:\t%s\n", arg[2]);
+			}else if(res==0){
+				printf("XPASS:\t%s [norun: %d]\n", arg[2], res);
+			}else{
+				printf("ERROR:\t%s [norun: %d]\n", arg[2], res);
+			}
+		}
+		fprintf(stderr, "--------\n");
+	}else{
+		printf("@toto@ %d (%s)\n", modus, arg[2]);
+	}
+	return 0;
+}
--- a/extract__.c	Tue Jan 25 20:04:05 2005 +0000
+++ b/extract__.c	Tue Jan 25 20:10:03 2005 +0000
@@ -1,6 +1,7 @@
 /* svn://svn.kuehne.cn/dstress/extract__.c
  *
  * extract compiler flags for DStress test cases
+ * [deprecated: use dstress.c]
  *
  * Copyright (C) 2004, 2005 Thomas Kuehne
  *
--- a/ifeq__.c	Tue Jan 25 20:04:05 2005 +0000
+++ b/ifeq__.c	Tue Jan 25 20:10:03 2005 +0000
@@ -1,6 +1,7 @@
 /* svn://svn.kuehne.cn/dstress/ifeq__.c
  *
  * compare the 2 input arguments (shell & OS independent)
+ * [deprecated: use dstress.c]
  *
  * Copyright (C) 2004, 2005 Thomas Kuehne
  *
--- a/return__.c	Tue Jan 25 20:04:05 2005 +0000
+++ b/return__.c	Tue Jan 25 20:10:03 2005 +0000
@@ -1,6 +1,7 @@
 /* svn://svn.kuehne.cn/dstress/return__.c
  *
  * execute the first argument and print the return code
+ * [deprecated: use dstress.c]
  *
  * Copyright (C) 2004, 2005 Thomas Kuehne
  *