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