Changed SetUpLogger based on CR.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Sun, 31 Jul 2011 20:01:34 +0300
changeset 5795 134c0f7ae826
parent 5794 e39e9c62c671
child 5796 610df1cc7b4a
Changed SetUpLogger based on CR.
test/test-automation/build-scripts/install-tests.sh
test/test-automation/logger.h
test/test-automation/plain_logger.c
test/test-automation/runner.c
test/test-automation/xml_logger.c
--- a/test/test-automation/build-scripts/install-tests.sh	Sun Jul 31 19:08:38 2011 +0300
+++ b/test/test-automation/build-scripts/install-tests.sh	Sun Jul 31 20:01:34 2011 +0300
@@ -21,6 +21,6 @@
 	cp -f "$suite/.libs/lib$suite.$EXT" $DIRECTORY
 done
 
-sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib
+#sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib
 
 echo "Test suites installed."
--- a/test/test-automation/logger.h	Sun Jul 31 19:08:38 2011 +0300
+++ b/test/test-automation/logger.h	Sun Jul 31 20:01:34 2011 +0300
@@ -24,11 +24,12 @@
 #include <time.h>
 
 /* Logging levels */
-typedef enum Level {
-	STANDARD = 1,
-	VERBOSE
+typedef enum LogLevel {
+	LOGGER_TERSE = 1,
+	LOGGER_VERBOSE
 } Level;
 
+#define LOGGER_DEFAULT_LEVEL LOGGER_TERSE
 
 typedef struct LoggerData {
 	//! If enabled logger will write to stdout instead of file
--- a/test/test-automation/plain_logger.c	Sun Jul 31 19:08:38 2011 +0300
+++ b/test/test-automation/plain_logger.c	Sun Jul 31 20:01:34 2011 +0300
@@ -13,7 +13,7 @@
 static int indentLevel;
 
 /*! Logging level of the logger */
-static Level level = STANDARD;
+static Level level = LOGGER_TERSE;
 
 //! Handle to log file
 static FILE *logFile;
@@ -155,7 +155,7 @@
 		time_t eventTime)
 {
 	// Log passed asserts only on VERBOSE level
-	if(level <= STANDARD && assertResult == ASSERT_PASS) {
+	if(level <= LOGGER_TERSE && assertResult == ASSERT_PASS) {
 		return ;
 	}
 
@@ -168,7 +168,7 @@
 		int actualValue, int expectedValue, time_t eventTime)
 {
 	// Log passed asserts only on VERBOSE level
-	if(level <= STANDARD && assertResult == ASSERT_PASS) {
+	if(level <= LOGGER_TERSE && assertResult == ASSERT_PASS) {
 		return ;
 	}
 
--- a/test/test-automation/runner.c	Sun Jul 31 19:08:38 2011 +0300
+++ b/test/test-automation/runner.c	Sun Jul 31 20:01:34 2011 +0300
@@ -106,6 +106,12 @@
 //! Default directory of the test suites
 #define DEFAULT_LOG_FILENAME "runner"
 
+//! Defines directory separator
+#define DIRECTORY_SEPARATOR '/'
+
+//! Name of the default stylesheet
+const char *defaultXSLStylesheet = "style.xsl";
+
 //! Fuzzer seed for the harness
 char *runSeed = NULL;
 
@@ -256,7 +262,7 @@
 				SDL_snprintf(reference->name, nameSize, "%s", name);
 
 				// copy the directory path
-				const int dpSize = dirSize + nameSize + 1 + extSize + 1;
+				const Uint32 dpSize = dirSize + nameSize + 1 + extSize + 1;
 				reference->directoryPath = SDL_malloc(dpSize * sizeof(char));
 				if(reference->directoryPath == NULL) {
 					SDL_free(reference->name);
@@ -891,7 +897,8 @@
  * \return Logger data structure (that needs be deallocated)
  */
 LoggerData *
-SetUpLogger()
+SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_enabled,
+			const int custom_xsl_enabled, const char *defaultXslSheet)
 {
 	LoggerData *loggerData = SDL_malloc(sizeof(LoggerData));
 	if(loggerData == NULL) {
@@ -900,7 +907,7 @@
 	}
 	memset(loggerData, 0, sizeof(LoggerData));
 
-	loggerData->level = (enable_verbose_logger ? VERBOSE : STANDARD);
+	loggerData->level = (enable_verbose_logger ? LOGGER_VERBOSE : LOGGER_TERSE);
 
 	if(log_stdout_enabled == 1) {
 		loggerData->stdoutEnabled = 1;
@@ -910,20 +917,24 @@
 
 		const char *extension = (xml_enabled ? "xml" : "log");
 
-		/* Combine and create directory for log file */
-		// log_directory + log_basename + seed + . + type
-		const int directoryLength = SDL_strlen(log_directory);
-		const int basenameLength = SDL_strlen(log_basename);
-		const int seedLength = SDL_strlen(runSeed);
-		const int extensionLength = SDL_strlen(extension);
-
 		// create directory (if it doesn't exist yet)
 		unsigned int mode = S_IRWXU | S_IRGRP | S_ISUID;
 		mkdir(log_directory, mode);
 
+		/* Combine and create directory for log file */
+		const Uint32 directoryLength = SDL_strlen(log_directory);
+		const Uint32 basenameLength = SDL_strlen(log_basename);
+		const Uint32 seedLength = SDL_strlen(runSeed);
+		const Uint32 extensionLength = SDL_strlen(extension);
+
 		// couple of extras bytes for '/', '-', '.' and '\0' at the end
-		const int length = directoryLength + basenameLength + seedLength
+		const Uint32 length = directoryLength + basenameLength + seedLength
 							+ extensionLength + 4;
+
+		if(length <= 0) {
+			return NULL;
+		}
+
 		char *filename = SDL_malloc(length);
 		if(filename == NULL) {
 			SDL_free(loggerData);
@@ -933,8 +944,8 @@
 		}
 		memset(filename, 0, length);
 
-		SDL_snprintf(filename, length, "%s/%s-%s.%s", log_directory, log_basename,
-					 runSeed, extension);
+		SDL_snprintf(filename, length, "%s%c%s-%s.%s", log_directory,
+				DIRECTORY_SEPARATOR, log_basename, runSeed, extension);
 
 		loggerData->filename = filename;
 	}
@@ -1285,7 +1296,12 @@
 		}
 	}
 
-	LoggerData *loggerData = SetUpLogger();
+	LoggerData *loggerData = SetUpLogger(log_stdout_enabled, xml_enabled,
+			xsl_enabled, custom_xsl_enabled, defaultXSLStylesheet);
+	if(loggerData == NULL) {
+		printf("Failed to create a logger.\n");
+		return 2;
+	}
 
 	if(log_stdout_enabled == 0) {
 		printf("Runner is executing the tests.\n");
--- a/test/test-automation/xml_logger.c	Sun Jul 31 19:08:38 2011 +0300
+++ b/test/test-automation/xml_logger.c	Sun Jul 31 20:01:34 2011 +0300
@@ -68,7 +68,7 @@
 static int indentLevel;
 
 /*! Logging level of the logger */
-static Level level = STANDARD;
+static Level level = LOGGER_TERSE;
 
 //! Constants for XMLOuputters EOL parameter
 #define YES 1
@@ -485,7 +485,7 @@
 		  time_t eventTime)
 {
 	// Log passed asserts only on VERBOSE level
-	if(level <= STANDARD && assertResult == ASSERT_PASS) {
+	if(level <= LOGGER_TERSE && assertResult == ASSERT_PASS) {
 		return ;
 	}
 
@@ -542,7 +542,7 @@
 		int actualValue, int excpected, time_t eventTime)
 {
 	// Log passed asserts only on VERBOSE level
-	if(level <= STANDARD && assertResult == ASSERT_PASS) {
+	if(level <= LOGGER_TERSE && assertResult == ASSERT_PASS) {
 		return ;
 	}