Commit e7697141 authored by Markus Kauppila's avatar Markus Kauppila

Added simple logging levels to logging system.

Added new option: --verbose.
Fixed help for option --version.
parent 6132d65f
......@@ -28,16 +28,19 @@
#include "fuzzer/fuzzer.h"
/*
extern int _testReturnValue;
extern int _testAssertsFailed;
extern int _testAssertsPassed;
*/
extern AssertFp testAssert;
// \todo Should these be consts?
#define TEST_ENABLED 1
#define TEST_DISABLED 0
//! Definitions of assert results
#define ASSERT_PASS 1
#define ASSERT_FAILURE 0
//! Definition of all the possible test results
#define TEST_RESULT_PASS 0
#define TEST_RESULT_FAILURE 1
......
......@@ -23,6 +23,18 @@
#include <time.h>
/* Logging levels */
typedef enum Level {
STANDARD = 1,
VERBOSE
} Level;
typedef struct LoggerData {
Level level; //!< Logging level of the logger (such as VERBOSE)
void *custom; //!< Some custom data that a logger needs
} LoggerData;
/*!
* Typedefs for function pointers that implement the generic
* logging interface. See the headers of implementations (plain_logger.h or
......
......@@ -2,12 +2,17 @@
#ifndef _PLAIN_LOGGER
#define _PLAIN_LOGGER
#include "Logger.h"
#include "logger_helpers.h"
#include "plain_logger.h"
#include "SDL_test.h"
/*! Current indentationt level */
static int indentLevel;
/*! Logging level of the logger */
static Level level = STANDARD;
/*!
* Prints out the output of the logger
*
......@@ -38,7 +43,7 @@ Output(const int currentIndentLevel, const char *message, ...)
void
PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, void *data)
time_t eventTime, LoggerData *data)
{
Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
Output(indentLevel, "Fuzzer seed is %s", runSeed);
......@@ -50,6 +55,8 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
Output(indentLevel, "\t%s", parameter);
}
level = data->level;
Output(indentLevel, "");
}
......@@ -117,6 +124,11 @@ void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime)
{
// Log passed asserts only on VERBOSE level
if(level <= STANDARD && assertResult == ASSERT_PASS) {
return ;
}
const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
}
......@@ -125,6 +137,11 @@ void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
int actualValue, int expectedValue, time_t eventTime)
{
// Log passed asserts only on VERBOSE level
if(level <= STANDARD && assertResult == ASSERT_PASS) {
return ;
}
const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s (expected %d, actualValue %d) - %s",
assertName, result, expectedValue, actualValue, assertMessage);
......
......@@ -10,11 +10,11 @@
* \param runnerParameters What parameters were given to the runner
* \param runSeed Fuzzer seed of the harness
* \param eventTime When the execution started
* \param data Any additional data logger needs
* \param loggerData LoggerData structure which contains data for the logger
*
*/
void PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, void *data);
time_t eventTime, LoggerData *data);
/*!
* Prints out information about ending the test run.
......
......@@ -72,6 +72,9 @@ static int custom_xsl_enabled = 0;
static int xsl_enabled = 0;
//! Flag for enabling universal timeout for tests
static int universal_timeout_enabled = 0;
//! Flag for enabling verbose logging
static int enable_verbose_logger = 0;
//!< Size of the test and suite name buffers
#define NAME_BUFFER_SIZE 1024
......@@ -804,12 +807,19 @@ HandleChildProcessReturnValue(int stat_lock)
/*!
* Sets up the logger.
*
* \return Some special data that will be passed to StartRun() logger call
* \return Logger data structure (that needs be deallocated)
*/
void *
SetUpLogger()
{
void *loggerData = NULL;
LoggerData *loggerData = SDL_malloc(sizeof(loggerData));
if(loggerData == NULL) {
fprintf(stderr, "Error: Logger data structure not allocated.");
return NULL;
}
loggerData->level = (enable_verbose_logger ? VERBOSE : STANDARD);
if(xml_enabled) {
RunStarted = XMLRunStarted;
RunEnded = XMLRunEnded;
......@@ -835,7 +845,7 @@ SetUpLogger()
sheet = xsl_stylesheet_name;
}
loggerData = sheet;
loggerData->custom = sheet;
} else {
RunStarted = PlainRunStarted;
RunEnded = PlainRunEnded;
......@@ -862,14 +872,15 @@ SetUpLogger()
*/
void
PrintUsage() {
printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
printf(" [--name-contains SUBSTR] [--show-tests]\n");
printf(" [--xml] [--xsl [STYLESHEET]] [--timeout VALUE]\n");
printf(" [--exec-key KEY] [--iterations VALUE]\n");
printf(" [--seed VALUE] [--version] [--help]\n");
printf("Usage: ./runner [--in-proc] [--show-tests] [--verbose] [--xml]\n");
printf(" [--xsl [STYLESHEET]] [--seed VALUE] [--iterations VALUE]\n");
printf(" [--exec-key KEY] [--timeout VALUE] [--test TEST]\n");
printf(" [--name-contains SUBSTR] [--suite SUITE]\n");
printf(" [--version] [--help]\n");
printf("Options:\n");
printf(" --in-proc Executes tests in-process\n");
printf(" --show-tests Prints out all the executable tests\n");
printf(" -v --verbose Enables verbose logging\n");
printf(" --xml Enables XML logger\n");
printf(" --xsl [STYLESHEET] Adds XSL stylesheet to the XML test reports for\n");
printf(" browser viewing. Optionally uses the specified XSL\n");
......@@ -887,6 +898,7 @@ PrintUsage() {
printf(" substring in test name\n");
printf(" -s --suite SUITE Executes only the given test suite\n");
printf(" --version Print version information\n");
printf(" -h --help Print this help\n");
}
......@@ -913,6 +925,9 @@ ParseOptions(int argc, char *argv[])
else if(SDL_strcmp(arg, "--xml") == 0) {
xml_enabled = 1;
}
else if(SDL_strcmp(arg, "--verbose") == 0 || SDL_strcmp(arg, "-v") == 0) {
enable_verbose_logger = 1;
}
else if(SDL_strcmp(arg, "--timeout") == 0 || SDL_strcmp(arg, "-tm") == 0) {
universal_timeout_enabled = 1;
char *timeoutString = NULL;
......@@ -1062,7 +1077,7 @@ main(int argc, char *argv[])
char *extension = "dylib";
#endif
void *loggerData = SetUpLogger();
LoggerData *loggerData = SetUpLogger();
const Uint32 startTicks = SDL_GetTicks();
......@@ -1083,6 +1098,9 @@ main(int argc, char *argv[])
RunStarted(argc, argv, runSeed, time(0), loggerData);
// logger data is no longer used
SDL_free(loggerData);
if(execute_inproc && universal_timeout_enabled) {
Log(time(0), "Test timeout is not supported with in-proc execution.");
Log(time(0), "Timeout will be disabled...");
......
......@@ -107,7 +107,7 @@ dummycase1(void *arg)
Log(0, "%d", random);
}
Log(0, "Random: %s", RandomAsciiString());
//Log(0, "Random: %s", RandomAsciiString());
}
void
......
......@@ -24,6 +24,7 @@
#include <SDL/SDL.h>
#include "Logger.h"
#include "xml.h"
#include "logger_helpers.h"
#include "SDL_test.h"
......@@ -66,6 +67,9 @@ const char *logElementName = "log";
/*! Current indentationt level */
static int indentLevel;
/*! Logging level of the logger */
static Level level = STANDARD;
//! Constants for XMLOuputters EOL parameter
#define YES 1
#define NO 0
......@@ -111,9 +115,10 @@ XMLOutputter(const int currentIndentLevel,
void
XMLRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, void *data)
time_t eventTime, LoggerData *data)
{
char *xslStylesheet = (char *)data;
char *xslStylesheet = (char *)data->custom;
level = data->level;
char *output = XMLOpenDocument(documentRoot, xslStylesheet);
XMLOutputter(indentLevel++, YES, output);
......@@ -241,6 +246,7 @@ XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
void
XMLSuiteStarted(const char *suiteName, time_t eventTime)
{
// log suite name
char *output = XMLOpenElement(suiteElementName);
XMLOutputter(indentLevel++, YES, output);
......@@ -250,12 +256,14 @@ XMLSuiteStarted(const char *suiteName, time_t eventTime)
output = XMLAddContent(suiteName);
XMLOutputter(indentLevel, NO, output);
// log test name
output = XMLCloseElement(nameElementName);
XMLOutputter(--indentLevel, YES, output);
output = XMLOpenElement(startTimeElementName);
XMLOutputter(indentLevel++, NO, output);
// log beginning time
output = XMLAddContent(TimestampToString(eventTime));
XMLOutputter(indentLevel, NO, output);
......@@ -329,8 +337,7 @@ XMLTestStarted(const char *testName, const char *suiteName,
char * output = XMLOpenElement(testElementName);
XMLOutputter(indentLevel++, YES, output);
//Attribute attribute = {"test", "value"};
//XMLOpenElementWithAttribute("name", &attribute);
// log test name
output = XMLOpenElement(nameElementName);
XMLOutputter(indentLevel++, NO, output);
......@@ -340,6 +347,7 @@ XMLTestStarted(const char *testName, const char *suiteName,
output = XMLCloseElement(nameElementName);
XMLOutputter(--indentLevel, YES, output);
// log test description
output = XMLOpenElement(descriptionElementName);
XMLOutputter(indentLevel++, NO, output);
......@@ -349,7 +357,7 @@ XMLTestStarted(const char *testName, const char *suiteName,
output = XMLCloseElement(descriptionElementName);
XMLOutputter(--indentLevel, YES, output);
// log exec key
// log execution key
output = XMLOpenElement(execKeyElementName);
XMLOutputter(indentLevel++, NO, output);
......@@ -457,6 +465,11 @@ void
XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime)
{
// Log passed asserts only on VERBOSE level
if(level <= STANDARD && assertResult == ASSERT_PASS) {
return ;
}
char *output = XMLOpenElement(assertElementName);
XMLOutputter(indentLevel++, YES, output);
......@@ -509,6 +522,11 @@ void
XMLAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
int actualValue, int excpected, time_t eventTime)
{
// Log passed asserts only on VERBOSE level
if(level <= STANDARD && assertResult == ASSERT_PASS) {
return ;
}
char *output = XMLOpenElement(assertElementName);
XMLOutputter(indentLevel++, YES, output);
......
......@@ -10,10 +10,10 @@
* \param runnerParameters What parameters were given to the runner
* \param runSeed Fuzzer seed of the harness
* \param eventTime When the execution started
* \param data Any additional data logger needs
* \param loggerData LoggerData structure which contains data for the logger
*/
void XMLRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, void *data);
time_t eventTime, LoggerData *data);
/*!
* Prints out information about ending the test run in XML
......
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