#include "SDL_config.h"
#include "SDL_test.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return currentClock / (float)CLOCKS_PER_SEC;
}
+void SDLTest_writeLogFile(SDL_RWops *rwops, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list list;
+ char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
+
+ /* Print log message into a buffer */
+ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ va_start(list, fmt);
+ SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
+ va_end(list);
+
+ char *message = SDL_stack_alloc(char, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ if (!message)
+ return;
+
+ size_t len = SDL_strlen(logMessage);
+ SDL_strlcpy(message, logMessage,len+1);
+
+ char *text = SDL_stack_alloc(char, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ if(text)
+ {
+ SDL_snprintf(text, SDLTEST_MAX_LOGMESSAGE_LENGTH, " INFO: %s: %s\n", SDLTest_TimestampToString(time(0)), message);
+ SDL_RWwrite(rwops, text, 1, SDL_strlen(text));
+ SDL_stack_free(text);
+ }
+ SDL_stack_free(message);
+
+}
/**
* \brief Execute a test suite using the given run seed and execution key.
*
char *suiteFilterName = NULL;
int testFilter = 0;
char *testFilterName = NULL;
- SDL_bool forceTestRun = SDL_FALSE;
+ SDL_bool forceTestRun = SDL_FALSE;
int testResult = 0;
int runResult = 0;
Uint32 totalTestFailedCount = 0;
/* Log run with fuzzer parameters */
SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
- /* Count the total number of tests */
+ /* Count the total number of tests */
suiteCounter = 0;
while (testSuites[suiteCounter]) {
testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
while (testSuite->testCases[testCounter])
{
testCounter++;
- totalNumberOfTests++;
- }
- }
-
- /* Pre-allocate an array for tracking failed tests (potentially all test cases) */
- failedTests = (SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
- if (failedTests == NULL) {
- SDLTest_LogError("Unable to allocate cache for failed tests");
+ totalNumberOfTests++;
+ }
+ }
+
+ /* Pre-allocate an array for tracking failed tests (potentially all test cases) */
+ failedTests = (SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
+ if (failedTests == NULL) {
+ SDLTest_LogError("Unable to allocate cache for failed tests");
SDL_Error(SDL_ENOMEM);
return -1;
- }
+ }
/* Initialize filtering */
if (filter != NULL && filter[0] != '\0') {
}
}
+
+
+
+ SDL_RWops *rwops = SDL_RWFromFile("SDL_Log_Summary.txt", "a+");
+
/* Loop over all suites */
suiteCounter = 0;
while(testSuites[suiteCounter]) {
if (suiteFilter == 1 && suiteFilterName != NULL && testSuite->name != NULL &&
SDL_strcmp(suiteFilterName, testSuite->name) != 0) {
/* Skip suite */
- SDLTest_Log("===== Test Suite %i: '%s' skipped\n",
- suiteCounter,
- currentSuiteName);
+ SDLTest_Log("===== Test Suite %i: '%s' skipped\n", suiteCounter, currentSuiteName);
+ SDLTest_writeLogFile(rwops, "===== Test Suite %i: '%s' skipped\n", suiteCounter, currentSuiteName);
} else {
/* Reset per-suite counters */
suiteStartSeconds = GetClock();
/* Log suite started */
- SDLTest_Log("===== Test Suite %i: '%s' started\n",
- suiteCounter,
- currentSuiteName);
+ SDLTest_Log("===== Test Suite %i: '%s' started\n", suiteCounter, currentSuiteName);
+ SDLTest_writeLogFile(rwops, "===== Test Suite %i: '%s' started\n", suiteCounter, currentSuiteName);
/* Loop over all test cases */
testCounter = 0;
if (testFilter == 1 && testFilterName != NULL && testCase->name != NULL &&
SDL_strcmp(testFilterName, testCase->name) != 0) {
/* Skip test */
- SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n",
- suiteCounter,
- testCounter,
- currentTestName);
+ SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n", suiteCounter, testCounter, currentTestName);
} else {
/* Override 'disabled' flag if we specified a test filter (i.e. force run for debugging) */
if (testFilter == 1 && !testCase->enabled) {
testStartSeconds = GetClock();
/* Log test started */
- SDLTest_Log("----- Test Case %i.%i: '%s' started",
- suiteCounter,
- testCounter,
- currentTestName);
+ SDLTest_Log("----- Test Case %i.%i: '%s' started", suiteCounter, testCounter, currentTestName);
if (testCase->description != NULL && testCase->description[0] != '\0') {
- SDLTest_Log("Test Description: '%s'",
- (testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
+ SDLTest_Log("Test Description: '%s'", (testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
}
/* Loop over all iterations */
}
SDLTest_Log("Test Iteration %i: execKey %" SDL_PRIu64, iterationCounter, execKey);
- testResult = SDLTest_RunTest(testSuite, testCase, execKey, forceTestRun);
+ testResult = SDLTest_RunTest(testSuite, testCase, execKey, forceTestRun);
if (testResult == TEST_RESULT_PASSED) {
testPassedCount++;
switch (testResult) {
case TEST_RESULT_PASSED:
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed");
break;
case TEST_RESULT_FAILED:
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed");
break;
case TEST_RESULT_NO_ASSERT:
SDLTest_LogError((char *)SDLTest_FinalResultFormat,"Test", currentTestName, "No Asserts");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Test", currentTestName, "No Asserts");
break;
}
/* Log suite runtime */
SDLTest_Log("Total Suite runtime: %.1f sec", runtime);
+ SDLTest_writeLogFile(rwops, "Total Suite runtime: %.1f sec", runtime);
/* Log summary and final Suite result */
countSum = testPassedCount + testFailedCount + testSkippedCount + testUnsupportedCount;
if (testFailedCount == 0)
{
SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
+ SDLTest_writeLogFile(rwops, logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed");
}
else
{
SDLTest_LogError(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
+ SDLTest_writeLogFile(rwops, logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed");
+
}
}
{
runResult = 0;
SDLTest_Log(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
+ SDLTest_writeLogFile(rwops, logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
SDLTest_Log((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Passed");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Passed");
+
}
else
{
runResult = 1;
SDLTest_LogError(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
+ SDLTest_writeLogFile(rwops, logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Failed");
+ SDLTest_writeLogFile(rwops, (char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Failed");
}
/* Print repro steps for failed tests */
SDLTest_Log(" --seed %s --filter %s", runSeed, failedTests[testCounter]->name);
}
}
+ SDL_RWclose(rwops);
SDL_free(failedTests);
SDLTest_Log("Exit code: %d", runResult);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
va_end(list);
- //write log
- char *message;
+ //write log
+ char *message;
message = SDL_stack_alloc(char, SDLTEST_MAX_LOGMESSAGE_LENGTH);
if (!message) {
return;
size_t len = SDL_strlen(logMessage);
SDL_strlcpy(message, logMessage,len+1);
-// SDL_RWops *rwops = SDL_RWFromFile("log.txt", "a+");
+ SDL_RWops *rwops = SDL_RWFromFile("SDL_Log_AllPrint.txt", "a+");
char *text;
text = SDL_stack_alloc(char, SDLTEST_MAX_LOGMESSAGE_LENGTH);
if(text)
{
SDL_snprintf(text, SDLTEST_MAX_LOGMESSAGE_LENGTH, " INFO: %s: %s\n", SDLTest_TimestampToString(time(0)), message);
-// SDL_RWwrite(rwops, text, 1, SDL_strlen(text));
+ SDL_RWwrite(rwops, text, 1, SDL_strlen(text));
SDL_stack_free(text);
}
-// SDL_RWclose(rwops);
+ SDL_RWclose(rwops);
SDL_stack_free(message);
/* Log with timestamp and newline */
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
va_end(list);
- //write log
- char *message;
+ //write log
+ char *message;
message = SDL_stack_alloc(char, SDLTEST_MAX_LOGMESSAGE_LENGTH);
if (!message) {
return;
size_t len = SDL_strlen(logMessage);
SDL_strlcpy(message, logMessage,len+1);
-// SDL_RWops *rwops = SDL_RWFromFile("log.txt", "a+");
+ SDL_RWops *rwops = SDL_RWFromFile("SDL_Log_AllPrint.txt", "a+");
char *text;
text = SDL_stack_alloc(char, SDLTEST_MAX_LOGMESSAGE_LENGTH);
if(text)
{
SDL_snprintf(text, SDLTEST_MAX_LOGMESSAGE_LENGTH, " ERROR: %s: %s\n", SDLTest_TimestampToString(time(0)), message);
-// SDL_RWwrite(rwops, text, 1, SDL_strlen(text));
+ SDL_RWwrite(rwops, text, 1, SDL_strlen(text));
SDL_stack_free(text);
}
-// SDL_RWclose(rwops);
+ SDL_RWclose(rwops);
SDL_stack_free(message);
/* Log with timestamp and newline */