src/test/SDL_test_harness.c
changeset 8605 57faccca4fab
parent 8149 681eb46b8ac4
child 8831 9326ec96c132
     1.1 --- a/src/test/SDL_test_harness.c	Mon Mar 10 19:59:06 2014 -0700
     1.2 +++ b/src/test/SDL_test_harness.c	Tue Mar 11 07:17:56 2014 -0700
     1.3 @@ -67,12 +67,13 @@
     1.4      seed = (char *)SDL_malloc((length + 1) * sizeof(char));
     1.5      if (seed == NULL) {
     1.6          SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
     1.7 +        SDL_Error(SDL_ENOMEM);
     1.8          return NULL;
     1.9      }
    1.10  
    1.11      /* Generate a random string of alphanumeric characters */
    1.12      SDLTest_RandomInitTime(&randomContext);
    1.13 -    for (counter = 0; counter < length - 1; ++counter) {
    1.14 +    for (counter = 0; counter < length; counter++) {
    1.15          unsigned int number = SDLTest_Random(&randomContext);
    1.16          char ch = (char) (number % (91 - 48)) + 48;
    1.17          if (ch >= 58 && ch <= 64) {
    1.18 @@ -80,7 +81,7 @@
    1.19          }
    1.20          seed[counter] = ch;
    1.21      }
    1.22 -    seed[counter] = '\0';
    1.23 +    seed[length] = '\0';
    1.24  
    1.25      return seed;
    1.26  }
    1.27 @@ -141,7 +142,8 @@
    1.28      entireStringLength  = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
    1.29      buffer = (char *)SDL_malloc(entireStringLength);
    1.30      if (buffer == NULL) {
    1.31 -        SDLTest_LogError("SDL_malloc failed to allocate buffer for execKey generation.");
    1.32 +        SDLTest_LogError("Failed to allocate buffer for execKey generation.");
    1.33 +        SDL_Error(SDL_ENOMEM);
    1.34          return 0;
    1.35      }
    1.36      SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
    1.37 @@ -347,7 +349,7 @@
    1.38  }
    1.39  
    1.40  /**
    1.41 -* \brief Execute a test suite using the given run seend and execution key.
    1.42 +* \brief Execute a test suite using the given run seed and execution key.
    1.43  *
    1.44  * The filter string is matched to the suite name (full comparison) to select a single suite,
    1.45  * or if no suite matches, it is matched to the test names (full comparison) to select a single test.
    1.46 @@ -362,6 +364,8 @@
    1.47  */
    1.48  int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations)
    1.49  {
    1.50 +    int totalNumberOfTests = 0;
    1.51 +    int failedNumberOfTests = 0;
    1.52      int suiteCounter;
    1.53      int testCounter;
    1.54      int iterationCounter;
    1.55 @@ -392,6 +396,7 @@
    1.56      Uint32 testSkippedCount = 0;
    1.57      Uint32 countSum = 0;
    1.58      char *logFormat = (char *)SDLTest_LogSummaryFormat;
    1.59 +    SDLTest_TestCaseReference **failedTests;
    1.60  
    1.61      /* Sanitize test iterations */
    1.62      if (testIterations < 1) {
    1.63 @@ -421,6 +426,27 @@
    1.64      /* Log run with fuzzer parameters */
    1.65      SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
    1.66  
    1.67 +	/* Count the total number of tests */
    1.68 +    suiteCounter = 0;
    1.69 +    while (testSuites[suiteCounter]) {
    1.70 +        testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
    1.71 +        suiteCounter++;
    1.72 +        testCounter = 0;
    1.73 +        while (testSuite->testCases[testCounter])
    1.74 +        {
    1.75 +            testCounter++;
    1.76 +			totalNumberOfTests++;
    1.77 +		}
    1.78 +	}
    1.79 +
    1.80 +	/* Pre-allocate an array for tracking failed tests (potentially all test cases) */
    1.81 +	failedTests = (SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
    1.82 +	if (failedTests == NULL) {	
    1.83 +	   SDLTest_LogError("Unable to allocate cache for failed tests");
    1.84 +           SDL_Error(SDL_ENOMEM);	   
    1.85 +           return -1;
    1.86 +	}
    1.87 +
    1.88      /* Initialize filtering */
    1.89      if (filter != NULL && filter[0] != '\0') {
    1.90          /* Loop over all suites to check if we have a filter match */
    1.91 @@ -580,6 +606,11 @@
    1.92                          break;
    1.93                      }
    1.94  
    1.95 +                    /* Collect failed test case references for repro-step display */
    1.96 +                    if (testResult == TEST_RESULT_FAILED) {
    1.97 +                        failedTests[failedNumberOfTests] = testCase;
    1.98 +                        failedNumberOfTests++;
    1.99 +                    }
   1.100                  }
   1.101              }
   1.102  
   1.103 @@ -630,6 +661,15 @@
   1.104          SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Failed");
   1.105      }
   1.106  
   1.107 +    /* Print repro steps for failed tests */
   1.108 +    if (failedNumberOfTests > 0) {
   1.109 +        SDLTest_Log("Harness input to repro failures:");
   1.110 +        for (testCounter = 0; testCounter < failedNumberOfTests; testCounter++) {
   1.111 +          SDLTest_Log(" --seed %s --filter %s", runSeed, failedTests[testCounter]->name);
   1.112 +        }
   1.113 +    }
   1.114 +    SDL_free(failedTests);
   1.115 +
   1.116      SDLTest_Log("Exit code: %d", runResult);
   1.117      return runResult;
   1.118  }