SDL-mirror/test/test-automation/src/libtest/plain_logger.c
Markus Kauppila 2f3c2a946c Reorganizing the project.
--HG--
rename : test/test-automation/SDL_test.h => test/test-automation/include/SDL_test.h
rename : test/test-automation/SDL_test.c => test/test-automation/src/libtest/SDL_test.c
rename : test/test-automation/common/common.c => test/test-automation/src/libtest/common/common.c
rename : test/test-automation/common/common.h => test/test-automation/src/libtest/common/common.h
rename : test/test-automation/common/images.h => test/test-automation/src/libtest/common/images.h
rename : test/test-automation/common/img_blit.c => test/test-automation/src/libtest/common/img_blit.c
rename : test/test-automation/common/img_blitblend.c => test/test-automation/src/libtest/common/img_blitblend.c
rename : test/test-automation/common/img_face.c => test/test-automation/src/libtest/common/img_face.c
rename : test/test-automation/common/img_primitives.c => test/test-automation/src/libtest/common/img_primitives.c
rename : test/test-automation/common/img_primitivesblend.c => test/test-automation/src/libtest/common/img_primitivesblend.c
rename : test/test-automation/fuzzer/fuzzer.c => test/test-automation/src/libtest/fuzzer/fuzzer.c
rename : test/test-automation/fuzzer/fuzzer.h => test/test-automation/src/libtest/fuzzer/fuzzer.h
rename : test/test-automation/fuzzer/utl_crc32.c => test/test-automation/src/libtest/fuzzer/utl_crc32.c
rename : test/test-automation/fuzzer/utl_crc32.h => test/test-automation/src/libtest/fuzzer/utl_crc32.h
rename : test/test-automation/fuzzer/utl_md5.c => test/test-automation/src/libtest/fuzzer/utl_md5.c
rename : test/test-automation/fuzzer/utl_md5.h => test/test-automation/src/libtest/fuzzer/utl_md5.h
rename : test/test-automation/fuzzer/utl_random.c => test/test-automation/src/libtest/fuzzer/utl_random.c
rename : test/test-automation/fuzzer/utl_random.h => test/test-automation/src/libtest/fuzzer/utl_random.h
rename : test/test-automation/logger_helpers.c => test/test-automation/src/libtest/logger_helpers.c
rename : test/test-automation/logger_helpers.h => test/test-automation/src/libtest/logger_helpers.h
rename : test/test-automation/plain_logger.c => test/test-automation/src/libtest/plain_logger.c
rename : test/test-automation/plain_logger.h => test/test-automation/src/libtest/plain_logger.h
rename : test/test-automation/xml.c => test/test-automation/src/libtest/xml.c
rename : test/test-automation/xml.h => test/test-automation/src/libtest/xml.h
rename : test/test-automation/xml_logger.c => test/test-automation/src/libtest/xml_logger.c
rename : test/test-automation/xml_logger.h => test/test-automation/src/libtest/xml_logger.h
rename : test/test-automation/logger.h => test/test-automation/src/runner/logger.h
rename : test/test-automation/runner.c => test/test-automation/src/runner/runner.c
rename : test/test-automation/support.c => test/test-automation/src/runner/support.c
rename : test/test-automation/support.h => test/test-automation/src/runner/support.h
rename : test/test-automation/testaudio/Makefile.am => test/test-automation/tests/testaudio/Makefile.am
rename : test/test-automation/testaudio/testaudio.c => test/test-automation/tests/testaudio/testaudio.c
rename : test/test-automation/testdummy/Makefile.am => test/test-automation/tests/testdummy/Makefile.am
rename : test/test-automation/testdummy/testdummy.c => test/test-automation/tests/testdummy/testdummy.c
rename : test/test-automation/testplatform/Makefile.am => test/test-automation/tests/testplatform/Makefile.am
rename : test/test-automation/testrect/Makefile.am => test/test-automation/tests/testrect/Makefile.am
rename : test/test-automation/testrect/testrect.c => test/test-automation/tests/testrect/testrect.c
rename : test/test-automation/testrender/Makefile.am => test/test-automation/tests/testrender/Makefile.am
rename : test/test-automation/testrender/testrender.c => test/test-automation/tests/testrender/testrender.c
rename : test/test-automation/testrwops/Makefile.am => test/test-automation/tests/testrwops/Makefile.am
rename : test/test-automation/testrwops/testrwops.c => test/test-automation/tests/testrwops/testrwops.c
rename : test/test-automation/testsurface/Makefile.am => test/test-automation/tests/testsurface/Makefile.am
rename : test/test-automation/testsurface/testsurface.c => test/test-automation/tests/testsurface/testsurface.c
2011-08-06 17:35:58 +03:00

204 lines
5 KiB
C

#ifndef _PLAIN_LOGGER
#define _PLAIN_LOGGER
#include "stdio.h"
#include "../../include/SDL_test.h"
#include "../runner/logger.h"
#include "logger_helpers.h"
#include "plain_logger.h"
/*! Current indentationt level */
static int indentLevel;
/*! Logging level of the logger */
static Level level = LOGGER_TERSE;
//! Handle to log file
static FILE *logFile;
/*!
* Prints out the output of the logger
*
* \param currentIndentLevel The currently used indentation level
* \param message The message to be printed out
*/
int
Output(const int currentIndentLevel, const char *message, ...)
{
if(logFile == NULL) {
fprintf(stderr, "logfile is NULL\n");
exit(3);
}
int indent = 0;
for( ; indent < currentIndentLevel; ++indent) {
fprintf(logFile, " "); // \todo make configurable?
}
char buffer[1024];
memset(buffer, 0, 1024);
va_list list;
va_start(list, message);
SDL_vsnprintf(buffer, 1024, message, list);
va_end(list);
fprintf(logFile, "%s\n", buffer);
fflush(logFile);
}
void
PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, LoggerData *data)
{
if(data == NULL) {
fprintf(stderr, "Logger data is NULL\n");
exit(3);
}
// Set up the logging destination
if(data->stdoutEnabled == 1) {
logFile = stdout;
} else {
logFile = fopen(data->filename, "w");
if(logFile == NULL) {
fprintf(stderr, "Log file %s couldn't opened\n", data->filename);
exit(3);
}
}
level = data->level;
//printf("Debug: %d == %d\n", level, data->level);
Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
Output(indentLevel, "Fuzzer seed is: %s", runSeed);
Output(indentLevel, "Runner parameters: ");
int counter = 0;
for(counter = 0; counter < parameterCount; counter++) {
char *parameter = runnerParameters[counter];
Output(indentLevel, "\t%s", parameter);
}
Output(indentLevel, "");
}
void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
int testSkippedCount, time_t endTime, double totalRuntime)
{
Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
testCount, totalRuntime, suiteCount);
Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount);
Output(indentLevel, "%d tests skipped", testSkippedCount);
fclose(logFile);
}
void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
Output(indentLevel++, "Executing tests from %s", suiteName);
}
void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
time_t endTime, double totalRuntime)
{
Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
testsPassed, testsFailed, testsSkipped, totalRuntime);
Output(indentLevel, "");
}
void
PlainTestStarted(const char *testName, const char *suiteName,
const char *testDescription, Uint64 execKey, time_t startTime)
{
Output(indentLevel++, "Executing test: %s (in %s). Exec key: %llX", testName, suiteName, execKey);
}
void
PlainTestEnded(const char *testName, const char *suiteName,
int testResult, time_t endTime, double totalRuntime)
{
switch(testResult) {
case TEST_RESULT_PASS:
Output(--indentLevel, "%s: ok", testName);
break;
case TEST_RESULT_FAILURE:
Output(--indentLevel, "%s: failed", testName);
break;
case TEST_RESULT_NO_ASSERT:
Output(--indentLevel, "%s: failed -> no assert", testName);
break;
case TEST_RESULT_SKIPPED:
Output(--indentLevel, "%s: skipped", testName);
break;
case TEST_RESULT_KILLED:
Output(--indentLevel, "%s: killed, exceeded timeout", testName);
break;
case TEST_RESULT_SETUP_FAILURE:
Output(--indentLevel, "%s: killed, setup failure", testName);
break;
}
}
void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime)
{
// Log passed asserts only on VERBOSE level
if(level <= LOGGER_TERSE && assertResult == ASSERT_PASS) {
return ;
}
const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
}
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 <= LOGGER_TERSE && assertResult == ASSERT_PASS) {
return ;
}
const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s (expected %d, actualValue %d) - %s",
assertName, result, expectedValue, actualValue, assertMessage);
}
void
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
{
Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
numAssertsFailed, numAssertsPass, numAsserts);
}
void
PlainLog(time_t eventTime, char *fmt, ...)
{
// create the log message
va_list args;
char logMessage[1024];
memset(logMessage, 0, sizeof(logMessage));
va_start( args, fmt );
SDL_vsnprintf( logMessage, sizeof(logMessage), fmt, args );
va_end( args );
Output(indentLevel, "%s", logMessage);
}
#endif