Commit d2d35069 authored by Markus Kauppila's avatar Markus Kauppila

Changed logging behavior. Runner uses stdout as default and

file logging is enabled with --logfile [BASENAME] (or --logdir).
parent f7a79ddf
...@@ -102,6 +102,30 @@ char *TimestampToString(const time_t timestamp) { ...@@ -102,6 +102,30 @@ char *TimestampToString(const time_t timestamp) {
return buffer; return buffer;
} }
/*!
* Converts unix timestamp to its ascii presentation in given format
*
* Note: uses static buffer internally, so the return value
* isn't valid after the next call of this function. If you
* want to retain the return value, make a copy of it
*
* \param timestamp Timestamp
* \param format Formatting specification such as "%Y%m%d"
*
* \return Ascii presentation
*/
char *TimestampToStringWithFormat(const time_t timestamp, char *format) {
static char buffer[256];
memset(buffer, 0, sizeof(buffer));
time_t copy = timestamp;
struct tm *local = localtime(&copy);
strftime(buffer, sizeof(buffer), format, local);
return buffer;
}
/*! Turns all the characters of the given /*! Turns all the characters of the given
* string to lowercase and returns the resulting string. * string to lowercase and returns the resulting string.
* *
......
...@@ -31,6 +31,8 @@ char *DoubleToString(const double decimal); ...@@ -31,6 +31,8 @@ char *DoubleToString(const double decimal);
char *TimestampToString(const time_t timestamp); char *TimestampToString(const time_t timestamp);
char *TimestampToStringWithFormat(const time_t timestamp, char *format);
char *ToLowerCase(const char *string); char *ToLowerCase(const char *string);
int ValidateString(const char *string); int ValidateString(const char *string);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "../libSDLtest/plain_logger.h" #include "../libSDLtest/plain_logger.h"
#include "../libSDLtest/xml_logger.h" #include "../libSDLtest/xml_logger.h"
#include "../libSDLtest/logger_helpers.h"
#include "logger.h" #include "logger.h"
#include "support.h" #include "support.h"
...@@ -56,28 +57,40 @@ typedef int (*CountFailedAssertsFp)(void); ...@@ -56,28 +57,40 @@ typedef int (*CountFailedAssertsFp)(void);
//!< Flag for executing tests in-process //!< Flag for executing tests in-process
static int execute_inproc = 0; static int execute_inproc = 0;
//!< Flag for only printing out the test names //!< Flag for only printing out the test names
static int only_print_tests = 0; static int only_print_tests = 0;
//!< Flag for executing only test with selected name //!< Flag for executing only test with selected name
static int only_selected_test = 0; static int only_selected_test = 0;
//!< Flag for executing only the selected test suite //!< Flag for executing only the selected test suite
static int only_selected_suite = 0; static int only_selected_suite = 0;
//!< Flag for executing only tests that contain certain string in their name //!< Flag for executing only tests that contain certain string in their name
static int only_tests_with_string = 0; static int only_tests_with_string = 0;
//!< Flag for enabling XML logging //!< Flag for enabling XML logging
static int xml_enabled = 0; static int xml_enabled = 0;
//! Flag for enabling user-supplied style sheet for XML test report //! Flag for enabling user-supplied style sheet for XML test report
static int custom_xsl_enabled = 0; static int custom_xsl_enabled = 0;
//! Flag for disabling xsl-style from xml report //! Flag for disabling xsl-style from xml report
static int xsl_enabled = 0; static int xsl_enabled = 0;
//! Flag for enabling universal timeout for tests //! Flag for enabling universal timeout for tests
static int universal_timeout_enabled = 0; static int universal_timeout_enabled = 0;
//! Flag for enabling verbose logging //! Flag for enabling verbose logging
static int enable_verbose_logger = 0; static int enable_verbose_logger = 0;
//! Flag for using user supplied run seed //! Flag for using user supplied run seed
static int userRunSeed = 0; static int userRunSeed = 0;
//! Whether or not logger should log to stdout instead of file //! Whether or not logger should log to stdout instead of file
static int log_stdout_enabled = 0; static int log_stdout_enabled = 1;
//! Whether or not dummy suite should be included to the test run //! Whether or not dummy suite should be included to the test run
static int include_dummy_suite = 0; static int include_dummy_suite = 0;
...@@ -106,7 +119,7 @@ int universal_timeout = -1; ...@@ -106,7 +119,7 @@ int universal_timeout = -1;
#define DEFAULT_LOG_DIRECTORY "logs" #define DEFAULT_LOG_DIRECTORY "logs"
//! Default directory of the test suites //! Default directory of the test suites
#define DEFAULT_LOG_FILENAME "runner" #define DEFAULT_LOG_FILENAME "testrun"
//! Defines directory separator //! Defines directory separator
#define DIRECTORY_SEPARATOR '/' #define DIRECTORY_SEPARATOR '/'
...@@ -979,15 +992,20 @@ SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_e ...@@ -979,15 +992,20 @@ SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_e
unsigned int mode = S_IRWXU | S_IRGRP | S_ISUID; unsigned int mode = S_IRWXU | S_IRGRP | S_ISUID;
mkdir(log_directory, mode); mkdir(log_directory, mode);
char *timeString = TimestampToStringWithFormat(time(0), "%Y%m%d_%H:%M:%S");
/* Combine and create directory for log file */ /* Combine and create directory for log file */
const Uint32 directoryLength = SDL_strlen(log_directory); const Uint32 directoryLength = SDL_strlen(log_directory);
const Uint32 basenameLength = SDL_strlen(log_basename); const Uint32 basenameLength = SDL_strlen(log_basename);
const Uint32 seedLength = SDL_strlen(runSeed); const Uint32 seedLength = SDL_strlen(runSeed);
const Uint32 extensionLength = SDL_strlen(extension); const Uint32 extensionLength = SDL_strlen(extension);
const Uint32 timeLength = SDL_strlen(timeString);
// couple of extras bytes for '/', '-', '.' and '\0' at the end // couple of extras bytes for '/', '-', '.' and '\0' at the end
const Uint32 length = directoryLength + basenameLength + seedLength const Uint32 length = directoryLength + basenameLength + seedLength
+ extensionLength + 4; + extensionLength + timeLength + 5;
if(length <= 0) { if(length <= 0) {
return NULL; return NULL;
...@@ -1002,8 +1020,8 @@ SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_e ...@@ -1002,8 +1020,8 @@ SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_e
} }
memset(filename, 0, length); memset(filename, 0, length);
SDL_snprintf(filename, length, "%s%c%s-%s.%s", log_directory, SDL_snprintf(filename, length, "%s%c%s-%s-%s.%s", log_directory,
DIRECTORY_SEPARATOR, log_basename, runSeed, extension); DIRECTORY_SEPARATOR, log_basename, timeString, runSeed, extension);
loggerData->filename = filename; loggerData->filename = filename;
} }
...@@ -1063,7 +1081,7 @@ SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_e ...@@ -1063,7 +1081,7 @@ SetUpLogger(const int log_stdout_enabled, const int xml_enabled, const int xsl_e
void void
PrintUsage() { PrintUsage() {
printf("Usage: ./runner [--in-proc] [--show-tests] [--verbose]\n"); printf("Usage: ./runner [--in-proc] [--show-tests] [--verbose]\n");
printf(" [--logfile BASENAME] [--logdir DIR] [--log-stdout] [--xml]\n"); printf(" [--logfile [BASENAME]] [--logdir DIR] [--xml]\n");
printf(" [--xsl [STYLESHEET]] [--seed VALUE] [--iterations VALUE]\n"); printf(" [--xsl [STYLESHEET]] [--seed VALUE] [--iterations VALUE]\n");
printf(" [--exec-key KEY] [--timeout VALUE] [--test TEST]\n"); printf(" [--exec-key KEY] [--timeout VALUE] [--test TEST]\n");
printf(" [--name-contains SUBSTR] [--suite SUITE] [--include-dummy]\n"); printf(" [--name-contains SUBSTR] [--suite SUITE] [--include-dummy]\n");
...@@ -1072,10 +1090,10 @@ PrintUsage() { ...@@ -1072,10 +1090,10 @@ PrintUsage() {
printf(" --in-proc Executes tests in-process\n"); printf(" --in-proc Executes tests in-process\n");
printf(" --show-tests Prints out all the executable tests\n"); printf(" --show-tests Prints out all the executable tests\n");
printf(" -v --verbose Enables verbose logging\n"); printf(" -v --verbose Enables verbose logging\n");
printf(" --logfile BASENAME Define basename for logfiles. Defaults to 'runner'\n"); printf(" --logfile [BASENAME] Enables logging to a file. If BASENAME is\n");
printf(" specified it'll be used as basename for\n");
printf(" the log file\n");
printf(" --logdir DIR Define directory for logs. Defaults to 'logs'\n"); printf(" --logdir DIR Define directory for logs. Defaults to 'logs'\n");
printf(" --log-stdout Log to stdout instead of file (overrides --logfile\n");
printf(" and --logdir options)\n");
printf(" --xml Enables XML logger\n"); printf(" --xml Enables XML logger\n");
printf(" --xsl [STYLESHEET] Adds XSL stylesheet to the XML test reports for\n"); printf(" --xsl [STYLESHEET] Adds XSL stylesheet to the XML test reports for\n");
printf(" browser viewing. Optionally uses the specified XSL\n"); printf(" browser viewing. Optionally uses the specified XSL\n");
...@@ -1137,23 +1155,22 @@ ParseOptions(int argc, char *argv[]) ...@@ -1137,23 +1155,22 @@ ParseOptions(int argc, char *argv[])
memset(log_directory, 0, NAME_BUFFER_SIZE); memset(log_directory, 0, NAME_BUFFER_SIZE);
memcpy(log_directory, dirString, SDL_strlen(dirString)); memcpy(log_directory, dirString, SDL_strlen(dirString));
log_stdout_enabled = 0;
} }
else if(SDL_strcmp(arg, "--logfile") == 0) { else if(SDL_strcmp(arg, "--logfile") == 0) {
char *fileString = NULL; char *fileString = NULL;
if( (i + 1) < argc) { if( (i + 1) < argc) {
fileString = argv[++i]; fileString = argv[++i];
} else { } else {
printf("runner: file is missing\n"); fileString = DEFAULT_LOG_FILENAME;
PrintUsage();
exit(1);
} }
memset(log_basename, 0, NAME_BUFFER_SIZE); memset(log_basename, 0, NAME_BUFFER_SIZE);
memcpy(log_basename, fileString, SDL_strlen(fileString)); memcpy(log_basename, fileString, SDL_strlen(fileString));
}
else if(SDL_strcmp(arg, "--log-stdout") == 0) { log_stdout_enabled = 0;
log_stdout_enabled = 1;
} }
else if(SDL_strcmp(arg, "--timeout") == 0 || SDL_strcmp(arg, "-tm") == 0) { else if(SDL_strcmp(arg, "--timeout") == 0 || SDL_strcmp(arg, "-tm") == 0) {
universal_timeout_enabled = 1; universal_timeout_enabled = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment