67 seed = (
char *)
SDL_malloc((length + 1) *
sizeof(char));
76 for (counter = 0; counter <
length; counter++) {
78 char ch = (char) (number % (91 - 48)) + 48;
79 if (ch >= 58 && ch <= 64) {
105 char iterationString[16];
109 Uint32 iterationStringLength;
110 Uint32 entireStringLength;
113 if (runSeed ==
NULL || runSeed[0] ==
'\0') {
118 if (suiteName ==
NULL || suiteName[0] ==
'\0') {
123 if (testName ==
NULL || testName[0] ==
'\0') {
128 if (iteration <= 0) {
134 SDL_memset(iterationString, 0,
sizeof(iterationString));
135 SDL_snprintf(iterationString,
sizeof(iterationString) - 1,
"%d", iteration);
141 iterationStringLength =
SDL_strlen(iterationString);
142 entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
143 buffer = (
char *)
SDL_malloc(entireStringLength);
144 if (buffer ==
NULL) {
149 SDL_snprintf(buffer, entireStringLength,
"%s%s%s%d", runSeed, suiteName, testName, iteration);
174 Uint32 timeoutInMilliseconds;
196 timeoutInMilliseconds = timeout * 1000;
230 int testCaseResult = 0;
294 if (fuzzerCount > 0) {
295 SDLTest_Log(
"Fuzzer invocations: %d", fuzzerCount);
325 while(&testSuites[suiteCounter]) {
326 testSuite=&testSuites[suiteCounter];
347 float currentClock = (float)clock();
348 return currentClock / (float)CLOCKS_PER_SEC;
367 int totalNumberOfTests = 0;
368 int failedNumberOfTests = 0;
371 int iterationCounter;
374 const char *runSeed =
NULL;
375 char *currentSuiteName;
376 char *currentTestName;
378 float runStartSeconds;
379 float suiteStartSeconds;
380 float testStartSeconds;
382 float suiteEndSeconds;
383 float testEndSeconds;
386 char *suiteFilterName =
NULL;
388 char *testFilterName =
NULL;
392 Uint32 totalTestFailedCount = 0;
393 Uint32 totalTestPassedCount = 0;
394 Uint32 totalTestSkippedCount = 0;
395 Uint32 testFailedCount = 0;
396 Uint32 testPassedCount = 0;
397 Uint32 testSkippedCount = 0;
403 if (testIterations < 1) {
408 if (userRunSeed ==
NULL || userRunSeed[0] ==
'\0') {
410 if (runSeed ==
NULL) {
415 runSeed = userRunSeed;
420 totalTestFailedCount = 0;
421 totalTestPassedCount = 0;
422 totalTestSkippedCount = 0;
428 SDLTest_Log(
"::::: Test Run /w seed '%s' started\n", runSeed);
432 while (testSuites[suiteCounter]) {
436 while (testSuite->
testCases[testCounter])
439 totalNumberOfTests++;
445 if (failedTests ==
NULL) {
452 if (filter !=
NULL && filter[0] !=
'\0') {
455 while (testSuites[suiteCounter] && suiteFilter == 0) {
461 suiteFilterName = testSuite->
name;
462 SDLTest_Log(
"Filtering: running only suite '%s'", suiteFilterName);
468 while (testSuite->
testCases[testCounter] && testFilter == 0)
475 suiteFilterName = testSuite->
name;
477 testFilterName = testCase->
name;
478 SDLTest_Log(
"Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName);
484 if (suiteFilter == 0 && testFilter == 0) {
494 while(testSuites[suiteCounter]) {
500 if (suiteFilter == 1 && suiteFilterName !=
NULL && testSuite->
name !=
NULL &&
511 testSkippedCount = 0;
530 if (testFilter == 1 && testFilterName !=
NULL && testCase->
name !=
NULL &&
533 SDLTest_Log(
"===== Test Case %i.%i: '%s' skipped\n",
539 if (testFilter == 1 && !testCase->
enabled) {
540 SDLTest_Log(
"Force run of disabled test since test filter was set");
558 iterationCounter = 0;
559 while(iterationCounter < testIterations)
563 if (userExecKey != 0) {
564 execKey = userExecKey;
570 testResult =
SDLTest_RunTest(testSuite, testCase, execKey, forceTestRun);
574 totalTestPassedCount++;
577 totalTestSkippedCount++;
580 totalTestFailedCount++;
586 runtime = testEndSeconds - testStartSeconds;
587 if (runtime < 0.0
f) runtime = 0.0f;
589 if (testIterations > 1) {
591 SDLTest_Log(
"Runtime of %i iterations: %.1f sec", testIterations, runtime);
592 SDLTest_Log(
"Average Test runtime: %.5f sec", runtime / (
float)testIterations);
595 SDLTest_Log(
"Total Test runtime: %.1f sec", runtime);
599 switch (testResult) {
613 failedTests[failedNumberOfTests] = testCase;
614 failedNumberOfTests++;
621 runtime = suiteEndSeconds - suiteStartSeconds;
622 if (runtime < 0.0
f) runtime = 0.0f;
625 SDLTest_Log(
"Total Suite runtime: %.1f sec", runtime);
628 countSum = testPassedCount + testFailedCount + testSkippedCount;
629 if (testFailedCount == 0)
631 SDLTest_Log(logFormat,
"Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
636 SDLTest_LogError(logFormat,
"Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
645 runtime = runEndSeconds - runStartSeconds;
646 if (runtime < 0.0
f) runtime = 0.0f;
649 SDLTest_Log(
"Total Run runtime: %.1f sec", runtime);
652 countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
653 if (totalTestFailedCount == 0)
656 SDLTest_Log(logFormat,
"Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
662 SDLTest_LogError(logFormat,
"Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
667 if (failedNumberOfTests > 0) {
669 for (testCounter = 0; testCounter < failedNumberOfTests; testCounter++) {
670 SDLTest_Log(
" --seed %s --filter %s", runSeed, failedTests[testCounter]->
name);
void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
SDLTest_TestCaseTearDownFp testTearDown
const char * SDLTest_FinalResultFormat
int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations)
Execute a test suite using the given run seed and execution key.
uint32_t Uint32
An unsigned 32-bit integer type.
char * SDLTest_GenerateRunSeed(const int length)
const char * SDLTest_InvalidNameFormat
Uint32(* SDL_TimerCallback)(Uint32 interval, void *param)
#define SDL_InitSubSystem
static Uint32 SDLTest_TestCaseTimeout
void SDLTest_BailOut()
Timeout handler. Aborts test run and exits harness process.
GLuint const GLchar * name
SDLTest_TestCaseSetUpFp testSetUp
uint64_t Uint64
An unsigned 64-bit integer type.
const SDLTest_TestCaseReference ** testCases
Uint64 SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
#define TEST_RESULT_FAILED
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and the ERROR priority.
void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext)
Initialize random number generator based on current system time.
SDL_TimerID SDLTest_SetTestTimeout(int timeout, void(*callback)())
Set timeout handler for test.
void SDLTest_Md5Update(SDLTest_Md5Context *mdContext, unsigned char *inBuf, unsigned int inLen)
update digest from variable length data
void SDLTest_Md5Init(SDLTest_Md5Context *mdContext)
initialize the context
#define TEST_RESULT_SETUP_FAILURE
static Uint32 callback(Uint32 interval, void *param)
#define TEST_RESULT_NO_ASSERT
unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext)
Initialize random number generator based on current system time.
int SDLTest_AssertSummaryToTestResult()
Converts the current assert summary state to a test result.
int SDLTest_GetFuzzerInvocationCount()
const char * SDLTest_LogSummaryFormat
#define TEST_RESULT_PASSED
void SDLTest_ResetAssertSummary()
Resets the assert summary counters to zero.
GLbitfield GLuint64 timeout
void SDLTest_Md5Final(SDLTest_Md5Context *mdContext)
complete digest computation
int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey, SDL_bool forceTestRun)
Execute a test using the given execution key.
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Prints given message with a timestamp in the TEST category and INFO priority.
void SDLTest_FuzzerInit(Uint64 execKey)
#define TEST_RESULT_SKIPPED
GLuint GLsizei GLsizei * length
SDLTest_TestCaseFp testCase
void SDLTest_LogAssertSummary()
Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
SDLTest_TestSuiteReference * testSuites[]