67 seed = (
char *)
SDL_malloc((length + 1) *
sizeof(char));
75 for (counter = 0; counter < length - 1; ++
counter) {
77 char ch = (char) (number % (91 - 48)) + 48;
78 if (ch >= 58 && ch <= 64) {
104 char iterationString[16];
108 Uint32 iterationStringLength;
109 Uint32 entireStringLength;
112 if (runSeed ==
NULL || runSeed[0] ==
'\0') {
117 if (suiteName ==
NULL || suiteName[0] ==
'\0') {
122 if (testName ==
NULL || testName[0] ==
'\0') {
127 if (iteration <= 0) {
133 SDL_memset(iterationString, 0,
sizeof(iterationString));
134 SDL_snprintf(iterationString,
sizeof(iterationString) - 1,
"%d", iteration);
140 iterationStringLength =
SDL_strlen(iterationString);
141 entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
142 buffer = (
char *)
SDL_malloc(entireStringLength);
143 if (buffer ==
NULL) {
144 SDLTest_LogError(
"SDL_malloc failed to allocate buffer for execKey generation.");
147 SDL_snprintf(buffer, entireStringLength,
"%s%s%s%d", runSeed, suiteName, testName, iteration);
172 Uint32 timeoutInMilliseconds;
175 if (callback ==
NULL) {
194 timeoutInMilliseconds = timeout * 1000;
195 timerID =
SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback)callback, 0
x0);
227 int testCaseResult = 0;
292 if (fuzzerCount > 0) {
293 SDLTest_Log(
"Fuzzer invocations: %d", fuzzerCount);
323 while(&testSuites[suiteCounter]) {
324 testSuite=&testSuites[suiteCounter];
345 float currentClock = (float)clock();
346 return currentClock / (float)CLOCKS_PER_SEC;
367 int iterationCounter;
370 const char *runSeed =
NULL;
371 char *currentSuiteName;
372 char *currentTestName;
374 float runStartSeconds;
375 float suiteStartSeconds;
376 float testStartSeconds;
378 float suiteEndSeconds;
379 float testEndSeconds;
382 char *suiteFilterName =
NULL;
384 char *testFilterName =
NULL;
387 Uint32 totalTestFailedCount = 0;
388 Uint32 totalTestPassedCount = 0;
389 Uint32 totalTestSkippedCount = 0;
390 Uint32 testFailedCount = 0;
391 Uint32 testPassedCount = 0;
392 Uint32 testSkippedCount = 0;
397 if (testIterations < 1) {
402 if (userRunSeed ==
NULL || userRunSeed[0] ==
'\0') {
404 if (runSeed ==
NULL) {
409 runSeed = userRunSeed;
414 totalTestFailedCount = 0;
415 totalTestPassedCount = 0;
416 totalTestSkippedCount = 0;
422 SDLTest_Log(
"::::: Test Run /w seed '%s' started\n", runSeed);
425 if (filter !=
NULL && filter[0] !=
'\0') {
428 while (testSuites[suiteCounter] && suiteFilter == 0) {
434 suiteFilterName = testSuite->
name;
435 SDLTest_Log(
"Filtering: running only suite '%s'", suiteFilterName);
441 while (testSuite->
testCases[testCounter] && testFilter == 0)
448 suiteFilterName = testSuite->
name;
450 testFilterName = testCase->
name;
451 SDLTest_Log(
"Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName);
457 if (suiteFilter == 0 && testFilter == 0) {
466 while(testSuites[suiteCounter]) {
472 if (suiteFilter == 1 && suiteFilterName !=
NULL && testSuite->
name !=
NULL &&
483 testSkippedCount = 0;
502 if (testFilter == 1 && testFilterName !=
NULL && testCase->
name !=
NULL &&
505 SDLTest_Log(
"===== Test Case %i.%i: '%s' skipped\n",
511 if (testFilter == 1 && !testCase->
enabled) {
512 SDLTest_Log(
"Force run of disabled test since test filter was set");
530 iterationCounter = 0;
531 while(iterationCounter < testIterations)
535 if (userExecKey != 0) {
536 execKey = userExecKey;
541 SDLTest_Log(
"Test Iteration %i: execKey %llu", iterationCounter, execKey);
546 totalTestPassedCount++;
549 totalTestSkippedCount++;
552 totalTestFailedCount++;
558 runtime = testEndSeconds - testStartSeconds;
559 if (runtime < 0.0
f) runtime = 0.0f;
561 if (testIterations > 1) {
563 SDLTest_Log(
"Runtime of %i iterations: %.1f sec", testIterations, runtime);
564 SDLTest_Log(
"Average Test runtime: %.5f sec", runtime / (
float)testIterations);
567 SDLTest_Log(
"Total Test runtime: %.1f sec", runtime);
571 switch (testResult) {
588 runtime = suiteEndSeconds - suiteStartSeconds;
589 if (runtime < 0.0
f) runtime = 0.0f;
592 SDLTest_Log(
"Total Suite runtime: %.1f sec", runtime);
595 countSum = testPassedCount + testFailedCount + testSkippedCount;
596 if (testFailedCount == 0)
598 SDLTest_Log(logFormat,
"Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
603 SDLTest_LogError(logFormat,
"Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
612 runtime = runEndSeconds - runStartSeconds;
613 if (runtime < 0.0
f) runtime = 0.0f;
616 SDLTest_Log(
"Total Run runtime: %.1f sec", runtime);
619 countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
620 if (totalTestFailedCount == 0)
623 SDLTest_Log(logFormat,
"Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
629 SDLTest_LogError(logFormat,
"Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
SDLTest_TestCaseTearDownFp testTearDown
const char * SDLTest_FinalResultFormat
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
char * SDLTest_GenerateRunSeed(const int length)
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
const char * SDLTest_InvalidNameFormat
DECLSPEC void SDLCALL SDL_free(void *mem)
static Uint32 SDLTest_TestCaseTimeout
void SDLTest_BailOut()
Timeout handler. Aborts test run and exits harness process.
DECLSPEC const char *SDLCALL SDL_GetError(void)
SDLTest_TestCaseSetUpFp testSetUp
const SDLTest_TestCaseReference ** testCases
Uint64 SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
Add a new timer to the pool of timers already running.
uint32_t Uint32
An unsigned 32-bit integer type.
EGLContext EGLenum EGLClientBuffer buffer
#define TEST_RESULT_FAILED
DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags)
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.
uint64_t Uint64
An unsigned 64-bit integer type.
DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags)
void SDLTest_Md5Update(SDLTest_Md5Context *mdContext, unsigned char *inBuf, unsigned int inLen)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
void SDLTest_Md5Init(SDLTest_Md5Context *mdContext)
#define TEST_RESULT_SETUP_FAILURE
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2)
GLbitfield GLuint64 timeout
#define TEST_RESULT_NO_ASSERT
void SDLTest_Log(const char *fmt,...)
Prints given message with a timestamp in the TEST category and INFO priority.
unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext)
Initialize random number generator based on current system time.
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
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.
void SDLTest_Md5Final(SDLTest_Md5Context *mdContext)
DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id)
Remove a timer knowing its ID.
void SDLTest_FuzzerInit(Uint64 execKey)
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.
#define TEST_RESULT_SKIPPED
SDLTest_TestCaseFp testCase
void SDLTest_LogAssertSummary()
Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey)
Execute a test using the given execution key.
void SDLTest_LogError(const char *fmt,...)
Prints given message with a timestamp in the TEST category and the ERROR priority.