32 #define SDLTEST_INVALID_NAME_FORMAT "(Invalid)" 35 #define SDLTEST_LOG_SUMMARY_FORMAT "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d" 38 #define SDLTEST_FINAL_RESULT_FORMAT ">>> %s '%s': %s\n" 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];
106 size_t runSeedLength;
107 size_t suiteNameLength;
108 size_t testNameLength;
109 size_t iterationStringLength;
110 size_t 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);
153 SDLTest_Md5Update(&md5Context, (
unsigned char *)buffer, (
unsigned int) entireStringLength);
174 Uint32 timeoutInMilliseconds;
196 timeoutInMilliseconds = timeout * 1000;
230 int testCaseResult = 0;
294 if (fuzzerCount > 0) {
295 SDLTest_Log(
"Fuzzer invocations: %d", fuzzerCount);
326 while(&testSuites[suiteCounter]) {
327 testSuite=&testSuites[suiteCounter];
349 float currentClock = clock() / (float) CLOCKS_PER_SEC;
369 int totalNumberOfTests = 0;
370 int failedNumberOfTests = 0;
373 int iterationCounter;
376 const char *runSeed =
NULL;
377 char *currentSuiteName;
378 char *currentTestName;
380 float runStartSeconds;
381 float suiteStartSeconds;
382 float testStartSeconds;
384 float suiteEndSeconds;
385 float testEndSeconds;
388 char *suiteFilterName =
NULL;
390 char *testFilterName =
NULL;
394 Uint32 totalTestFailedCount = 0;
395 Uint32 totalTestPassedCount = 0;
396 Uint32 totalTestSkippedCount = 0;
397 Uint32 testFailedCount = 0;
398 Uint32 testPassedCount = 0;
399 Uint32 testSkippedCount = 0;
404 if (testIterations < 1) {
409 if (userRunSeed ==
NULL || userRunSeed[0] ==
'\0') {
411 if (runSeed ==
NULL) {
416 runSeed = userRunSeed;
421 totalTestFailedCount = 0;
422 totalTestPassedCount = 0;
423 totalTestSkippedCount = 0;
429 SDLTest_Log(
"::::: Test Run /w seed '%s' started\n", runSeed);
433 while (testSuites[suiteCounter]) {
437 while (testSuite->
testCases[testCounter])
440 totalNumberOfTests++;
446 if (failedTests ==
NULL) {
453 if (filter !=
NULL && filter[0] !=
'\0') {
456 while (testSuites[suiteCounter] && suiteFilter == 0) {
462 suiteFilterName = testSuite->
name;
463 SDLTest_Log(
"Filtering: running only suite '%s'", suiteFilterName);
469 while (testSuite->
testCases[testCounter] && testFilter == 0)
471 testCase = testSuite->
testCases[testCounter];
476 suiteFilterName = testSuite->
name;
478 testFilterName = testCase->
name;
479 SDLTest_Log(
"Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName);
485 if (suiteFilter == 0 && testFilter == 0) {
495 while(testSuites[suiteCounter]) {
501 if (suiteFilter == 1 && suiteFilterName !=
NULL && testSuite->
name !=
NULL &&
512 testSkippedCount = 0;
526 testCase = testSuite->
testCases[testCounter];
531 if (testFilter == 1 && testFilterName !=
NULL && testCase->
name !=
NULL &&
534 SDLTest_Log(
"===== Test Case %i.%i: '%s' skipped\n",
540 if (testFilter == 1 && !testCase->
enabled) {
541 SDLTest_Log(
"Force run of disabled test since test filter was set");
559 iterationCounter = 0;
560 while(iterationCounter < testIterations)
564 if (userExecKey != 0) {
565 execKey = userExecKey;
571 testResult =
SDLTest_RunTest(testSuite, testCase, execKey, forceTestRun);
575 totalTestPassedCount++;
578 totalTestSkippedCount++;
581 totalTestFailedCount++;
587 runtime = testEndSeconds - testStartSeconds;
588 if (runtime < 0.0
f) runtime = 0.0f;
590 if (testIterations > 1) {
592 SDLTest_Log(
"Runtime of %i iterations: %.1f sec", testIterations, runtime);
593 SDLTest_Log(
"Average Test runtime: %.5f sec", runtime / (
float)testIterations);
596 SDLTest_Log(
"Total Test runtime: %.1f sec", runtime);
600 switch (testResult) {
614 failedTests[failedNumberOfTests] = testCase;
615 failedNumberOfTests++;
622 runtime = suiteEndSeconds - suiteStartSeconds;
623 if (runtime < 0.0
f) runtime = 0.0f;
626 SDLTest_Log(
"Total Suite runtime: %.1f sec", runtime);
629 countSum = testPassedCount + testFailedCount + testSkippedCount;
630 if (testFailedCount == 0)
646 runtime = runEndSeconds - runStartSeconds;
647 if (runtime < 0.0
f) runtime = 0.0f;
650 SDLTest_Log(
"Total Run runtime: %.1f sec", runtime);
653 countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
654 if (totalTestFailedCount == 0)
668 if (failedNumberOfTests > 0) {
670 for (testCounter = 0; testCounter < failedNumberOfTests; testCounter++) {
671 SDLTest_Log(
" --seed %s --filter %s", runSeed, failedTests[testCounter]->
name);
#define SDLTEST_INVALID_NAME_FORMAT
SDLTest_TestCaseTearDownFp testTearDown
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.
char * SDLTest_GenerateRunSeed(const int length)
Generates a random run seed string for the harness. The generated seed will contain alphanumeric char...
Uint32(* SDL_TimerCallback)(Uint32 interval, void *param)
#define SDLTEST_FINAL_RESULT_FORMAT
#define SDL_InitSubSystem
static Uint32 SDLTest_TestCaseTimeout
SDLTest_TestCaseSetUpFp testSetUp
const SDLTest_TestCaseReference ** testCases
GLuint const GLchar * name
int SDLTest_GetFuzzerInvocationCount(void)
#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.
static SDL_TimerID SDLTest_SetTestTimeout(int timeout, void(*callback)())
Set timeout handler for test.
void SDLTest_ResetAssertSummary(void)
Resets the assert summary counters to zero.
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)
void SDLTest_LogAssertSummary(void)
Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
#define TEST_RESULT_NO_ASSERT
unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext)
Initialize random number generator based on current system time.
int SDLTest_AssertSummaryToTestResult(void)
Converts the current assert summary state to a test result.
#define TEST_RESULT_PASSED
GLbitfield GLuint64 timeout
void SDLTest_Md5Final(SDLTest_Md5Context *mdContext)
complete digest computation
#define SDLTEST_LOG_SUMMARY_FORMAT
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.
static Uint64 SDLTest_GenerateExecKey(const char *runSeed, char *suiteName, char *testName, int iteration)
static SDL_NORETURN void SDLTest_BailOut()
Timeout handler. Aborts test run and exits harness process.
void SDLTest_FuzzerInit(Uint64 execKey)
#define TEST_RESULT_SKIPPED
GLuint GLsizei GLsizei * length
SDLTest_TestCaseFp testCase
static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseReference *testCase, Uint64 execKey, SDL_bool forceTestRun)
Execute a test using the given execution key.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
SDLTest_TestSuiteReference * testSuites[]