upgrade SDL to version 2.0.8
[platform/upstream/SDL.git] / src / test / SDL_test_harness.c
index 15021c6..423ee98 100755 (executable)
@@ -22,7 +22,6 @@
 #include "SDL_config.h"
 
 #include "SDL_test.h"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -32,7 +31,7 @@
 #define SDLTEST_INVALID_NAME_FORMAT "(Invalid)"
 
 /* Log summary message format */
-#define SDLTEST_LOG_SUMMARY_FORMAT "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d"
+#define SDLTEST_LOG_SUMMARY_FORMAT "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d Unsupported=%d"
 
 /* Final result message format */
 #define SDLTEST_FINAL_RESULT_FORMAT ">>> %s '%s': %s\n"
@@ -250,7 +249,7 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseRef
     SDLTest_ResetAssertSummary();
 
     /* Set timeout timer */
-    timer = SDLTest_SetTestTimeout(SDLTest_TestCaseTimeout, SDLTest_BailOut);
+    //timer = SDLTest_SetTestTimeout(SDLTest_TestCaseTimeout, SDLTest_BailOut);
 
     /* Maybe run suite initalizer function */
     if (testSuite->testSetUp) {
@@ -274,6 +273,9 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseRef
     } else if (testCaseResult == TEST_ABORTED) {
         /* Test was aborted early; assume it failed */
         testResult = TEST_RESULT_FAILED;
+    } else if (testCaseResult == TEST_UNSUPPORTED) {
+        /* Test was unsupported */
+        testResult = TEST_RESULT_UNSUPPORTED;
     } else {
         /* Perform failure analysis based on asserts */
         testResult = SDLTest_AssertSummaryToTestResult();
@@ -305,6 +307,9 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseRef
     } else if (testCaseResult == TEST_ABORTED) {
         /* Test was aborted early; assume it failed */
         SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Failed (Aborted)");
+    } else if (testCaseResult == TEST_UNSUPPORTED) {
+        /* Test was unsupported */
+        SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Unsupported");
     } else {
         SDLTest_LogAssertSummary();
     }
@@ -313,7 +318,7 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseRef
 }
 
 /* Prints summary of all suites/tests contained in the given reference */
-#if 0 
+#if 0
 static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
 {
     int suiteCounter;
@@ -350,6 +355,34 @@ static float GetClock()
     return currentClock;
 }
 
+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\n", 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.
 *
@@ -388,15 +421,17 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
     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;
     Uint32 totalTestPassedCount = 0;
     Uint32 totalTestSkippedCount = 0;
+    Uint32 totalTestUnsupportedCount = 0;
     Uint32 testFailedCount = 0;
     Uint32 testPassedCount = 0;
     Uint32 testSkippedCount = 0;
+    Uint32 testUnsupportedCount = 0;
     Uint32 countSum = 0;
     const SDLTest_TestCaseReference **failedTests;
 
@@ -421,6 +456,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
     totalTestFailedCount = 0;
     totalTestPassedCount = 0;
     totalTestSkippedCount = 0;
+    totalTestUnsupportedCount = 0;
 
     /* Take time - run start */
     runStartSeconds = GetClock();
@@ -428,7 +464,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
     /* 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];
@@ -437,17 +473,17 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
         while (testSuite->testCases[testCounter])
         {
             testCounter++;
-                       totalNumberOfTests++;
-               }
-       }
-
-       /* Pre-allocate an array for tracking failed tests (potentially all test cases) */
-       failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
-       if (failedTests == NULL) {      
-          SDLTest_LogError("Unable to allocate cache for failed tests");
-           SDL_Error(SDL_ENOMEM);         
+            totalNumberOfTests++;
+        }
+    }
+
+    /* Pre-allocate an array for tracking failed tests (potentially all test cases) */
+    failedTests = (const 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') {
@@ -490,6 +526,11 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
         }
     }
 
+
+
+
+    SDL_RWops *rwops = SDL_RWFromFile("SDL_Log_Summary.txt", "a+");
+
     /* Loop over all suites */
     suiteCounter = 0;
     while(testSuites[suiteCounter]) {
@@ -501,23 +542,22 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
         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 */
             testFailedCount = 0;
             testPassedCount = 0;
             testSkippedCount = 0;
+            testUnsupportedCount = 0;
 
             /* Take time - suite start */
             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;
@@ -539,7 +579,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
                     /* Override 'disabled' flag if we specified a test filter (i.e. force run for debugging) */
                     if (testFilter == 1 && !testCase->enabled) {
                         SDLTest_Log("Force run of disabled test since test filter was set");
-                                               forceTestRun = SDL_TRUE;
+                        forceTestRun = SDL_TRUE;
                     }
 
                     /* Take time - test start */
@@ -568,7 +608,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
                         }
 
                         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++;
@@ -576,6 +616,9 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
                         } else if (testResult == TEST_RESULT_SKIPPED) {
                             testSkippedCount++;
                             totalTestSkippedCount++;
+                        } else if (testResult == TEST_RESULT_UNSUPPORTED) {
+                            testUnsupportedCount++;
+                            totalTestUnsupportedCount++;
                         } else {
                             testFailedCount++;
                             totalTestFailedCount++;
@@ -600,12 +643,15 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
                     switch (testResult) {
                     case TEST_RESULT_PASSED:
                         SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Passed");
+                        SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Passed");
                         break;
                     case TEST_RESULT_FAILED:
                         SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Failed");
+                        SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Failed");
                         break;
                     case TEST_RESULT_NO_ASSERT:
                         SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT,"Test", currentTestName, "No Asserts");
+                        SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "No Asserts");
                         break;
                     }
 
@@ -624,18 +670,23 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
 
             /* 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;
+            countSum = testPassedCount + testFailedCount + testSkippedCount + testUnsupportedCount;
             if (testFailedCount == 0)
             {
-                SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
+                SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
+                SDLTest_writeLogFile(rwops, SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
                 SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Passed");
+                SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Passed");
             }
             else
             {
-                SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
+                SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
+                SDLTest_writeLogFile(rwops, SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount, testUnsupportedCount);
                 SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Failed");
+                SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Failed");
             }
 
         }
@@ -650,18 +701,23 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
     SDLTest_Log("Total Run runtime: %.1f sec", runtime);
 
     /* Log summary and final run result */
-    countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
+    countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount + totalTestUnsupportedCount;
     if (totalTestFailedCount == 0)
     {
         runResult = 0;
-        SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
+        SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
+        SDLTest_writeLogFile(rwops, SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
         SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Passed");
+        SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Passed");
+
     }
     else
     {
         runResult = 1;
-        SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
+        SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
+        SDLTest_writeLogFile(rwops, SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount, totalTestUnsupportedCount);
         SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Failed");
+        SDLTest_writeLogFile(rwops, SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Failed");
     }
 
     /* Print repro steps for failed tests */
@@ -671,6 +727,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
           SDLTest_Log(" --seed %s --filter %s", runSeed, failedTests[testCounter]->name);
         }
     }
+    SDL_RWclose(rwops);
     SDL_free((void *) failedTests);
 
     SDLTest_Log("Exit code: %d", runResult);