Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added simple logging levels to logging system.
Browse files Browse the repository at this point in the history
Added new option: --verbose.
Fixed help for option --version.
  • Loading branch information
mkauppila committed Jul 27, 2011
1 parent 426fc75 commit 8f2c09b
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 23 deletions.
9 changes: 6 additions & 3 deletions test/test-automation/SDL_test.h
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/test-automation/logger.h
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion test/test-automation/plain_logger.c
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand All @@ -50,6 +55,8 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
Output(indentLevel, "\t%s", parameter);
}

level = data->level;

Output(indentLevel, "");
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/test-automation/plain_logger.h
Expand Up @@ -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.
Expand Down
36 changes: 27 additions & 9 deletions test/test-automation/runner.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -835,7 +845,7 @@ SetUpLogger()
sheet = xsl_stylesheet_name;
}

loggerData = sheet;
loggerData->custom = sheet;
} else {
RunStarted = PlainRunStarted;
RunEnded = PlainRunEnded;
Expand All @@ -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");
Expand All @@ -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");
}

Expand All @@ -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;
Expand Down Expand Up @@ -1062,7 +1077,7 @@ main(int argc, char *argv[])
char *extension = "dylib";
#endif

void *loggerData = SetUpLogger();
LoggerData *loggerData = SetUpLogger();

const Uint32 startTicks = SDL_GetTicks();

Expand All @@ -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...");
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/testdummy/testdummy.c
Expand Up @@ -107,7 +107,7 @@ dummycase1(void *arg)
Log(0, "%d", random);
}

Log(0, "Random: %s", RandomAsciiString());
//Log(0, "Random: %s", RandomAsciiString());
}

void
Expand Down
28 changes: 23 additions & 5 deletions test/test-automation/xml_logger.c
Expand Up @@ -24,6 +24,7 @@

#include <SDL/SDL.h>

#include "Logger.h"
#include "xml.h"
#include "logger_helpers.h"
#include "SDL_test.h"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/test-automation/xml_logger.h
Expand Up @@ -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
Expand Down

0 comments on commit 8f2c09b

Please sign in to comment.