aschiffler@6717
|
1 |
/*
|
aschiffler@6717
|
2 |
Simple DirectMedia Layer
|
aschiffler@6717
|
3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
aschiffler@6717
|
4 |
|
aschiffler@6717
|
5 |
This software is provided 'as-is', without any express or implied
|
aschiffler@6717
|
6 |
warranty. In no event will the authors be held liable for any damages
|
aschiffler@6717
|
7 |
arising from the use of this software.
|
aschiffler@6717
|
8 |
|
aschiffler@6717
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
aschiffler@6717
|
10 |
including commercial applications, and to alter it and redistribute it
|
aschiffler@6717
|
11 |
freely, subject to the following restrictions:
|
aschiffler@6717
|
12 |
|
aschiffler@6717
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
aschiffler@6717
|
14 |
claim that you wrote the original software. If you use this software
|
aschiffler@6717
|
15 |
in a product, an acknowledgment in the product documentation would be
|
aschiffler@6717
|
16 |
appreciated but is not required.
|
aschiffler@6717
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
aschiffler@6717
|
18 |
misrepresented as being the original software.
|
aschiffler@6717
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
aschiffler@6717
|
20 |
*/
|
aschiffler@6717
|
21 |
|
aschiffler@6717
|
22 |
#include "SDL_config.h"
|
aschiffler@6717
|
23 |
|
aschiffler@6717
|
24 |
#include "SDL_test.h"
|
aschiffler@6717
|
25 |
|
aschiffler@6721
|
26 |
#include <stdio.h>
|
aschiffler@6721
|
27 |
#include <stdlib.h>
|
aschiffler@6718
|
28 |
#include <string.h>
|
aschiffler@6721
|
29 |
#include <time.h>
|
aschiffler@6718
|
30 |
|
aschiffler@6756
|
31 |
/* Invalid test name/description message format */
|
aschiffler@6756
|
32 |
const char *SDLTest_InvalidNameFormat = "(Invalid)";
|
aschiffler@6721
|
33 |
|
aschiffler@6756
|
34 |
/* Log summary message format */
|
aschiffler@6756
|
35 |
const char *SDLTest_LogSummaryFormat = "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d";
|
aschiffler@6756
|
36 |
|
aschiffler@6756
|
37 |
/* Final result message format */
|
aschiffler@6756
|
38 |
const char *SDLTest_FinalResultFormat = ">>> %s '%s': %s\n";
|
aschiffler@6721
|
39 |
|
aschiffler@6721
|
40 |
/*! \brief Timeout for single test case execution */
|
aschiffler@6721
|
41 |
static Uint32 SDLTest_TestCaseTimeout = 3600;
|
aschiffler@6717
|
42 |
|
aschiffler@6717
|
43 |
/**
|
aschiffler@6717
|
44 |
* Generates a random run seed string for the harness. The generated seed
|
aschiffler@6717
|
45 |
* will contain alphanumeric characters (0-9A-Z).
|
aschiffler@6717
|
46 |
*
|
aschiffler@6717
|
47 |
* Note: The returned string needs to be deallocated by the caller.
|
aschiffler@6717
|
48 |
*
|
aschiffler@6717
|
49 |
* \param length The length of the seed string to generate
|
aschiffler@6717
|
50 |
*
|
aschiffler@6717
|
51 |
* \returns The generated seed string
|
aschiffler@6717
|
52 |
*/
|
aschiffler@6717
|
53 |
char *
|
aschiffler@6717
|
54 |
SDLTest_GenerateRunSeed(const int length)
|
aschiffler@6717
|
55 |
{
|
aschiffler@6717
|
56 |
char *seed = NULL;
|
aschiffler@6717
|
57 |
SDLTest_RandomContext randomContext;
|
aschiffler@6717
|
58 |
int counter;
|
aschiffler@6717
|
59 |
|
aschiffler@6717
|
60 |
// Sanity check input
|
aschiffler@6717
|
61 |
if (length <= 0) {
|
aschiffler@6717
|
62 |
SDLTest_LogError("The length of the harness seed must be >0.");
|
aschiffler@6717
|
63 |
return NULL;
|
aschiffler@6717
|
64 |
}
|
aschiffler@6717
|
65 |
|
aschiffler@6717
|
66 |
// Allocate output buffer
|
aschiffler@6717
|
67 |
seed = (char *)SDL_malloc((length + 1) * sizeof(char));
|
aschiffler@6717
|
68 |
if (seed == NULL) {
|
aschiffler@6717
|
69 |
SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
|
aschiffler@6717
|
70 |
return NULL;
|
aschiffler@6717
|
71 |
}
|
aschiffler@6717
|
72 |
|
aschiffler@6717
|
73 |
// Generate a random string of alphanumeric characters
|
aschiffler@6717
|
74 |
SDLTest_RandomInitTime(&randomContext);
|
aschiffler@6717
|
75 |
for (counter = 0; counter < length - 1; ++counter) {
|
aschiffler@6717
|
76 |
unsigned int number = SDLTest_Random(&randomContext);
|
aschiffler@6717
|
77 |
char ch = (char) (number % (91 - 48)) + 48;
|
aschiffler@6717
|
78 |
if (ch >= 58 && ch <= 64) {
|
aschiffler@6717
|
79 |
ch = 65;
|
aschiffler@6717
|
80 |
}
|
aschiffler@6717
|
81 |
seed[counter] = ch;
|
aschiffler@6717
|
82 |
}
|
aschiffler@6717
|
83 |
seed[counter] = '\0';
|
aschiffler@6717
|
84 |
|
aschiffler@6717
|
85 |
return seed;
|
aschiffler@6717
|
86 |
}
|
aschiffler@6717
|
87 |
|
aschiffler@6717
|
88 |
/**
|
aschiffler@6717
|
89 |
* Generates an execution key for the fuzzer.
|
aschiffler@6717
|
90 |
*
|
aschiffler@6717
|
91 |
* \param runSeed The run seed to use
|
aschiffler@6717
|
92 |
* \param suiteName The name of the test suite
|
aschiffler@6717
|
93 |
* \param testName The name of the test
|
aschiffler@6717
|
94 |
* \param iteration The iteration count
|
aschiffler@6717
|
95 |
*
|
aschiffler@6717
|
96 |
* \returns The generated execution key to initialize the fuzzer with.
|
aschiffler@6717
|
97 |
*
|
aschiffler@6717
|
98 |
*/
|
aschiffler@6717
|
99 |
Uint64
|
aschiffler@6717
|
100 |
SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
|
aschiffler@6717
|
101 |
{
|
aschiffler@6717
|
102 |
SDLTest_Md5Context md5Context;
|
aschiffler@6717
|
103 |
Uint64 *keys;
|
aschiffler@6717
|
104 |
char iterationString[16];
|
aschiffler@6717
|
105 |
Uint32 runSeedLength;
|
aschiffler@6717
|
106 |
Uint32 suiteNameLength;
|
aschiffler@6717
|
107 |
Uint32 testNameLength;
|
aschiffler@6717
|
108 |
Uint32 iterationStringLength;
|
aschiffler@6717
|
109 |
Uint32 entireStringLength;
|
aschiffler@6717
|
110 |
char *buffer;
|
aschiffler@6717
|
111 |
|
aschiffler@6717
|
112 |
if (runSeed == NULL || strlen(runSeed)==0) {
|
aschiffler@6717
|
113 |
SDLTest_LogError("Invalid runSeed string.");
|
aschiffler@6717
|
114 |
return -1;
|
aschiffler@6717
|
115 |
}
|
aschiffler@6717
|
116 |
|
aschiffler@6717
|
117 |
if (suiteName == NULL || strlen(suiteName)==0) {
|
aschiffler@6717
|
118 |
SDLTest_LogError("Invalid suiteName string.");
|
aschiffler@6717
|
119 |
return -1;
|
aschiffler@6717
|
120 |
}
|
aschiffler@6717
|
121 |
|
aschiffler@6717
|
122 |
if (testName == NULL || strlen(testName)==0) {
|
aschiffler@6717
|
123 |
SDLTest_LogError("Invalid testName string.");
|
aschiffler@6717
|
124 |
return -1;
|
aschiffler@6717
|
125 |
}
|
aschiffler@6717
|
126 |
|
aschiffler@6717
|
127 |
if (iteration <= 0) {
|
aschiffler@6717
|
128 |
SDLTest_LogError("Invalid iteration count.");
|
aschiffler@6717
|
129 |
return -1;
|
aschiffler@6717
|
130 |
}
|
aschiffler@6717
|
131 |
|
aschiffler@6717
|
132 |
// Convert iteration number into a string
|
aschiffler@6717
|
133 |
memset(iterationString, 0, sizeof(iterationString));
|
aschiffler@6717
|
134 |
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
|
aschiffler@6717
|
135 |
|
aschiffler@6717
|
136 |
// Combine the parameters into single string
|
aschiffler@6717
|
137 |
runSeedLength = strlen(runSeed);
|
aschiffler@6717
|
138 |
suiteNameLength = strlen(suiteName);
|
aschiffler@6717
|
139 |
testNameLength = strlen(testName);
|
aschiffler@6717
|
140 |
iterationStringLength = strlen(iterationString);
|
aschiffler@6717
|
141 |
entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
|
aschiffler@6717
|
142 |
buffer = (char *)SDL_malloc(entireStringLength);
|
aschiffler@6717
|
143 |
if (buffer == NULL) {
|
aschiffler@6717
|
144 |
SDLTest_LogError("SDL_malloc failed to allocate buffer for execKey generation.");
|
aschiffler@6717
|
145 |
return 0;
|
aschiffler@6717
|
146 |
}
|
aschiffler@6717
|
147 |
SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
|
aschiffler@6717
|
148 |
|
aschiffler@6717
|
149 |
// Hash string and use half of the digest as 64bit exec key
|
aschiffler@6717
|
150 |
SDLTest_Md5Init(&md5Context);
|
aschiffler@6717
|
151 |
SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, entireStringLength);
|
aschiffler@6717
|
152 |
SDLTest_Md5Final(&md5Context);
|
aschiffler@6717
|
153 |
SDL_free(buffer);
|
aschiffler@6717
|
154 |
keys = (Uint64 *)md5Context.digest;
|
aschiffler@6717
|
155 |
|
aschiffler@6717
|
156 |
return keys[0];
|
aschiffler@6717
|
157 |
}
|
aschiffler@6718
|
158 |
|
aschiffler@6718
|
159 |
/**
|
aschiffler@6718
|
160 |
* \brief Set timeout handler for test.
|
aschiffler@6718
|
161 |
*
|
aschiffler@6718
|
162 |
* Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before.
|
aschiffler@6718
|
163 |
*
|
aschiffler@6718
|
164 |
* \param timeout Timeout interval in seconds.
|
aschiffler@6718
|
165 |
* \param callback Function that will be called after timeout has elapsed.
|
aschiffler@6718
|
166 |
*
|
aschiffler@6718
|
167 |
* \return Timer id or -1 on failure.
|
aschiffler@6718
|
168 |
*/
|
aschiffler@6718
|
169 |
SDL_TimerID
|
aschiffler@6721
|
170 |
SDLTest_SetTestTimeout(int timeout, void (*callback)())
|
aschiffler@6718
|
171 |
{
|
aschiffler@6718
|
172 |
Uint32 timeoutInMilliseconds;
|
aschiffler@6718
|
173 |
SDL_TimerID timerID;
|
aschiffler@6718
|
174 |
|
aschiffler@6718
|
175 |
if (callback == NULL) {
|
aschiffler@6718
|
176 |
SDLTest_LogError("Timeout callback can't be NULL");
|
aschiffler@6718
|
177 |
return -1;
|
aschiffler@6718
|
178 |
}
|
aschiffler@6718
|
179 |
|
aschiffler@6718
|
180 |
if (timeout < 0) {
|
aschiffler@6718
|
181 |
SDLTest_LogError("Timeout value must be bigger than zero.");
|
aschiffler@6718
|
182 |
return -1;
|
aschiffler@6718
|
183 |
}
|
aschiffler@6718
|
184 |
|
aschiffler@6718
|
185 |
/* Init SDL timer if not initialized before */
|
aschiffler@6718
|
186 |
if (SDL_WasInit(SDL_INIT_TIMER) == 0) {
|
aschiffler@6718
|
187 |
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
|
aschiffler@6718
|
188 |
SDLTest_LogError("Failed to init timer subsystem: %s", SDL_GetError());
|
aschiffler@6718
|
189 |
return -1;
|
aschiffler@6718
|
190 |
}
|
aschiffler@6718
|
191 |
}
|
aschiffler@6718
|
192 |
|
aschiffler@6718
|
193 |
/* Set timer */
|
aschiffler@6718
|
194 |
timeoutInMilliseconds = timeout * 1000;
|
aschiffler@6718
|
195 |
timerID = SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback)callback, 0x0);
|
aschiffler@6718
|
196 |
if (timerID == 0) {
|
aschiffler@6718
|
197 |
SDLTest_LogError("Creation of SDL timer failed: %s", SDL_GetError());
|
aschiffler@6718
|
198 |
return -1;
|
aschiffler@6718
|
199 |
}
|
aschiffler@6718
|
200 |
|
aschiffler@6718
|
201 |
return timerID;
|
aschiffler@6718
|
202 |
}
|
aschiffler@6721
|
203 |
|
aschiffler@6721
|
204 |
void
|
aschiffler@6721
|
205 |
SDLTest_BailOut()
|
aschiffler@6721
|
206 |
{
|
aschiffler@6721
|
207 |
SDLTest_LogError("TestCaseTimeout timer expired. Aborting test run.");
|
aschiffler@6721
|
208 |
exit(TEST_ABORTED); // bail out from the test
|
aschiffler@6721
|
209 |
}
|
aschiffler@6721
|
210 |
|
aschiffler@6721
|
211 |
/**
|
aschiffler@6721
|
212 |
* \brief Execute a test using the given execution key.
|
aschiffler@6721
|
213 |
*
|
aschiffler@6721
|
214 |
* \param testSuite Suite containing the test case.
|
aschiffler@6721
|
215 |
* \param testCase Case to execute.
|
aschiffler@6721
|
216 |
* \param execKey Execution key for the fuzzer.
|
aschiffler@6721
|
217 |
*
|
aschiffler@6721
|
218 |
* \returns Test case result.
|
aschiffler@6721
|
219 |
*/
|
aschiffler@6721
|
220 |
int
|
aschiffler@6721
|
221 |
SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey)
|
aschiffler@6721
|
222 |
{
|
aschiffler@6721
|
223 |
SDL_TimerID timer = 0;
|
aschiffler@6727
|
224 |
int testResult = 0;
|
aschiffler@6757
|
225 |
int fuzzerCount;
|
aschiffler@6721
|
226 |
|
aschiffler@6721
|
227 |
if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL)
|
aschiffler@6721
|
228 |
{
|
aschiffler@6721
|
229 |
SDLTest_LogError("Setup failure: testSuite or testCase references NULL");
|
aschiffler@6721
|
230 |
return TEST_RESULT_SETUP_FAILURE;
|
aschiffler@6721
|
231 |
}
|
aschiffler@6721
|
232 |
|
aschiffler@6721
|
233 |
if (!testCase->enabled)
|
aschiffler@6721
|
234 |
{
|
aschiffler@6756
|
235 |
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Skipped");
|
aschiffler@6721
|
236 |
return TEST_RESULT_SKIPPED;
|
aschiffler@6721
|
237 |
}
|
aschiffler@6721
|
238 |
|
aschiffler@6757
|
239 |
// Initialize fuzzer
|
aschiffler@6721
|
240 |
SDLTest_FuzzerInit(execKey);
|
aschiffler@6721
|
241 |
|
aschiffler@6721
|
242 |
// Reset assert tracker
|
aschiffler@6721
|
243 |
SDLTest_ResetAssertSummary();
|
aschiffler@6721
|
244 |
|
aschiffler@6721
|
245 |
// Set timeout timer
|
aschiffler@6721
|
246 |
timer = SDLTest_SetTestTimeout(SDLTest_TestCaseTimeout, SDLTest_BailOut);
|
aschiffler@6721
|
247 |
|
aschiffler@6721
|
248 |
// Maybe run suite initalizer function
|
aschiffler@6721
|
249 |
if (testSuite->testSetUp) {
|
aschiffler@6721
|
250 |
testSuite->testSetUp(0x0);
|
aschiffler@6727
|
251 |
if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) {
|
aschiffler@6756
|
252 |
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite Setup", testSuite->name, "Failed");
|
aschiffler@6721
|
253 |
return TEST_RESULT_SETUP_FAILURE;
|
aschiffler@6721
|
254 |
}
|
aschiffler@6721
|
255 |
}
|
aschiffler@6721
|
256 |
|
aschiffler@6721
|
257 |
// Run test case function
|
aschiffler@6721
|
258 |
testCase->testCase(0x0);
|
aschiffler@6727
|
259 |
testResult = SDLTest_AssertSummaryToTestResult();
|
aschiffler@6721
|
260 |
|
aschiffler@6727
|
261 |
// Maybe run suite cleanup function (ignore failed asserts)
|
aschiffler@6721
|
262 |
if (testSuite->testTearDown) {
|
aschiffler@6721
|
263 |
testSuite->testTearDown(0x0);
|
aschiffler@6721
|
264 |
}
|
aschiffler@6721
|
265 |
|
aschiffler@6721
|
266 |
// Cancel timeout timer
|
aschiffler@6721
|
267 |
if (timer) {
|
aschiffler@6721
|
268 |
SDL_RemoveTimer(timer);
|
aschiffler@6721
|
269 |
}
|
aschiffler@6721
|
270 |
|
aschiffler@6721
|
271 |
// Report on asserts and fuzzer usage
|
aschiffler@6757
|
272 |
fuzzerCount = SDLTest_GetFuzzerInvocationCount();
|
aschiffler@6757
|
273 |
if (fuzzerCount > 0) {
|
aschiffler@6757
|
274 |
SDLTest_Log("Fuzzer invocations: %d", fuzzerCount);
|
aschiffler@6757
|
275 |
}
|
aschiffler@6721
|
276 |
SDLTest_LogAssertSummary();
|
aschiffler@6721
|
277 |
|
aschiffler@6727
|
278 |
return testResult;
|
aschiffler@6721
|
279 |
}
|
aschiffler@6721
|
280 |
|
aschiffler@6721
|
281 |
/* Prints summary of all suites/tests contained in the given reference */
|
aschiffler@6721
|
282 |
void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
|
aschiffler@6721
|
283 |
{
|
aschiffler@6721
|
284 |
int suiteCounter;
|
aschiffler@6721
|
285 |
int testCounter;
|
aschiffler@6721
|
286 |
SDLTest_TestSuiteReference *testSuite;
|
aschiffler@6721
|
287 |
SDLTest_TestCaseReference *testCase;
|
aschiffler@6721
|
288 |
|
aschiffler@6721
|
289 |
// Loop over all suites
|
aschiffler@6721
|
290 |
suiteCounter = 0;
|
aschiffler@6721
|
291 |
while(&testSuites[suiteCounter]) {
|
aschiffler@6721
|
292 |
testSuite=&testSuites[suiteCounter];
|
aschiffler@6721
|
293 |
suiteCounter++;
|
aschiffler@6721
|
294 |
SDLTest_Log("Test Suite %i - %s\n", suiteCounter,
|
aschiffler@6756
|
295 |
(testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
|
aschiffler@6721
|
296 |
|
aschiffler@6721
|
297 |
// Loop over all test cases
|
aschiffler@6721
|
298 |
testCounter = 0;
|
aschiffler@6721
|
299 |
while(testSuite->testCases[testCounter])
|
aschiffler@6721
|
300 |
{
|
aschiffler@6721
|
301 |
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
|
aschiffler@6721
|
302 |
testCounter++;
|
aschiffler@6721
|
303 |
SDLTest_Log(" Test Case %i - %s: %s", testCounter,
|
aschiffler@6756
|
304 |
(testCase->name) ? testCase->name : SDLTest_InvalidNameFormat,
|
aschiffler@6756
|
305 |
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
|
aschiffler@6721
|
306 |
}
|
aschiffler@6721
|
307 |
}
|
aschiffler@6721
|
308 |
}
|
aschiffler@6721
|
309 |
|
aschiffler@6756
|
310 |
/* Gets a timer value in seconds */
|
aschiffler@6756
|
311 |
float GetClock()
|
aschiffler@6756
|
312 |
{
|
aschiffler@6756
|
313 |
float currentClock = (float)clock();
|
aschiffler@6756
|
314 |
return currentClock / (float)CLOCKS_PER_SEC;
|
aschiffler@6756
|
315 |
}
|
aschiffler@6721
|
316 |
|
aschiffler@6721
|
317 |
/**
|
aschiffler@6756
|
318 |
* \brief Execute a test suite using the given run seend and execution key.
|
aschiffler@6721
|
319 |
*
|
aschiffler@6721
|
320 |
* \param testSuites Suites containing the test case.
|
aschiffler@6721
|
321 |
* \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
|
aschiffler@6721
|
322 |
* \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
|
aschiffler@6721
|
323 |
* \param testIterations Number of iterations to run each test case.
|
aschiffler@6721
|
324 |
*
|
aschiffler@6721
|
325 |
* \returns Test run result; 0 when all tests passed, 1 if any tests failed.
|
aschiffler@6721
|
326 |
*/
|
aschiffler@6721
|
327 |
int
|
aschiffler@6756
|
328 |
SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations)
|
aschiffler@6721
|
329 |
{
|
aschiffler@6721
|
330 |
int suiteCounter;
|
aschiffler@6721
|
331 |
int testCounter;
|
aschiffler@6721
|
332 |
int iterationCounter;
|
aschiffler@6721
|
333 |
SDLTest_TestSuiteReference *testSuite;
|
aschiffler@6721
|
334 |
SDLTest_TestCaseReference *testCase;
|
aschiffler@6727
|
335 |
char *runSeed = NULL;
|
aschiffler@6756
|
336 |
char *currentSuiteName;
|
aschiffler@6756
|
337 |
char *currentTestName;
|
aschiffler@6721
|
338 |
Uint64 execKey;
|
aschiffler@6756
|
339 |
float runStartSeconds;
|
aschiffler@6756
|
340 |
float suiteStartSeconds;
|
aschiffler@6756
|
341 |
float testStartSeconds;
|
aschiffler@6756
|
342 |
float runEndSeconds;
|
aschiffler@6756
|
343 |
float suiteEndSeconds;
|
aschiffler@6756
|
344 |
float testEndSeconds;
|
aschiffler@6760
|
345 |
float runtime;
|
aschiffler@6756
|
346 |
int testResult = 0;
|
aschiffler@6756
|
347 |
int runResult = 0;
|
aschiffler@6756
|
348 |
Uint32 totalTestFailedCount = 0;
|
aschiffler@6756
|
349 |
Uint32 totalTestPassedCount = 0;
|
aschiffler@6756
|
350 |
Uint32 totalTestSkippedCount = 0;
|
aschiffler@6756
|
351 |
Uint32 testFailedCount = 0;
|
aschiffler@6756
|
352 |
Uint32 testPassedCount = 0;
|
aschiffler@6756
|
353 |
Uint32 testSkippedCount = 0;
|
aschiffler@6756
|
354 |
Uint32 countSum = 0;
|
aschiffler@6756
|
355 |
char *logFormat = (char *)SDLTest_LogSummaryFormat;
|
aschiffler@6721
|
356 |
|
aschiffler@6721
|
357 |
// Sanitize test iterations
|
aschiffler@6721
|
358 |
if (testIterations < 1) {
|
aschiffler@6721
|
359 |
testIterations = 1;
|
aschiffler@6721
|
360 |
}
|
aschiffler@6721
|
361 |
|
aschiffler@6721
|
362 |
// Generate run see if we don't have one already
|
aschiffler@6721
|
363 |
if (userRunSeed == NULL || strlen(userRunSeed) == 0) {
|
aschiffler@6721
|
364 |
runSeed = SDLTest_GenerateRunSeed(16);
|
aschiffler@6721
|
365 |
if (runSeed == NULL) {
|
aschiffler@6756
|
366 |
SDLTest_LogError("Generating a random seed failed");
|
aschiffler@6721
|
367 |
return 2;
|
aschiffler@6721
|
368 |
}
|
aschiffler@6757
|
369 |
} else {
|
aschiffler@6757
|
370 |
runSeed = userRunSeed;
|
aschiffler@6721
|
371 |
}
|
aschiffler@6721
|
372 |
|
aschiffler@6721
|
373 |
// Reset per-run counters
|
aschiffler@6756
|
374 |
totalTestFailedCount = 0;
|
aschiffler@6756
|
375 |
totalTestPassedCount = 0;
|
aschiffler@6756
|
376 |
totalTestSkippedCount = 0;
|
aschiffler@6721
|
377 |
|
aschiffler@6721
|
378 |
// Take time - run start
|
aschiffler@6756
|
379 |
runStartSeconds = GetClock();
|
aschiffler@6721
|
380 |
|
aschiffler@6756
|
381 |
// Log run with fuzzer parameters
|
aschiffler@6757
|
382 |
SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
|
aschiffler@6721
|
383 |
|
aschiffler@6721
|
384 |
// Loop over all suites
|
aschiffler@6721
|
385 |
suiteCounter = 0;
|
aschiffler@6756
|
386 |
while(testSuites[suiteCounter]) {
|
aschiffler@6756
|
387 |
testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
|
aschiffler@6721
|
388 |
suiteCounter++;
|
aschiffler@6721
|
389 |
|
aschiffler@6721
|
390 |
// Reset per-suite counters
|
aschiffler@6756
|
391 |
testFailedCount = 0;
|
aschiffler@6756
|
392 |
testPassedCount = 0;
|
aschiffler@6756
|
393 |
testSkippedCount = 0;
|
aschiffler@6721
|
394 |
|
aschiffler@6721
|
395 |
// Take time - suite start
|
aschiffler@6756
|
396 |
suiteStartSeconds = GetClock();
|
aschiffler@6721
|
397 |
|
aschiffler@6756
|
398 |
// Log suite started
|
aschiffler@6756
|
399 |
currentSuiteName = (char *)((testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
|
aschiffler@6757
|
400 |
SDLTest_Log("===== Test Suite %i: '%s' started\n",
|
aschiffler@6756
|
401 |
suiteCounter,
|
aschiffler@6756
|
402 |
currentSuiteName);
|
aschiffler@6721
|
403 |
|
aschiffler@6721
|
404 |
// Loop over all test cases
|
aschiffler@6721
|
405 |
testCounter = 0;
|
aschiffler@6721
|
406 |
while(testSuite->testCases[testCounter])
|
aschiffler@6721
|
407 |
{
|
aschiffler@6721
|
408 |
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
|
aschiffler@6721
|
409 |
testCounter++;
|
aschiffler@6721
|
410 |
|
aschiffler@6721
|
411 |
// Take time - test start
|
aschiffler@6756
|
412 |
testStartSeconds = GetClock();
|
aschiffler@6721
|
413 |
|
aschiffler@6756
|
414 |
// Log test started
|
aschiffler@6756
|
415 |
currentTestName = (char *)((testCase->name) ? testCase->name : SDLTest_InvalidNameFormat);
|
aschiffler@6757
|
416 |
SDLTest_Log("----- Test Case %i.%i: '%s' started",
|
aschiffler@6757
|
417 |
suiteCounter,
|
aschiffler@6756
|
418 |
testCounter,
|
aschiffler@6756
|
419 |
currentTestName);
|
aschiffler@6757
|
420 |
if (testCase->description != NULL && strlen(testCase->description)>0) {
|
aschiffler@6757
|
421 |
SDLTest_Log("Test Description: '%s'",
|
aschiffler@6757
|
422 |
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
|
aschiffler@6757
|
423 |
}
|
aschiffler@6757
|
424 |
|
aschiffler@6721
|
425 |
// Loop over all iterations
|
aschiffler@6721
|
426 |
iterationCounter = 0;
|
aschiffler@6721
|
427 |
while(iterationCounter < testIterations)
|
aschiffler@6721
|
428 |
{
|
aschiffler@6721
|
429 |
iterationCounter++;
|
aschiffler@6721
|
430 |
|
aschiffler@6757
|
431 |
if (userExecKey != 0) {
|
aschiffler@6721
|
432 |
execKey = userExecKey;
|
aschiffler@6721
|
433 |
} else {
|
aschiffler@6721
|
434 |
execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter);
|
aschiffler@6721
|
435 |
}
|
aschiffler@6721
|
436 |
|
aschiffler@6757
|
437 |
SDLTest_Log("Test Iteration %i: execKey %llu", iterationCounter, execKey);
|
aschiffler@6721
|
438 |
testResult = SDLTest_RunTest(testSuite, testCase, execKey);
|
aschiffler@6721
|
439 |
|
aschiffler@6721
|
440 |
if (testResult == TEST_RESULT_PASSED) {
|
aschiffler@6721
|
441 |
testPassedCount++;
|
aschiffler@6721
|
442 |
totalTestPassedCount++;
|
aschiffler@6721
|
443 |
} else if (testResult == TEST_RESULT_SKIPPED) {
|
aschiffler@6721
|
444 |
testSkippedCount++;
|
aschiffler@6721
|
445 |
totalTestSkippedCount++;
|
aschiffler@6721
|
446 |
} else {
|
aschiffler@6721
|
447 |
testFailedCount++;
|
aschiffler@6721
|
448 |
totalTestFailedCount++;
|
aschiffler@6721
|
449 |
}
|
aschiffler@6721
|
450 |
}
|
aschiffler@6721
|
451 |
|
aschiffler@6721
|
452 |
// Take time - test end
|
aschiffler@6756
|
453 |
testEndSeconds = GetClock();
|
aschiffler@6760
|
454 |
runtime = testEndSeconds - testStartSeconds;
|
aschiffler@6760
|
455 |
if (runtime < 0.0f) runtime = 0.0f;
|
aschiffler@6756
|
456 |
|
aschiffler@6757
|
457 |
if (testIterations > 1) {
|
aschiffler@6757
|
458 |
// Log test runtime
|
aschiffler@6760
|
459 |
SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime);
|
aschiffler@6760
|
460 |
SDLTest_Log("Test runtime: %.5f sec", runtime / (float)testIterations);
|
aschiffler@6757
|
461 |
} else {
|
aschiffler@6757
|
462 |
// Log test runtime
|
aschiffler@6760
|
463 |
SDLTest_Log("Test runtime: %.1f sec", runtime);
|
aschiffler@6757
|
464 |
}
|
aschiffler@6721
|
465 |
|
aschiffler@6756
|
466 |
// Log final test result
|
aschiffler@6756
|
467 |
switch (testResult) {
|
aschiffler@6756
|
468 |
case TEST_RESULT_PASSED:
|
aschiffler@6756
|
469 |
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed");
|
aschiffler@6756
|
470 |
break;
|
aschiffler@6756
|
471 |
case TEST_RESULT_FAILED:
|
aschiffler@6756
|
472 |
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed");
|
aschiffler@6756
|
473 |
break;
|
aschiffler@6756
|
474 |
case TEST_RESULT_NO_ASSERT:
|
aschiffler@6756
|
475 |
SDLTest_LogError((char *)SDLTest_FinalResultFormat,"Test", currentTestName, "No Asserts");
|
aschiffler@6756
|
476 |
break;
|
aschiffler@6756
|
477 |
}
|
aschiffler@6721
|
478 |
}
|
aschiffler@6721
|
479 |
|
aschiffler@6721
|
480 |
// Take time - suite end
|
aschiffler@6756
|
481 |
suiteEndSeconds = GetClock();
|
aschiffler@6760
|
482 |
runtime = suiteEndSeconds - suiteStartSeconds;
|
aschiffler@6760
|
483 |
if (runtime < 0.0f) runtime = 0.0f;
|
aschiffler@6756
|
484 |
|
aschiffler@6756
|
485 |
// Log suite runtime
|
aschiffler@6760
|
486 |
SDLTest_Log("Suite runtime: %.1f sec", runtime);
|
aschiffler@6721
|
487 |
|
aschiffler@6756
|
488 |
// Log summary and final Suite result
|
aschiffler@6757
|
489 |
countSum = testPassedCount + testFailedCount + testSkippedCount;
|
aschiffler@6756
|
490 |
if (testFailedCount == 0)
|
aschiffler@6756
|
491 |
{
|
aschiffler@6756
|
492 |
SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
|
aschiffler@6756
|
493 |
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed");
|
aschiffler@6756
|
494 |
}
|
aschiffler@6756
|
495 |
else
|
aschiffler@6756
|
496 |
{
|
aschiffler@6756
|
497 |
SDLTest_LogError(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
|
aschiffler@6756
|
498 |
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed");
|
aschiffler@6756
|
499 |
}
|
aschiffler@6721
|
500 |
}
|
aschiffler@6721
|
501 |
|
aschiffler@6721
|
502 |
// Take time - run end
|
aschiffler@6756
|
503 |
runEndSeconds = GetClock();
|
aschiffler@6760
|
504 |
runtime = runEndSeconds - runStartSeconds;
|
aschiffler@6760
|
505 |
if (runtime < 0.0f) runtime = 0.0f;
|
aschiffler@6756
|
506 |
|
aschiffler@6756
|
507 |
// Log total runtime
|
aschiffler@6760
|
508 |
SDLTest_Log("Total runtime: %.1f sec", runtime);
|
aschiffler@6721
|
509 |
|
aschiffler@6756
|
510 |
// Log summary and final run result
|
aschiffler@6756
|
511 |
countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
|
aschiffler@6756
|
512 |
if (testFailedCount == 0)
|
aschiffler@6756
|
513 |
{
|
aschiffler@6756
|
514 |
runResult = 0;
|
aschiffler@6756
|
515 |
SDLTest_Log(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
|
aschiffler@6757
|
516 |
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Passed");
|
aschiffler@6756
|
517 |
}
|
aschiffler@6756
|
518 |
else
|
aschiffler@6756
|
519 |
{
|
aschiffler@6756
|
520 |
runResult = 1;
|
aschiffler@6756
|
521 |
SDLTest_LogError(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
|
aschiffler@6757
|
522 |
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Failed");
|
aschiffler@6756
|
523 |
}
|
aschiffler@6721
|
524 |
|
aschiffler@6757
|
525 |
SDLTest_Log("Exit code: %d", runResult);
|
aschiffler@6756
|
526 |
return runResult;
|
aschiffler@6721
|
527 |
}
|