Various fixes and additions to logger system.
This commit is contained in:
parent
ac07ad67d9
commit
94c6ae4eab
9 changed files with 266 additions and 104 deletions
|
@ -8,7 +8,7 @@ runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
|
|||
runner_LDFLAGS = `sdl-config --libs`
|
||||
|
||||
bin_PROGRAMS = logger
|
||||
logger_SOURCES = xml_logger.c xml.c
|
||||
logger_SOURCES = xml_logger.c xml.c plain_logger.c logger.c
|
||||
logger_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
|
||||
logger_LDFLAGS = `sdl-config --libs`
|
||||
|
||||
|
|
89
test/test-automation/logger.c
Normal file
89
test/test-automation/logger.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "logger.h"
|
||||
#include "xml_logger.h"
|
||||
#include "plain_logger.h"
|
||||
|
||||
// Pointers to selected logger implementation
|
||||
RunStartedFp RunStarted = 0;
|
||||
RunEndedFp RunEnded = 0;
|
||||
SuiteStartedFp SuiteStarted = 0;
|
||||
SuiteEndedFp SuiteEnded = 0;
|
||||
TestStartedFp TestStarted = 0;
|
||||
TestEndedFp TestEnded = 0;
|
||||
AssertFp Assert = 0;
|
||||
LogFp Log = 0;
|
||||
|
||||
/*!
|
||||
* Prints the given message to stderr. Function adds nesting
|
||||
* to the output.
|
||||
*
|
||||
* \return Possible error value (\todo)
|
||||
*/
|
||||
int
|
||||
LogGenericOutput(const char *message)
|
||||
{
|
||||
/*
|
||||
int depth = indentDepth;
|
||||
while(depth--) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
*/
|
||||
|
||||
fprintf(stderr, "%s\n", message);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* Test app for logging functionality
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int xml_enabled = 1;
|
||||
|
||||
if(xml_enabled) {
|
||||
RunStarted = XMLRunStarted;
|
||||
RunEnded = XMLRunEnded;
|
||||
|
||||
SuiteStarted = XMLSuiteStarted;
|
||||
SuiteEnded = XMLSuiteEnded;
|
||||
|
||||
TestStarted = XMLTestStarted;
|
||||
TestEnded = XMLTestEnded;
|
||||
|
||||
Assert = XMLAssert;
|
||||
Log = XMLLog;
|
||||
} else {
|
||||
RunStarted = PlainRunStarted;
|
||||
RunEnded = PlainRunEnded;
|
||||
|
||||
SuiteStarted = PlainSuiteStarted;
|
||||
SuiteEnded = PlainSuiteEnded;
|
||||
|
||||
TestStarted = PlainTestStarted;
|
||||
TestEnded = PlainTestEnded;
|
||||
|
||||
Assert = PlainAssert;
|
||||
Log = PlainLog;
|
||||
}
|
||||
|
||||
RunStarted(LogGenericOutput, "All the data from harness", 0);
|
||||
SuiteStarted("Suite data here", 0);
|
||||
|
||||
TestStarted("test1", "desc", 0);
|
||||
TestEnded("test1", "desc", 0, 0, 0, 0);
|
||||
|
||||
//XMLTestStarted("test2", "desc", 0);
|
||||
//XMLTestEnded("test2", "desc", 0, 0, 0, 0);
|
||||
|
||||
SuiteEnded(0, 0, 0, 0.0f, 0);
|
||||
RunEnded(0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -26,25 +26,26 @@
|
|||
// Function pointer to function which handles to output
|
||||
typedef int (*LogOutputFp)(const char *);
|
||||
|
||||
|
||||
/*!
|
||||
* Generic logger interface
|
||||
*
|
||||
*/
|
||||
void RunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime);
|
||||
void RunEnded(time_t endTime, time_t totalRuntime);
|
||||
typedef void (*RunStartedFp)(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime);
|
||||
typedef void (*RunEndedFp)(time_t endTime, time_t totalRuntime);
|
||||
|
||||
void SuiteStarted(const char *suiteName, time_t eventTime);
|
||||
void SuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||
typedef void (*SuiteStartedFp)(const char *suiteName, time_t eventTime);
|
||||
typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
|
||||
double endTime, time_t totalRuntime);
|
||||
|
||||
void TestStarted(const char *testName, const char *testDescription, time_t startTime);
|
||||
void TestEnded(const char *testName, const char *testDescription, int testResult,
|
||||
typedef void (*TestStartedFp)(const char *testName, const char *testDescription, time_t startTime);
|
||||
typedef void (*TestEndedFp)(const char *testName, const char *testDescription, int testResult,
|
||||
int numAsserts, time_t endTime, time_t totalRuntime);
|
||||
|
||||
void Assert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
typedef void (*AssertFp)(const char *assertName, int assertResult, const char *assertMessage,
|
||||
time_t eventTime);
|
||||
|
||||
void Log(const char *logMessage, time_t eventTime);
|
||||
typedef void (*LogFp)(const char *logMessage, time_t eventTime);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
63
test/test-automation/plain_logger.c
Normal file
63
test/test-automation/plain_logger.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
#ifndef _PLAIN_LOGGER
|
||||
#define _PLAIN_LOGGER
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "plain_logger.h"
|
||||
|
||||
|
||||
LogOutputFp logger = 0;
|
||||
|
||||
void
|
||||
PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
||||
{
|
||||
logger = outputFn;
|
||||
}
|
||||
|
||||
void
|
||||
PlainRunEnded(time_t endTime, time_t totalRuntime)
|
||||
{
|
||||
// \todo add total number of tests, suites, pass/failure test count
|
||||
}
|
||||
|
||||
void
|
||||
PlainSuiteStarted(const char *suiteName, time_t eventTime)
|
||||
{
|
||||
printf("Executing tests in %s\n", suiteName);
|
||||
}
|
||||
|
||||
void
|
||||
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||
double endTime, time_t totalRuntime)
|
||||
{
|
||||
printf("Suite executed. %d passed, %d failed and %d skipped\n", testsPassed, testsFailed, testsSkipped);
|
||||
}
|
||||
|
||||
void
|
||||
PlainTestStarted(const char *testName, const char *testDescription, time_t startTime)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
PlainTestEnded(const char *testName, const char *testDescription,
|
||||
int testResult, int numAsserts, time_t endTime, time_t totalRuntime)
|
||||
{
|
||||
printf("Asserts:%d\n", numAsserts);
|
||||
printf("%s: ok\n", testName);
|
||||
}
|
||||
|
||||
void
|
||||
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
time_t eventTime)
|
||||
{
|
||||
const char *result = (assertResult) ? "passed" : "failed";
|
||||
printf("%s %s: %s\n", assertName, assertResult, assertMessage);
|
||||
}
|
||||
|
||||
void
|
||||
PlainLog(const char *logMessage, time_t eventTime)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
25
test/test-automation/plain_logger.h
Normal file
25
test/test-automation/plain_logger.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef _PLAIN_LOGGER_H
|
||||
#define _PLAIN_LOGGER_H
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
void PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime);
|
||||
|
||||
void PlainRunEnded(time_t endTime, time_t totalRuntime);
|
||||
|
||||
void PlainSuiteStarted(const char *suiteName, time_t eventTime);
|
||||
|
||||
void PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||
double endTime, time_t totalRuntime);
|
||||
|
||||
void PlainTestStarted(const char *testName, const char *testDescription, time_t startTime);
|
||||
|
||||
void PlainTestEnded(const char *testName, const char *testDescription,
|
||||
int testResult, int numAsserts, time_t endTime, time_t totalRuntime);
|
||||
|
||||
void PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
time_t eventTime);
|
||||
|
||||
void PlainLog(const char *logMessage, time_t eventTime);
|
||||
|
||||
#endif
|
|
@ -19,10 +19,11 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef _XML_C
|
||||
#define _XML_C
|
||||
|
||||
#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
@ -110,12 +111,12 @@ PrintOpenTags()
|
|||
/*
|
||||
===================
|
||||
|
||||
XML
|
||||
Functions to handle XML creation
|
||||
|
||||
===================
|
||||
*/
|
||||
|
||||
static int has_open_element = 0;
|
||||
static const char *root;
|
||||
|
||||
void
|
||||
XMLOpenDocument(const char *rootTag, LogOutputFp log)
|
||||
|
@ -133,28 +134,14 @@ XMLOpenDocument(const char *rootTag, LogOutputFp log)
|
|||
|
||||
// add open tag
|
||||
AddOpenTag(rootTag);
|
||||
|
||||
root = rootTag; // it's fine, as long as rootTag points to static memory?
|
||||
}
|
||||
|
||||
void
|
||||
XMLCloseDocument() {
|
||||
// Close the open tags with proper nesting
|
||||
TagList *openTag = openTags;
|
||||
while(openTag) {
|
||||
TagList *temp = openTag->next;
|
||||
|
||||
size_t size = SDL_strlen(openTag->tag) + 4 + 1; /* one extra for '\0', '<', '/' and '>' */
|
||||
char *buffer = SDL_malloc(size);
|
||||
snprintf(buffer, size, "%s%s%s", "</", openTag->tag, ">");
|
||||
logger(buffer);
|
||||
SDL_free(buffer);
|
||||
|
||||
RemoveOpenTag(openTag->tag);
|
||||
|
||||
openTag = temp;
|
||||
XMLCloseElement(root);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *currentTag = NULL;
|
||||
|
||||
void
|
||||
XMLOpenElement(const char *tag)
|
||||
|
@ -165,10 +152,6 @@ XMLOpenElement(const char *tag)
|
|||
logger(buffer);
|
||||
SDL_free(buffer);
|
||||
|
||||
currentTag = tag;
|
||||
|
||||
has_open_element = 1;
|
||||
|
||||
AddOpenTag(tag);
|
||||
}
|
||||
|
||||
|
@ -183,10 +166,6 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute)
|
|||
logger(buffer);
|
||||
SDL_free(buffer);
|
||||
|
||||
currentTag = tag;
|
||||
|
||||
has_open_element = 1;
|
||||
|
||||
AddOpenTag(tag);
|
||||
}
|
||||
|
||||
|
@ -194,10 +173,6 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute)
|
|||
void
|
||||
XMLAddAttribute(const char *attribute, const char *value)
|
||||
{
|
||||
// Requires open element
|
||||
if(has_open_element == 0) {
|
||||
return ;
|
||||
}
|
||||
size_t attributeSize = SDL_strlen(attribute);
|
||||
size_t valueSize = SDL_strlen(value);
|
||||
|
||||
|
@ -249,6 +224,7 @@ XMLCloseElement(const char *tag)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
has_open_element = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -67,10 +67,11 @@ void XMLAddAttribute(const char *attribute, const char *value);
|
|||
void XMLAddContent(const char *content);
|
||||
|
||||
/*!
|
||||
* Closes previously opened element.
|
||||
* Enforces proper nesting by not allowing end elements haphazardly.
|
||||
* Closes previously opened element until tag given as parameter is met.
|
||||
* Enforces proper nesting by not allowing to close elements out-of-order.
|
||||
*
|
||||
* Closes all the opened elements until the given element/tag is found
|
||||
* which will be the last tag to be closed
|
||||
*
|
||||
* \param tag Element to close
|
||||
*/
|
||||
|
|
|
@ -18,42 +18,16 @@
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef _LOGGER_C
|
||||
#define _LOGGER_C
|
||||
|
||||
#include "logger.h"
|
||||
#ifndef _XML_LOGGER_C
|
||||
#define _XML_LOGGER_C
|
||||
|
||||
#include "xml.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*!
|
||||
* Prints the given message to stderr. Function adds nesting
|
||||
* to the output.
|
||||
*
|
||||
* \return Possible error value (\todo)
|
||||
*/
|
||||
int
|
||||
LogGenericOutput(const char *message)
|
||||
{
|
||||
/*
|
||||
int depth = indentDepth;
|
||||
while(depth--) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
*/
|
||||
|
||||
fprintf(stderr, "%s\n", message);
|
||||
fflush(stderr);
|
||||
}
|
||||
#include "xml_logger.h"
|
||||
|
||||
void
|
||||
RunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
||||
XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
||||
{
|
||||
XMLOpenDocument("testlog", outputFn);
|
||||
|
||||
|
@ -63,13 +37,13 @@ RunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
|||
}
|
||||
|
||||
void
|
||||
RunEnded(time_t endTime, time_t totalRuntime)
|
||||
XMLRunEnded(time_t endTime, time_t totalRuntime)
|
||||
{
|
||||
XMLCloseDocument();
|
||||
XMLCloseDocument("testlog");
|
||||
}
|
||||
|
||||
void
|
||||
SuiteStarted(const char *suiteName, time_t eventTime)
|
||||
XMLSuiteStarted(const char *suiteName, time_t eventTime)
|
||||
{
|
||||
XMLOpenElement("suite");
|
||||
|
||||
|
@ -79,51 +53,59 @@ SuiteStarted(const char *suiteName, time_t eventTime)
|
|||
}
|
||||
|
||||
void
|
||||
SuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||
XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||
double endTime, time_t totalRuntime)
|
||||
{
|
||||
XMLCloseElement("suite");
|
||||
}
|
||||
|
||||
void
|
||||
TestStarted(const char *testName, const char *testDescription, time_t startTime)
|
||||
XMLTestStarted(const char *testName, const char *testDescription, time_t startTime)
|
||||
{
|
||||
XMLOpenElement("test");
|
||||
|
||||
XMLOpenElement("name");
|
||||
XMLAddContent(testName);
|
||||
XMLCloseElement("name");
|
||||
|
||||
XMLOpenElement("description");
|
||||
XMLAddContent(testDescription);
|
||||
XMLCloseElement("description");
|
||||
|
||||
XMLOpenElement("starttime");
|
||||
//XMLAddContent(startTime);
|
||||
XMLCloseElement("starttime");
|
||||
}
|
||||
|
||||
void
|
||||
TestEnded(const char *testName, const char *testDescription, int testResult,
|
||||
int numAsserts, time_t endTime, time_t totalRuntime)
|
||||
XMLTestEnded(const char *testName, const char *testDescription,
|
||||
int testResult, int numAsserts, time_t endTime, time_t totalRuntime)
|
||||
{
|
||||
|
||||
XMLCloseElement("test");
|
||||
}
|
||||
|
||||
void
|
||||
Assert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
time_t eventTime)
|
||||
{
|
||||
XMLOpenElement("assert");
|
||||
|
||||
XMLOpenElement("result");
|
||||
XMLAddContent((assertResult) ? "pass" : "failure");
|
||||
XMLOpenElement("result");
|
||||
|
||||
|
||||
XMLCloseElement("assert");
|
||||
}
|
||||
|
||||
void
|
||||
Log(const char *logMessage, time_t eventTime)
|
||||
XMLLog(const char *logMessage, time_t eventTime)
|
||||
{
|
||||
XMLOpenElement("log");
|
||||
|
||||
}
|
||||
XMLAddContent(logMessage);
|
||||
|
||||
|
||||
/*!
|
||||
* Main for testing the logger
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
RunStarted(LogGenericOutput, "All the data from harness", 0);
|
||||
SuiteStarted("Suite data here", 0);
|
||||
SuiteEnded(0, 0, 0, 0.0f, 0);
|
||||
RunEnded(0, 0);
|
||||
|
||||
return 0;
|
||||
XMLCloseElement("log");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
25
test/test-automation/xml_logger.h
Normal file
25
test/test-automation/xml_logger.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef _XML_LOGGER_H
|
||||
#define _XML_LOGGER_H
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
void XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime);
|
||||
|
||||
void XMLRunEnded(time_t endTime, time_t totalRuntime);
|
||||
|
||||
void XMLSuiteStarted(const char *suiteName, time_t eventTime);
|
||||
|
||||
void XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||
double endTime, time_t totalRuntime);
|
||||
|
||||
void XMLTestStarted(const char *testName, const char *testDescription, time_t startTime);
|
||||
|
||||
void XMLTestEnded(const char *testName, const char *testDescription,
|
||||
int testResult, int numAsserts, time_t endTime, time_t totalRuntime);
|
||||
|
||||
void XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
time_t eventTime);
|
||||
|
||||
void XMLLog(const char *logMessage, time_t eventTime);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue