changeset 971:8da09834526d

* Valgrind support is now part of dstress.c instead of crashRun.c * fixed parallel build of test cases with multiple object files
author thomask
date Thu, 20 Apr 2006 08:50:01 +0000
parents 3a6109fe74c5
children 1429b206580f
files Makefile Makefile.parallel crashRun.c dstress.c
diffstat 4 files changed, 68 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Apr 20 06:04:53 2006 +0000
+++ b/Makefile	Thu Apr 20 08:50:01 2006 +0000
@@ -110,19 +110,10 @@
 #
 # the tools
 #
-$(return__) : return__.c Makefile
-	$(CC) $(CFLAGS) $< -o $@
-
-$(ifeq__) : ifeq__.c Makefile
-	$(CC) $(CFLAGS) $< -o $@
-
-$(extract__) : extract__.c Makefile
+% : %.c Makefile
 	$(CC) $(CFLAGS) $< -o $@
 
 $(dstress__) : dstress.c $(crashRun__) Makefile
-	$(CC) $(CFLAGS) $< -o $@
-
-$(crashRun__) : crashRun.c Makefile
 	$(CC) $(CFLAGS) -DUSE_VALGRIND $< -o $@
 
 basic_tools : $(ifeq__) $(return__) $(extract__) $(dstress__)
@@ -340,7 +331,7 @@
 	$(RM) $(OBJ_DIR)/[k-o]*.*
 	$(RM) $(OBJ_DIR)/[p-t]*.*
 	$(RM) $(OBJ_DIR)/[u-z]*.*
-	$(RM) $(OBJ_DIR)/?*.*
+	$(RM) -rf $(OBJ_DIR)/*
 	$(RM) run.sh norun.sh compile.sh nocompile.sh
 
 # the empty line above has to remain, otherwise some weired problems can arise
--- a/Makefile.parallel	Thu Apr 20 06:04:53 2006 +0000
+++ b/Makefile.parallel	Thu Apr 20 08:50:01 2006 +0000
@@ -71,9 +71,6 @@
 
 .PHONY:: all clean compile nocompile norun run tools version
 
-bug:
-	$(error not yet save for test cases involving multiple object files)
-	
 all :: version compile nocompile run norun
 
 % : %.c
@@ -141,7 +138,7 @@
 	$(RM) obj/[k-o]*.*
 	$(RM) obj/[p-t]*.*
 	$(RM) obj/[u-z]*.*
-	$(RM) obj/?*.*
+	$(RM) -rf obj/*
 	$(RM) run.sh norun.sh compile.sh nocompile.sh
 	$(RM) $(dstress) $(crashRun)
 
--- a/crashRun.c	Thu Apr 20 06:04:53 2006 +0000
+++ b/crashRun.c	Thu Apr 20 08:50:01 2006 +0000
@@ -34,7 +34,6 @@
 
 #undef WAIT_GUARD
 #define WAIT_GUARD 3
-#define VALGRIND "valgrind -q --suppressions=valgrind.suppress"
 
 /* time-out in seconds
  * Posix: cpu time(timeOut) and system time(timeOut * WAIT_GUARD)
@@ -224,14 +223,10 @@
 
 	for(i=0; i<argc; i++){
 		cmdLen+=strlen(argv[i]);
-		cmdLen+=3;
+		cmdLen+=1;
 	}
 
-#ifdef USE_VALGRIND
-	cmdLen += strlen(VALGRIND);
-#endif
-
-	cmd = malloc(cmdLen);
+	cmd = malloc(++cmdLen);
 	if(!cmd){
 		fprintf(stderr, "failed to allocate enough memory");
 		exit(EXIT_FAILURE);
@@ -240,14 +235,8 @@
 	*cmd = '\x00';
 	tmp = cmd;
 
-#ifdef USE_VALGRIND
-	tmpLen = snprintf(tmp, cmdLen, "%s ", VALGRIND);
-	tmp += tmpLen;
-	cmdLen -= tmpLen;
-#endif
-
 	for(i=0; i<argc; i++){
-		tmpLen = snprintf(tmp, cmdLen, "\"%s\" ", argv[i]);
+		tmpLen = snprintf(tmp, cmdLen, "%s ", argv[i]);
 		tmp += tmpLen;
 		cmdLen -= tmpLen;
 	}
--- a/dstress.c	Thu Apr 20 06:04:53 2006 +0000
+++ b/dstress.c	Thu Apr 20 08:50:01 2006 +0000
@@ -155,15 +155,24 @@
 
 #ifdef USE_POSIX
 #define		CRASH_RUN	"./crashRun 30 2000"
+#ifdef USE_VALGRIND
+#define		VALGRIND	"valgrind --leak-check=no -q --suppressions=valgrind.suppress"	
+#else
+#define		VALGRIND	""
+#endif
 #define		TMP_DIR		"./obj"
+#define		RM_DIR		"rm -rf"
 #else
 #ifdef USE_WINDOWS
+#define		VALGRIND	""
 #define		TMP_DIR		".\\obj"
 #else
 #error OS dependent file names not defined
 #endif
 #endif
 
+char* tmp_dir;
+
 #ifdef USE_WINDOWS
 HANDLE originalStdout, originalStderr;
 #endif
@@ -258,13 +267,13 @@
 	char* back;
 	size_t len;
 
-	len = strlen(TMP_DIR) + 128;
+	len = strlen(tmp_dir) + 128;
 	back = malloc(len);
 
 #ifdef USE_POSIX
-	snprintf(back, len, "%s/t%x-%x-%x.tmp", TMP_DIR, getpid(), rand(), ++genTempFileNameCount);
+	snprintf(back, len, "%s/t%x-%x-%x.tmp", tmp_dir, getpid(), rand(), ++genTempFileNameCount);
 #else
-	snprintf(back, len, "%s\\t%x-%x-%x.tmp", TMP_DIR, getpid(), rand(), ++genTempFileNameCount);
+	snprintf(back, len, "%s\\t%x-%x-%x.tmp", tmp_dir, getpid(), rand(), ++genTempFileNameCount);
 #endif
 
 	return back;
@@ -455,7 +464,9 @@
 		}
 	}
 
-	return calloc(1,1);
+	back = malloc(1);
+	back[0] = 0;
+	return back;
 }
 
 /* check compile-time error messages */
@@ -787,14 +798,14 @@
 	}
 
 	/* gen command */
-	bufferLen = strlen(compiler) + strlen(arguments) + strlen(TMP_DIR)
+	bufferLen = strlen(compiler) + strlen(arguments) + strlen(tmp_dir)
 		+ strlen(case_file) + 21;
 	buffer = malloc(bufferLen);
 	snprintf(buffer, bufferLen, "%s %s ", compiler, arguments);
 
 	if(NULL == strstr(buffer, "-od")){
 		snprintf(buffer, bufferLen, "%s %s -od%s -c %s",
-			compiler, arguments, TMP_DIR, case_file);
+			compiler, arguments, tmp_dir, case_file);
 	}else{
 		snprintf(buffer, bufferLen, "%s %s -c %s",
 			compiler, arguments, case_file);
@@ -877,7 +888,7 @@
 
 	/* gen command */
 
-	bufferLen = strlen(compiler) + strlen(arguments) + strlen(TMP_DIR)
+	bufferLen = strlen(compiler) + strlen(arguments) + strlen(tmp_dir)
 			+ strlen(case_file) * 2 + 64;
 	buffer = malloc(bufferLen);
 	snprintf(buffer, bufferLen, "%s %s ", compiler, arguments);
@@ -886,12 +897,12 @@
 		if(NULL == strstr(buffer, "-of")){
 			snprintf(buffer, bufferLen,
 				"%s %s -od%s -of%s.exe %s",
-				compiler, arguments, TMP_DIR, case_file,
+				compiler, arguments, tmp_dir, case_file,
 				case_file);
 		}else{
 			snprintf(buffer, bufferLen,
 				"%s %s -od%s %s",
-				compiler, arguments, TMP_DIR, case_file);
+				compiler, arguments, tmp_dir, case_file);
 		}
 	}else if(NULL == strstr(buffer, "-of")){
 		snprintf(buffer, bufferLen,
@@ -937,9 +948,15 @@
 	}
 
 	/* test 2/3 - run */
-	bufferLen = strlen(case_file) + 30;
-	buffer = malloc(bufferLen);
-	snprintf(buffer, bufferLen, "%s.exe", case_file);
+	if(VALGRIND && VALGRIND[0]){
+		bufferLen = strlen(VALGRIND) + strlen(case_file) + 8;
+		buffer = malloc(bufferLen);
+		snprintf(buffer, bufferLen, "%s %s.exe", VALGRIND, case_file);
+	}else{
+		bufferLen = strlen(case_file) + 8;
+		buffer = malloc(bufferLen);
+		snprintf(buffer, bufferLen, "%s.exe", case_file);
+	}
 	printf("%s\n", buffer);
 	res=crashRun(buffer, &logFile);
 	free(buffer);
@@ -1132,6 +1149,23 @@
 
 	free(buffer);
 
+	/* tmp_dir */
+	if(!cmd_arg_case || !cmd_arg_case[0]){
+		tmp_dir = TMP_DIR;
+	}else{
+		pid_t pid;
+		pid = getpid();
+		bufferLen = strlen(TMP_DIR) + 4 + sizeof(pid_t) * 4;
+		buffer = malloc(bufferLen);
+		snprintf(buffer, bufferLen, "%s/_%X", TMP_DIR, pid);
+		tmp_dir = cleanPathSeperator(buffer);
+		if(mkdir(tmp_dir, 0770)){
+			fprintf(stderr, "failed to create tmp dir: %s (%d, %s)\n",
+					tmp_dir, errno, strerror(errno));
+			return EXIT_FAILURE;
+		}
+	}
+
 	/* set implicit source file */
 	if(strcmp(error_line, "")!=0 && strcmp(error_file, "")==0){
 		error_file=case_file;
@@ -1270,16 +1304,16 @@
 			printf("--------\n");
 		}
 	}else{
-		if(torture_require){
-			if(!cmd_arg_case){
+		if(torture_require && !torture_require[0]){
+			if(!cmd_arg_case || !cmd_arg_case[0]){
 				torture_require = cmd_arg_case;
 			}else{
-				size_t new_len = strlen(cmd_arg_case);
-				new_len += strlen(torture_require);
-				new_len++;
-				cmd_arg_case = realloc(cmd_arg_case, new_len);
-				strcat(cmd_arg_case, " ");
-				strcat(cmd_arg_case, torture_require);
+				bufferLen = strlen(cmd_arg_case);
+				bufferLen += strlen(torture_require);
+				bufferLen += 2;
+				buffer = malloc(bufferLen);
+				snprintf(buffer, bufferLen, "%s %s", cmd_arg_case, torture_require);
+				cmd_arg_case = buffer;
 			}
 		}
 		if(modus & (MODE_RUN | MODE_NORUN)){
@@ -1303,5 +1337,13 @@
 		printResult(case_result, modus, case_file, stdout);
 	}
 
+	if(strcmp(TMP_DIR, tmp_dir)){
+		bufferLen = strlen(tmp_dir);
+		bufferLen += strlen(RM_DIR);
+		bufferLen += 2;
+		buffer = malloc(bufferLen);
+		snprintf(buffer, bufferLen, "%s %s", RM_DIR, tmp_dir);
+		system(buffer);
+	}
 	exit(EXIT_SUCCESS);
 }