1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#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;
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, "Test run ended at %s", TimestampToString(endTime));
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);
Output(indentLevel++, "Test description: %s", testDescription);
}
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