This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
plain_logger.c
155 lines (130 loc) · 4.1 KB
1
2
3
4
#ifndef _PLAIN_LOGGER
#define _PLAIN_LOGGER
5
#include "logger_helpers.h"
6
#include "plain_logger.h"
7
#include "SDL_test.h"
8
9
10
static int indentLevel;
11
/*!
12
13
* Prints out the output of the logger
*
14
* \param currentIndentLevel The currently used indentation level
15
* \param message The message to be printed out
16
17
*/
int
18
Output(const int currentIndentLevel, const char *message, ...)
19
{
20
int ident = 0;
21
for( ; ident < currentIndentLevel; ++ident) {
22
23
24
fprintf(stdout, " "); // \todo make configurable?
}
25
26
27
28
29
30
31
32
33
34
char buffer[1024];
memset(buffer, 0, 1024);
va_list list;
va_start(list, message);
SDL_vsnprintf(buffer, 1024, message, list);
va_end(list);
35
36
fprintf(stdout, "%s\n", buffer);
fflush(stdout);
37
}
38
39
void
40
41
PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, void *data)
42
{
43
Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
44
Output(indentLevel, "Fuzzer seed is %s", runSeed);
45
Output(indentLevel, "Runner parameters: ");
46
47
48
49
int counter = 0;
for(counter = 0; counter < parameterCount; counter++) {
char *parameter = runnerParameters[counter];
50
Output(indentLevel, "\t%s", parameter);
51
}
52
53
Output(indentLevel, "");
54
55
56
}
void
57
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
58
int testSkippedCount, time_t endTime, double totalRuntime)
59
{
60
Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
61
testCount, totalRuntime, suiteCount);
62
63
64
Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount);
65
Output(indentLevel, "%d tests skipped", testSkippedCount);
66
67
68
69
70
}
void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
71
Output(indentLevel++, "Executing tests from %s", suiteName);
72
73
74
75
}
void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
76
time_t endTime, double totalRuntime)
77
{
78
79
80
Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
testsPassed, testsFailed, testsSkipped, totalRuntime);
Output(indentLevel, "");
81
82
83
}
void
84
PlainTestStarted(const char *testName, const char *suiteName,
85
const char *testDescription, char *execKey, time_t startTime)
86
{
87
Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
88
89
90
}
void
91
PlainTestEnded(const char *testName, const char *suiteName,
92
int testResult, time_t endTime, double totalRuntime)
93
{
94
95
96
97
98
99
100
101
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:
102
Output(--indentLevel, "%s: failed -> no assert", testName);
103
104
break;
case TEST_RESULT_SKIPPED:
105
Output(--indentLevel, "%s: skipped", testName);
106
107
108
109
110
111
112
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;
113
}
114
115
116
117
}
void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
118
119
120
time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
121
Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
122
123
124
125
}
void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
126
int actualValue, int expectedValue, time_t eventTime)
127
128
{
const char *result = (assertResult) ? "passed" : "failed";
129
130
Output(indentLevel, "%s: %s (expected %d, actualValue %d) - %s",
assertName, result, expectedValue, actualValue, assertMessage);
131
132
133
}
void
134
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
135
{
136
Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
137
numAssertsFailed, numAssertsPass, numAsserts);
138
139
140
}
void
141
PlainLog(time_t eventTime, char *fmt, ...)
142
{
143
144
145
146
147
148
149
150
151
// 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 );
152
Output(indentLevel, "%s", logMessage);
153
154
155
}
#endif