Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
635 lines (550 loc) · 19.1 KB

SDL_test_harness.c

File metadata and controls

635 lines (550 loc) · 19.1 KB
 
Dec 23, 2012
Dec 23, 2012
2
Simple DirectMedia Layer
Feb 15, 2013
Feb 15, 2013
3
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
Dec 23, 2012
Dec 23, 2012
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.
20
21
22
23
24
25
*/
#include "SDL_config.h"
#include "SDL_test.h"
Dec 5, 2012
Dec 5, 2012
26
27
#include <stdio.h>
#include <stdlib.h>
Dec 1, 2012
Dec 1, 2012
28
#include <string.h>
Dec 5, 2012
Dec 5, 2012
29
#include <time.h>
Dec 1, 2012
Dec 1, 2012
30
Dec 5, 2012
Dec 5, 2012
31
/* Invalid test name/description message format */
Dec 15, 2012
Dec 15, 2012
32
33
34
35
36
37
38
const char *SDLTest_InvalidNameFormat = "(Invalid)";
/* Log summary message format */
const char *SDLTest_LogSummaryFormat = "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d";
/* Final result message format */
const char *SDLTest_FinalResultFormat = ">>> %s '%s': %s\n";
Dec 5, 2012
Dec 5, 2012
39
40
41
/*! \brief Timeout for single test case execution */
static Uint32 SDLTest_TestCaseTimeout = 3600;
Dec 23, 2012
Dec 23, 2012
44
45
46
47
48
49
50
51
52
* Generates a random run seed string for the harness. The generated seed
* will contain alphanumeric characters (0-9A-Z).
*
* Note: The returned string needs to be deallocated by the caller.
*
* \param length The length of the seed string to generate
*
* \returns The generated seed string
*/
Dec 24, 2012
Dec 24, 2012
54
SDLTest_GenerateRunSeed(const int length)
55
56
57
58
59
{
char *seed = NULL;
SDLTest_RandomContext randomContext;
int counter;
May 18, 2013
May 18, 2013
60
/* Sanity check input */
61
62
63
64
65
if (length <= 0) {
SDLTest_LogError("The length of the harness seed must be >0.");
return NULL;
}
May 18, 2013
May 18, 2013
66
/* Allocate output buffer */
67
68
69
70
71
72
seed = (char *)SDL_malloc((length + 1) * sizeof(char));
if (seed == NULL) {
SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
return NULL;
}
May 18, 2013
May 18, 2013
73
/* Generate a random string of alphanumeric characters */
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
SDLTest_RandomInitTime(&randomContext);
for (counter = 0; counter < length - 1; ++counter) {
unsigned int number = SDLTest_Random(&randomContext);
char ch = (char) (number % (91 - 48)) + 48;
if (ch >= 58 && ch <= 64) {
ch = 65;
}
seed[counter] = ch;
}
seed[counter] = '\0';
return seed;
}
/**
Dec 23, 2012
Dec 23, 2012
89
90
91
92
93
94
95
96
97
98
* Generates an execution key for the fuzzer.
*
* \param runSeed The run seed to use
* \param suiteName The name of the test suite
* \param testName The name of the test
* \param iteration The iteration count
*
* \returns The generated execution key to initialize the fuzzer with.
*
*/
Dec 24, 2012
Dec 24, 2012
100
SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
101
102
103
104
105
106
107
108
109
110
111
{
SDLTest_Md5Context md5Context;
Uint64 *keys;
char iterationString[16];
Uint32 runSeedLength;
Uint32 suiteNameLength;
Uint32 testNameLength;
Uint32 iterationStringLength;
Uint32 entireStringLength;
char *buffer;
Dec 24, 2012
Dec 24, 2012
112
if (runSeed == NULL || SDL_strlen(runSeed)==0) {
113
114
115
116
SDLTest_LogError("Invalid runSeed string.");
return -1;
}
Dec 24, 2012
Dec 24, 2012
117
if (suiteName == NULL || SDL_strlen(suiteName)==0) {
118
119
120
121
SDLTest_LogError("Invalid suiteName string.");
return -1;
}
Dec 24, 2012
Dec 24, 2012
122
if (testName == NULL || SDL_strlen(testName)==0) {
123
124
125
126
127
128
129
130
131
SDLTest_LogError("Invalid testName string.");
return -1;
}
if (iteration <= 0) {
SDLTest_LogError("Invalid iteration count.");
return -1;
}
May 18, 2013
May 18, 2013
132
/* Convert iteration number into a string */
Dec 24, 2012
Dec 24, 2012
133
SDL_memset(iterationString, 0, sizeof(iterationString));
134
135
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
May 18, 2013
May 18, 2013
136
/* Combine the parameters into single string */
Dec 24, 2012
Dec 24, 2012
137
138
139
140
runSeedLength = SDL_strlen(runSeed);
suiteNameLength = SDL_strlen(suiteName);
testNameLength = SDL_strlen(testName);
iterationStringLength = SDL_strlen(iterationString);
141
142
143
144
145
146
147
148
entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
buffer = (char *)SDL_malloc(entireStringLength);
if (buffer == NULL) {
SDLTest_LogError("SDL_malloc failed to allocate buffer for execKey generation.");
return 0;
}
SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
May 18, 2013
May 18, 2013
149
/* Hash string and use half of the digest as 64bit exec key */
150
151
152
153
154
155
156
157
SDLTest_Md5Init(&md5Context);
SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, entireStringLength);
SDLTest_Md5Final(&md5Context);
SDL_free(buffer);
keys = (Uint64 *)md5Context.digest;
return keys[0];
}
Dec 1, 2012
Dec 1, 2012
158
159
/**
Dec 23, 2012
Dec 23, 2012
160
161
162
163
164
165
166
167
168
* \brief Set timeout handler for test.
*
* Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before.
*
* \param timeout Timeout interval in seconds.
* \param callback Function that will be called after timeout has elapsed.
*
* \return Timer id or -1 on failure.
*/
Dec 1, 2012
Dec 1, 2012
169
SDL_TimerID
Dec 24, 2012
Dec 24, 2012
170
SDLTest_SetTestTimeout(int timeout, void (*callback)())
Dec 1, 2012
Dec 1, 2012
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
{
Uint32 timeoutInMilliseconds;
SDL_TimerID timerID;
if (callback == NULL) {
SDLTest_LogError("Timeout callback can't be NULL");
return -1;
}
if (timeout < 0) {
SDLTest_LogError("Timeout value must be bigger than zero.");
return -1;
}
/* Init SDL timer if not initialized before */
if (SDL_WasInit(SDL_INIT_TIMER) == 0) {
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
SDLTest_LogError("Failed to init timer subsystem: %s", SDL_GetError());
return -1;
}
}
/* Set timer */
timeoutInMilliseconds = timeout * 1000;
timerID = SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback)callback, 0x0);
if (timerID == 0) {
SDLTest_LogError("Creation of SDL timer failed: %s", SDL_GetError());
return -1;
}
return timerID;
}
Dec 5, 2012
Dec 5, 2012
203
Dec 23, 2012
Dec 23, 2012
204
205
206
/**
* \brief Timeout handler. Aborts test run and exits harness process.
*/
Dec 5, 2012
Dec 5, 2012
207
void
Dec 23, 2012
Dec 23, 2012
208
SDLTest_BailOut()
Dec 5, 2012
Dec 5, 2012
209
210
{
SDLTest_LogError("TestCaseTimeout timer expired. Aborting test run.");
May 18, 2013
May 18, 2013
211
exit(TEST_ABORTED); /* bail out from the test */
Dec 5, 2012
Dec 5, 2012
212
213
214
}
/**
Dec 23, 2012
Dec 23, 2012
215
216
217
218
219
220
221
222
* \brief Execute a test using the given execution key.
*
* \param testSuite Suite containing the test case.
* \param testCase Case to execute.
* \param execKey Execution key for the fuzzer.
*
* \returns Test case result.
*/
Dec 5, 2012
Dec 5, 2012
223
int
Jan 31, 2013
Jan 31, 2013
224
SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey)
Dec 5, 2012
Dec 5, 2012
225
226
{
SDL_TimerID timer = 0;
May 18, 2013
May 18, 2013
227
int testCaseResult = 0;
Dec 10, 2012
Dec 10, 2012
228
int testResult = 0;
Dec 16, 2012
Dec 16, 2012
229
int fuzzerCount;
Dec 5, 2012
Dec 5, 2012
230
231
232
233
234
235
236
237
238
if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL)
{
SDLTest_LogError("Setup failure: testSuite or testCase references NULL");
return TEST_RESULT_SETUP_FAILURE;
}
if (!testCase->enabled)
{
Dec 23, 2012
Dec 23, 2012
239
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Skipped (Disabled)");
Dec 5, 2012
Dec 5, 2012
240
241
242
return TEST_RESULT_SKIPPED;
}
Dec 23, 2012
Dec 23, 2012
243
May 18, 2013
May 18, 2013
244
/* Initialize fuzzer */
Dec 5, 2012
Dec 5, 2012
245
246
SDLTest_FuzzerInit(execKey);
May 18, 2013
May 18, 2013
247
/* Reset assert tracker */
Dec 5, 2012
Dec 5, 2012
248
249
SDLTest_ResetAssertSummary();
May 18, 2013
May 18, 2013
250
/* Set timeout timer */
Dec 5, 2012
Dec 5, 2012
251
252
timer = SDLTest_SetTestTimeout(SDLTest_TestCaseTimeout, SDLTest_BailOut);
May 18, 2013
May 18, 2013
253
/* Maybe run suite initalizer function */
Dec 5, 2012
Dec 5, 2012
254
255
if (testSuite->testSetUp) {
testSuite->testSetUp(0x0);
Dec 10, 2012
Dec 10, 2012
256
if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) {
Dec 15, 2012
Dec 15, 2012
257
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite Setup", testSuite->name, "Failed");
Dec 5, 2012
Dec 5, 2012
258
259
260
261
return TEST_RESULT_SETUP_FAILURE;
}
}
May 18, 2013
May 18, 2013
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* Run test case function */
testCaseResult = testCase->testCase(0x0);
/* Convert test execution result into harness result */
if (testCaseResult == TEST_SKIPPED) {
/* Test was programatically skipped */
testResult = TEST_RESULT_SKIPPED;
} else if (testCaseResult == TEST_STARTED) {
/* Test did not return a TEST_COMPLETED value; assume it failed */
testResult = TEST_RESULT_FAILED;
} else if (testCaseResult == TEST_ABORTED) {
/* Test was aborted early; assume it failed */
testResult = TEST_RESULT_FAILED;
} else {
/* Perform failure analysis based on asserts */
testResult = SDLTest_AssertSummaryToTestResult();
}
Dec 5, 2012
Dec 5, 2012
279
May 18, 2013
May 18, 2013
280
/* Maybe run suite cleanup function (ignore failed asserts) */
Dec 5, 2012
Dec 5, 2012
281
282
283
284
if (testSuite->testTearDown) {
testSuite->testTearDown(0x0);
}
May 18, 2013
May 18, 2013
285
/* Cancel timeout timer */
Dec 5, 2012
Dec 5, 2012
286
287
288
289
if (timer) {
SDL_RemoveTimer(timer);
}
May 18, 2013
May 18, 2013
290
/* Report on asserts and fuzzer usage */
Dec 16, 2012
Dec 16, 2012
291
292
293
294
fuzzerCount = SDLTest_GetFuzzerInvocationCount();
if (fuzzerCount > 0) {
SDLTest_Log("Fuzzer invocations: %d", fuzzerCount);
}
May 18, 2013
May 18, 2013
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* Final log based on test execution result */
if (testCaseResult == TEST_SKIPPED) {
/* Test was programatically skipped */
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Skipped (Programmatically)");
} else if (testCaseResult == TEST_STARTED) {
/* Test did not return a TEST_COMPLETED value; assume it failed */
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Failed (test started, but did not return TEST_COMPLETED)");
} else if (testCaseResult == TEST_ABORTED) {
/* Test was aborted early; assume it failed */
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Failed (Aborted)");
} else {
SDLTest_LogAssertSummary();
}
Dec 5, 2012
Dec 5, 2012
309
Dec 10, 2012
Dec 10, 2012
310
return testResult;
Dec 5, 2012
Dec 5, 2012
311
312
313
314
315
316
317
318
319
320
}
/* Prints summary of all suites/tests contained in the given reference */
void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
{
int suiteCounter;
int testCounter;
SDLTest_TestSuiteReference *testSuite;
SDLTest_TestCaseReference *testCase;
May 18, 2013
May 18, 2013
321
/* Loop over all suites */
Dec 5, 2012
Dec 5, 2012
322
323
324
325
326
suiteCounter = 0;
while(&testSuites[suiteCounter]) {
testSuite=&testSuites[suiteCounter];
suiteCounter++;
SDLTest_Log("Test Suite %i - %s\n", suiteCounter,
Dec 15, 2012
Dec 15, 2012
327
(testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
Dec 5, 2012
Dec 5, 2012
328
May 18, 2013
May 18, 2013
329
/* Loop over all test cases */
Dec 5, 2012
Dec 5, 2012
330
331
332
333
334
335
testCounter = 0;
while(testSuite->testCases[testCounter])
{
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
testCounter++;
SDLTest_Log(" Test Case %i - %s: %s", testCounter,
Dec 15, 2012
Dec 15, 2012
336
337
(testCase->name) ? testCase->name : SDLTest_InvalidNameFormat,
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
Dec 5, 2012
Dec 5, 2012
338
339
340
341
}
}
}
Dec 15, 2012
Dec 15, 2012
342
343
344
345
346
347
/* Gets a timer value in seconds */
float GetClock()
{
float currentClock = (float)clock();
return currentClock / (float)CLOCKS_PER_SEC;
}
Dec 5, 2012
Dec 5, 2012
348
349
/**
Dec 23, 2012
Dec 23, 2012
350
351
352
353
354
355
356
357
358
359
360
361
362
* \brief Execute a test suite using the given run seend and execution key.
*
* The filter string is matched to the suite name (full comparison) to select a single suite,
* or if no suite matches, it is matched to the test names (full comparison) to select a single test.
*
* \param testSuites Suites containing the test case.
* \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
* \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
* \param filter Filter specification. NULL disables. Case sensitive.
* \param testIterations Number of iterations to run each test case.
*
* \returns Test run result; 0 when all tests passed, 1 if any tests failed.
*/
Dec 23, 2012
Dec 23, 2012
363
int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations)
Dec 5, 2012
Dec 5, 2012
364
365
366
367
368
369
{
int suiteCounter;
int testCounter;
int iterationCounter;
SDLTest_TestSuiteReference *testSuite;
SDLTest_TestCaseReference *testCase;
Dec 23, 2012
Dec 23, 2012
370
const char *runSeed = NULL;
Dec 15, 2012
Dec 15, 2012
371
372
char *currentSuiteName;
char *currentTestName;
Dec 5, 2012
Dec 5, 2012
373
Uint64 execKey;
Dec 15, 2012
Dec 15, 2012
374
375
376
377
378
379
float runStartSeconds;
float suiteStartSeconds;
float testStartSeconds;
float runEndSeconds;
float suiteEndSeconds;
float testEndSeconds;
Dec 17, 2012
Dec 17, 2012
380
float runtime;
Dec 23, 2012
Dec 23, 2012
381
382
383
384
int suiteFilter = 0;
char *suiteFilterName = NULL;
int testFilter = 0;
char *testFilterName = NULL;
Dec 15, 2012
Dec 15, 2012
385
386
387
388
389
390
391
392
393
394
int testResult = 0;
int runResult = 0;
Uint32 totalTestFailedCount = 0;
Uint32 totalTestPassedCount = 0;
Uint32 totalTestSkippedCount = 0;
Uint32 testFailedCount = 0;
Uint32 testPassedCount = 0;
Uint32 testSkippedCount = 0;
Uint32 countSum = 0;
char *logFormat = (char *)SDLTest_LogSummaryFormat;
Dec 5, 2012
Dec 5, 2012
395
May 18, 2013
May 18, 2013
396
/* Sanitize test iterations */
Dec 5, 2012
Dec 5, 2012
397
398
399
400
if (testIterations < 1) {
testIterations = 1;
}
May 18, 2013
May 18, 2013
401
/* Generate run see if we don't have one already */
Dec 24, 2012
Dec 24, 2012
402
if (userRunSeed == NULL || SDL_strlen(userRunSeed) == 0) {
Dec 5, 2012
Dec 5, 2012
403
404
runSeed = SDLTest_GenerateRunSeed(16);
if (runSeed == NULL) {
Dec 15, 2012
Dec 15, 2012
405
SDLTest_LogError("Generating a random seed failed");
Dec 5, 2012
Dec 5, 2012
406
407
return 2;
}
Dec 16, 2012
Dec 16, 2012
408
409
} else {
runSeed = userRunSeed;
Dec 5, 2012
Dec 5, 2012
410
411
}
Dec 23, 2012
Dec 23, 2012
412
May 18, 2013
May 18, 2013
413
/* Reset per-run counters */
Dec 15, 2012
Dec 15, 2012
414
415
416
totalTestFailedCount = 0;
totalTestPassedCount = 0;
totalTestSkippedCount = 0;
Dec 5, 2012
Dec 5, 2012
417
May 18, 2013
May 18, 2013
418
/* Take time - run start */
Dec 15, 2012
Dec 15, 2012
419
runStartSeconds = GetClock();
Dec 5, 2012
Dec 5, 2012
420
May 18, 2013
May 18, 2013
421
/* Log run with fuzzer parameters */
Dec 16, 2012
Dec 16, 2012
422
SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
Dec 5, 2012
Dec 5, 2012
423
May 18, 2013
May 18, 2013
424
/* Initialize filtering */
Dec 23, 2012
Dec 23, 2012
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
if (filter != NULL && SDL_strlen(filter) > 0) {
/* Loop over all suites to check if we have a filter match */
suiteCounter = 0;
while (testSuites[suiteCounter] && suiteFilter == 0) {
testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
suiteCounter++;
if (testSuite->name != NULL && SDL_strcmp(filter, testSuite->name) == 0) {
/* Matched a suite name */
suiteFilter = 1;
suiteFilterName = testSuite->name;
SDLTest_Log("Filtering: running only suite '%s'", suiteFilterName);
break;
}
/* Within each suite, loop over all test cases to check if we have a filter match */
testCounter = 0;
while (testSuite->testCases[testCounter] && testFilter == 0)
{
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
testCounter++;
if (testCase->name != NULL && SDL_strcmp(filter, testCase->name) == 0) {
/* Matched a test name */
suiteFilter = 1;
suiteFilterName = testSuite->name;
testFilter = 1;
testFilterName = testCase->name;
SDLTest_Log("Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName);
break;
}
}
}
if (suiteFilter == 0 && testFilter == 0) {
SDLTest_LogError("Filter '%s' did not match any test suite/case.", filter);
SDLTest_Log("Exit code: 2");
return 2;
}
}
May 18, 2013
May 18, 2013
464
/* Loop over all suites */
Dec 5, 2012
Dec 5, 2012
465
suiteCounter = 0;
Dec 15, 2012
Dec 15, 2012
466
467
468
while(testSuites[suiteCounter]) {
testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
currentSuiteName = (char *)((testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
Dec 23, 2012
Dec 23, 2012
469
suiteCounter++;
Dec 5, 2012
Dec 5, 2012
470
May 18, 2013
May 18, 2013
471
/* Filter suite if flag set and we have a name */
Dec 23, 2012
Dec 23, 2012
472
473
if (suiteFilter == 1 && suiteFilterName != NULL && testSuite->name != NULL &&
SDL_strcmp(suiteFilterName, testSuite->name) != 0) {
May 18, 2013
May 18, 2013
474
/* Skip suite */
Dec 23, 2012
Dec 23, 2012
475
476
477
478
479
SDLTest_Log("===== Test Suite %i: '%s' skipped\n",
suiteCounter,
currentSuiteName);
} else {
May 18, 2013
May 18, 2013
480
/* Reset per-suite counters */
Dec 23, 2012
Dec 23, 2012
481
482
483
484
testFailedCount = 0;
testPassedCount = 0;
testSkippedCount = 0;
May 18, 2013
May 18, 2013
485
/* Take time - suite start */
Dec 23, 2012
Dec 23, 2012
486
487
suiteStartSeconds = GetClock();
May 18, 2013
May 18, 2013
488
/* Log suite started */
Dec 23, 2012
Dec 23, 2012
489
490
491
492
SDLTest_Log("===== Test Suite %i: '%s' started\n",
suiteCounter,
currentSuiteName);
May 18, 2013
May 18, 2013
493
/* Loop over all test cases */
Dec 23, 2012
Dec 23, 2012
494
495
testCounter = 0;
while(testSuite->testCases[testCounter])
Dec 5, 2012
Dec 5, 2012
496
{
Dec 23, 2012
Dec 23, 2012
497
498
499
500
testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
currentTestName = (char *)((testCase->name) ? testCase->name : SDLTest_InvalidNameFormat);
testCounter++;
May 18, 2013
May 18, 2013
501
/* Filter tests if flag set and we have a name */
Dec 23, 2012
Dec 23, 2012
502
503
if (testFilter == 1 && testFilterName != NULL && testCase->name != NULL &&
SDL_strcmp(testFilterName, testCase->name) != 0) {
May 18, 2013
May 18, 2013
504
/* Skip test */
Dec 23, 2012
Dec 23, 2012
505
506
507
508
SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n",
suiteCounter,
testCounter,
currentTestName);
Dec 5, 2012
Dec 5, 2012
509
} else {
May 18, 2013
May 18, 2013
510
/* Override 'disabled' flag if we specified a test filter (i.e. force run for debugging) */
Jan 31, 2013
Jan 31, 2013
511
512
513
514
if (testFilter == 1 && !testCase->enabled) {
SDLTest_Log("Force run of disabled test since test filter was set");
testCase->enabled = 1;
}
Dec 5, 2012
Dec 5, 2012
515
May 18, 2013
May 18, 2013
516
/* Take time - test start */
Dec 23, 2012
Dec 23, 2012
517
518
testStartSeconds = GetClock();
May 18, 2013
May 18, 2013
519
/* Log test started */
Dec 23, 2012
Dec 23, 2012
520
521
522
523
SDLTest_Log("----- Test Case %i.%i: '%s' started",
suiteCounter,
testCounter,
currentTestName);
Dec 24, 2012
Dec 24, 2012
524
if (testCase->description != NULL && SDL_strlen(testCase->description)>0) {
Dec 23, 2012
Dec 23, 2012
525
526
527
528
SDLTest_Log("Test Description: '%s'",
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
}
May 18, 2013
May 18, 2013
529
/* Loop over all iterations */
Dec 23, 2012
Dec 23, 2012
530
531
532
533
534
535
536
537
iterationCounter = 0;
while(iterationCounter < testIterations)
{
iterationCounter++;
if (userExecKey != 0) {
execKey = userExecKey;
} else {
Dec 23, 2012
Dec 23, 2012
538
execKey = SDLTest_GenerateExecKey((char *)runSeed, testSuite->name, testCase->name, iterationCounter);
Dec 23, 2012
Dec 23, 2012
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
}
SDLTest_Log("Test Iteration %i: execKey %llu", iterationCounter, execKey);
testResult = SDLTest_RunTest(testSuite, testCase, execKey);
if (testResult == TEST_RESULT_PASSED) {
testPassedCount++;
totalTestPassedCount++;
} else if (testResult == TEST_RESULT_SKIPPED) {
testSkippedCount++;
totalTestSkippedCount++;
} else {
testFailedCount++;
totalTestFailedCount++;
}
}
May 18, 2013
May 18, 2013
556
/* Take time - test end */
Dec 23, 2012
Dec 23, 2012
557
558
559
560
561
testEndSeconds = GetClock();
runtime = testEndSeconds - testStartSeconds;
if (runtime < 0.0f) runtime = 0.0f;
if (testIterations > 1) {
May 18, 2013
May 18, 2013
562
/* Log test runtime */
Dec 23, 2012
Dec 23, 2012
563
564
565
SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime);
SDLTest_Log("Average Test runtime: %.5f sec", runtime / (float)testIterations);
} else {
May 18, 2013
May 18, 2013
566
/* Log test runtime */
Dec 23, 2012
Dec 23, 2012
567
568
569
SDLTest_Log("Total Test runtime: %.1f sec", runtime);
}
May 18, 2013
May 18, 2013
570
/* Log final test result */
Dec 23, 2012
Dec 23, 2012
571
572
573
574
575
576
577
578
579
580
581
switch (testResult) {
case TEST_RESULT_PASSED:
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed");
break;
case TEST_RESULT_FAILED:
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed");
break;
case TEST_RESULT_NO_ASSERT:
SDLTest_LogError((char *)SDLTest_FinalResultFormat,"Test", currentTestName, "No Asserts");
break;
}
Dec 5, 2012
Dec 5, 2012
582
583
584
585
}
}
May 18, 2013
May 18, 2013
586
/* Take time - suite end */
Dec 23, 2012
Dec 23, 2012
587
588
suiteEndSeconds = GetClock();
runtime = suiteEndSeconds - suiteStartSeconds;
Dec 17, 2012
Dec 17, 2012
589
if (runtime < 0.0f) runtime = 0.0f;
Dec 15, 2012
Dec 15, 2012
590
May 18, 2013
May 18, 2013
591
/* Log suite runtime */
Dec 23, 2012
Dec 23, 2012
592
SDLTest_Log("Total Suite runtime: %.1f sec", runtime);
Dec 5, 2012
Dec 5, 2012
593
May 18, 2013
May 18, 2013
594
/* Log summary and final Suite result */
Dec 23, 2012
Dec 23, 2012
595
596
597
598
599
600
601
602
603
604
605
countSum = testPassedCount + testFailedCount + testSkippedCount;
if (testFailedCount == 0)
{
SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed");
}
else
{
SDLTest_LogError(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed");
}
Dec 15, 2012
Dec 15, 2012
606
607
}
Dec 5, 2012
Dec 5, 2012
608
609
}
May 18, 2013
May 18, 2013
610
/* Take time - run end */
Dec 15, 2012
Dec 15, 2012
611
runEndSeconds = GetClock();
Dec 17, 2012
Dec 17, 2012
612
613
runtime = runEndSeconds - runStartSeconds;
if (runtime < 0.0f) runtime = 0.0f;
Dec 15, 2012
Dec 15, 2012
614
May 18, 2013
May 18, 2013
615
/* Log total runtime */
Dec 23, 2012
Dec 23, 2012
616
SDLTest_Log("Total Run runtime: %.1f sec", runtime);
Dec 5, 2012
Dec 5, 2012
617
May 18, 2013
May 18, 2013
618
/* Log summary and final run result */
Dec 15, 2012
Dec 15, 2012
619
countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
Dec 23, 2012
Dec 23, 2012
620
if (totalTestFailedCount == 0)
Dec 15, 2012
Dec 15, 2012
621
622
623
{
runResult = 0;
SDLTest_Log(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
Dec 16, 2012
Dec 16, 2012
624
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Passed");
Dec 15, 2012
Dec 15, 2012
625
626
627
628
629
}
else
{
runResult = 1;
SDLTest_LogError(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
Dec 16, 2012
Dec 16, 2012
630
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Failed");
Dec 15, 2012
Dec 15, 2012
631
}
Dec 5, 2012
Dec 5, 2012
632
Dec 16, 2012
Dec 16, 2012
633
SDLTest_Log("Exit code: %d", runResult);
Dec 15, 2012
Dec 15, 2012
634
return runResult;
Dec 5, 2012
Dec 5, 2012
635
}