Added simple logging levels to logging system.
Added new option: --verbose.
Fixed help for option --version.
1.1 --- a/test/test-automation/SDL_test.h Mon Jul 25 20:32:31 2011 +0300
1.2 +++ b/test/test-automation/SDL_test.h Wed Jul 27 17:48:07 2011 +0300
1.3 @@ -28,16 +28,19 @@
1.4
1.5 #include "fuzzer/fuzzer.h"
1.6
1.7 +/*
1.8 extern int _testReturnValue;
1.9 extern int _testAssertsFailed;
1.10 extern int _testAssertsPassed;
1.11 +*/
1.12
1.13 -extern AssertFp testAssert;
1.14 -
1.15 -// \todo Should these be consts?
1.16 #define TEST_ENABLED 1
1.17 #define TEST_DISABLED 0
1.18
1.19 +//! Definitions of assert results
1.20 +#define ASSERT_PASS 1
1.21 +#define ASSERT_FAILURE 0
1.22 +
1.23 //! Definition of all the possible test results
1.24 #define TEST_RESULT_PASS 0
1.25 #define TEST_RESULT_FAILURE 1
2.1 --- a/test/test-automation/logger.h Mon Jul 25 20:32:31 2011 +0300
2.2 +++ b/test/test-automation/logger.h Wed Jul 27 17:48:07 2011 +0300
2.3 @@ -23,6 +23,18 @@
2.4
2.5 #include <time.h>
2.6
2.7 +/* Logging levels */
2.8 +typedef enum Level {
2.9 + STANDARD = 1,
2.10 + VERBOSE
2.11 +} Level;
2.12 +
2.13 +
2.14 +typedef struct LoggerData {
2.15 + Level level; //!< Logging level of the logger (such as VERBOSE)
2.16 + void *custom; //!< Some custom data that a logger needs
2.17 +} LoggerData;
2.18 +
2.19 /*!
2.20 * Typedefs for function pointers that implement the generic
2.21 * logging interface. See the headers of implementations (plain_logger.h or
3.1 --- a/test/test-automation/plain_logger.c Mon Jul 25 20:32:31 2011 +0300
3.2 +++ b/test/test-automation/plain_logger.c Wed Jul 27 17:48:07 2011 +0300
3.3 @@ -2,12 +2,17 @@
3.4 #ifndef _PLAIN_LOGGER
3.5 #define _PLAIN_LOGGER
3.6
3.7 +#include "Logger.h"
3.8 #include "logger_helpers.h"
3.9 #include "plain_logger.h"
3.10 #include "SDL_test.h"
3.11
3.12 +/*! Current indentationt level */
3.13 static int indentLevel;
3.14
3.15 +/*! Logging level of the logger */
3.16 +static Level level = STANDARD;
3.17 +
3.18 /*!
3.19 * Prints out the output of the logger
3.20 *
3.21 @@ -38,7 +43,7 @@
3.22
3.23 void
3.24 PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
3.25 - time_t eventTime, void *data)
3.26 + time_t eventTime, LoggerData *data)
3.27 {
3.28 Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
3.29 Output(indentLevel, "Fuzzer seed is %s", runSeed);
3.30 @@ -50,6 +55,8 @@
3.31 Output(indentLevel, "\t%s", parameter);
3.32 }
3.33
3.34 + level = data->level;
3.35 +
3.36 Output(indentLevel, "");
3.37 }
3.38
3.39 @@ -117,6 +124,11 @@
3.40 PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
3.41 time_t eventTime)
3.42 {
3.43 + // Log passed asserts only on VERBOSE level
3.44 + if(level <= STANDARD && assertResult == ASSERT_PASS) {
3.45 + return ;
3.46 + }
3.47 +
3.48 const char *result = (assertResult) ? "passed" : "failed";
3.49 Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
3.50 }
3.51 @@ -125,6 +137,11 @@
3.52 PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
3.53 int actualValue, int expectedValue, time_t eventTime)
3.54 {
3.55 + // Log passed asserts only on VERBOSE level
3.56 + if(level <= STANDARD && assertResult == ASSERT_PASS) {
3.57 + return ;
3.58 + }
3.59 +
3.60 const char *result = (assertResult) ? "passed" : "failed";
3.61 Output(indentLevel, "%s: %s (expected %d, actualValue %d) - %s",
3.62 assertName, result, expectedValue, actualValue, assertMessage);
4.1 --- a/test/test-automation/plain_logger.h Mon Jul 25 20:32:31 2011 +0300
4.2 +++ b/test/test-automation/plain_logger.h Wed Jul 27 17:48:07 2011 +0300
4.3 @@ -10,11 +10,11 @@
4.4 * \param runnerParameters What parameters were given to the runner
4.5 * \param runSeed Fuzzer seed of the harness
4.6 * \param eventTime When the execution started
4.7 - * \param data Any additional data logger needs
4.8 + * \param loggerData LoggerData structure which contains data for the logger
4.9 *
4.10 */
4.11 void PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
4.12 - time_t eventTime, void *data);
4.13 + time_t eventTime, LoggerData *data);
4.14
4.15 /*!
4.16 * Prints out information about ending the test run.
5.1 --- a/test/test-automation/runner.c Mon Jul 25 20:32:31 2011 +0300
5.2 +++ b/test/test-automation/runner.c Wed Jul 27 17:48:07 2011 +0300
5.3 @@ -72,6 +72,9 @@
5.4 static int xsl_enabled = 0;
5.5 //! Flag for enabling universal timeout for tests
5.6 static int universal_timeout_enabled = 0;
5.7 +//! Flag for enabling verbose logging
5.8 +static int enable_verbose_logger = 0;
5.9 +
5.10
5.11 //!< Size of the test and suite name buffers
5.12 #define NAME_BUFFER_SIZE 1024
5.13 @@ -804,12 +807,19 @@
5.14 /*!
5.15 * Sets up the logger.
5.16 *
5.17 - * \return Some special data that will be passed to StartRun() logger call
5.18 + * \return Logger data structure (that needs be deallocated)
5.19 */
5.20 void *
5.21 SetUpLogger()
5.22 {
5.23 - void *loggerData = NULL;
5.24 + LoggerData *loggerData = SDL_malloc(sizeof(loggerData));
5.25 + if(loggerData == NULL) {
5.26 + fprintf(stderr, "Error: Logger data structure not allocated.");
5.27 + return NULL;
5.28 + }
5.29 +
5.30 + loggerData->level = (enable_verbose_logger ? VERBOSE : STANDARD);
5.31 +
5.32 if(xml_enabled) {
5.33 RunStarted = XMLRunStarted;
5.34 RunEnded = XMLRunEnded;
5.35 @@ -835,7 +845,7 @@
5.36 sheet = xsl_stylesheet_name;
5.37 }
5.38
5.39 - loggerData = sheet;
5.40 + loggerData->custom = sheet;
5.41 } else {
5.42 RunStarted = PlainRunStarted;
5.43 RunEnded = PlainRunEnded;
5.44 @@ -862,14 +872,15 @@
5.45 */
5.46 void
5.47 PrintUsage() {
5.48 - printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
5.49 - printf(" [--name-contains SUBSTR] [--show-tests]\n");
5.50 - printf(" [--xml] [--xsl [STYLESHEET]] [--timeout VALUE]\n");
5.51 - printf(" [--exec-key KEY] [--iterations VALUE]\n");
5.52 - printf(" [--seed VALUE] [--version] [--help]\n");
5.53 + printf("Usage: ./runner [--in-proc] [--show-tests] [--verbose] [--xml]\n");
5.54 + printf(" [--xsl [STYLESHEET]] [--seed VALUE] [--iterations VALUE]\n");
5.55 + printf(" [--exec-key KEY] [--timeout VALUE] [--test TEST]\n");
5.56 + printf(" [--name-contains SUBSTR] [--suite SUITE]\n");
5.57 + printf(" [--version] [--help]\n");
5.58 printf("Options:\n");
5.59 printf(" --in-proc Executes tests in-process\n");
5.60 printf(" --show-tests Prints out all the executable tests\n");
5.61 + printf(" -v --verbose Enables verbose logging\n");
5.62 printf(" --xml Enables XML logger\n");
5.63 printf(" --xsl [STYLESHEET] Adds XSL stylesheet to the XML test reports for\n");
5.64 printf(" browser viewing. Optionally uses the specified XSL\n");
5.65 @@ -887,6 +898,7 @@
5.66 printf(" substring in test name\n");
5.67 printf(" -s --suite SUITE Executes only the given test suite\n");
5.68
5.69 + printf(" --version Print version information\n");
5.70 printf(" -h --help Print this help\n");
5.71 }
5.72
5.73 @@ -913,6 +925,9 @@
5.74 else if(SDL_strcmp(arg, "--xml") == 0) {
5.75 xml_enabled = 1;
5.76 }
5.77 + else if(SDL_strcmp(arg, "--verbose") == 0 || SDL_strcmp(arg, "-v") == 0) {
5.78 + enable_verbose_logger = 1;
5.79 + }
5.80 else if(SDL_strcmp(arg, "--timeout") == 0 || SDL_strcmp(arg, "-tm") == 0) {
5.81 universal_timeout_enabled = 1;
5.82 char *timeoutString = NULL;
5.83 @@ -1062,7 +1077,7 @@
5.84 char *extension = "dylib";
5.85 #endif
5.86
5.87 - void *loggerData = SetUpLogger();
5.88 + LoggerData *loggerData = SetUpLogger();
5.89
5.90 const Uint32 startTicks = SDL_GetTicks();
5.91
5.92 @@ -1083,6 +1098,9 @@
5.93
5.94 RunStarted(argc, argv, runSeed, time(0), loggerData);
5.95
5.96 + // logger data is no longer used
5.97 + SDL_free(loggerData);
5.98 +
5.99 if(execute_inproc && universal_timeout_enabled) {
5.100 Log(time(0), "Test timeout is not supported with in-proc execution.");
5.101 Log(time(0), "Timeout will be disabled...");
6.1 --- a/test/test-automation/testdummy/testdummy.c Mon Jul 25 20:32:31 2011 +0300
6.2 +++ b/test/test-automation/testdummy/testdummy.c Wed Jul 27 17:48:07 2011 +0300
6.3 @@ -107,7 +107,7 @@
6.4 Log(0, "%d", random);
6.5 }
6.6
6.7 - Log(0, "Random: %s", RandomAsciiString());
6.8 + //Log(0, "Random: %s", RandomAsciiString());
6.9 }
6.10
6.11 void
7.1 --- a/test/test-automation/xml_logger.c Mon Jul 25 20:32:31 2011 +0300
7.2 +++ b/test/test-automation/xml_logger.c Wed Jul 27 17:48:07 2011 +0300
7.3 @@ -24,6 +24,7 @@
7.4
7.5 #include <SDL/SDL.h>
7.6
7.7 +#include "Logger.h"
7.8 #include "xml.h"
7.9 #include "logger_helpers.h"
7.10 #include "SDL_test.h"
7.11 @@ -66,6 +67,9 @@
7.12 /*! Current indentationt level */
7.13 static int indentLevel;
7.14
7.15 +/*! Logging level of the logger */
7.16 +static Level level = STANDARD;
7.17 +
7.18 //! Constants for XMLOuputters EOL parameter
7.19 #define YES 1
7.20 #define NO 0
7.21 @@ -111,9 +115,10 @@
7.22
7.23 void
7.24 XMLRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
7.25 - time_t eventTime, void *data)
7.26 + time_t eventTime, LoggerData *data)
7.27 {
7.28 - char *xslStylesheet = (char *)data;
7.29 + char *xslStylesheet = (char *)data->custom;
7.30 + level = data->level;
7.31
7.32 char *output = XMLOpenDocument(documentRoot, xslStylesheet);
7.33 XMLOutputter(indentLevel++, YES, output);
7.34 @@ -241,6 +246,7 @@
7.35 void
7.36 XMLSuiteStarted(const char *suiteName, time_t eventTime)
7.37 {
7.38 + // log suite name
7.39 char *output = XMLOpenElement(suiteElementName);
7.40 XMLOutputter(indentLevel++, YES, output);
7.41
7.42 @@ -250,12 +256,14 @@
7.43 output = XMLAddContent(suiteName);
7.44 XMLOutputter(indentLevel, NO, output);
7.45
7.46 + // log test name
7.47 output = XMLCloseElement(nameElementName);
7.48 XMLOutputter(--indentLevel, YES, output);
7.49
7.50 output = XMLOpenElement(startTimeElementName);
7.51 XMLOutputter(indentLevel++, NO, output);
7.52
7.53 + // log beginning time
7.54 output = XMLAddContent(TimestampToString(eventTime));
7.55 XMLOutputter(indentLevel, NO, output);
7.56
7.57 @@ -329,8 +337,7 @@
7.58 char * output = XMLOpenElement(testElementName);
7.59 XMLOutputter(indentLevel++, YES, output);
7.60
7.61 - //Attribute attribute = {"test", "value"};
7.62 - //XMLOpenElementWithAttribute("name", &attribute);
7.63 + // log test name
7.64 output = XMLOpenElement(nameElementName);
7.65 XMLOutputter(indentLevel++, NO, output);
7.66
7.67 @@ -340,6 +347,7 @@
7.68 output = XMLCloseElement(nameElementName);
7.69 XMLOutputter(--indentLevel, YES, output);
7.70
7.71 + // log test description
7.72 output = XMLOpenElement(descriptionElementName);
7.73 XMLOutputter(indentLevel++, NO, output);
7.74
7.75 @@ -349,7 +357,7 @@
7.76 output = XMLCloseElement(descriptionElementName);
7.77 XMLOutputter(--indentLevel, YES, output);
7.78
7.79 - // log exec key
7.80 + // log execution key
7.81 output = XMLOpenElement(execKeyElementName);
7.82 XMLOutputter(indentLevel++, NO, output);
7.83
7.84 @@ -457,6 +465,11 @@
7.85 XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
7.86 time_t eventTime)
7.87 {
7.88 + // Log passed asserts only on VERBOSE level
7.89 + if(level <= STANDARD && assertResult == ASSERT_PASS) {
7.90 + return ;
7.91 + }
7.92 +
7.93 char *output = XMLOpenElement(assertElementName);
7.94 XMLOutputter(indentLevel++, YES, output);
7.95
7.96 @@ -509,6 +522,11 @@
7.97 XMLAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
7.98 int actualValue, int excpected, time_t eventTime)
7.99 {
7.100 + // Log passed asserts only on VERBOSE level
7.101 + if(level <= STANDARD && assertResult == ASSERT_PASS) {
7.102 + return ;
7.103 + }
7.104 +
7.105 char *output = XMLOpenElement(assertElementName);
7.106 XMLOutputter(indentLevel++, YES, output);
7.107
8.1 --- a/test/test-automation/xml_logger.h Mon Jul 25 20:32:31 2011 +0300
8.2 +++ b/test/test-automation/xml_logger.h Wed Jul 27 17:48:07 2011 +0300
8.3 @@ -10,10 +10,10 @@
8.4 * \param runnerParameters What parameters were given to the runner
8.5 * \param runSeed Fuzzer seed of the harness
8.6 * \param eventTime When the execution started
8.7 - * \param data Any additional data logger needs
8.8 + * \param loggerData LoggerData structure which contains data for the logger
8.9 */
8.10 void XMLRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
8.11 - time_t eventTime, void *data);
8.12 + time_t eventTime, LoggerData *data);
8.13
8.14 /*!
8.15 * Prints out information about ending the test run in XML