From e6997f706ebbe757e83a1d9813ace9db87566971 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Thu, 28 Jul 2011 22:11:30 +0300 Subject: [PATCH] Fixed an issue with fuzzing seeds. --- .../build-scripts/install-tests.sh | 2 +- test/test-automation/fuzzer/fuzzer.c | 27 +++++++++---------- test/test-automation/fuzzer/fuzzer.h | 4 +-- test/test-automation/logger.h | 4 +-- test/test-automation/plain_logger.c | 2 +- test/test-automation/plain_logger.h | 2 +- test/test-automation/runner.c | 14 +++++----- test/test-automation/xml_logger.c | 2 +- test/test-automation/xml_logger.h | 2 +- 9 files changed, 29 insertions(+), 30 deletions(-) diff --git a/test/test-automation/build-scripts/install-tests.sh b/test/test-automation/build-scripts/install-tests.sh index a9517a271..fb78a8e49 100755 --- a/test/test-automation/build-scripts/install-tests.sh +++ b/test/test-automation/build-scripts/install-tests.sh @@ -21,6 +21,6 @@ do cp -f "$suite/.libs/lib$suite.$EXT" $DIRECTORY done -sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib +#sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib echo "Test suites installed." diff --git a/test/test-automation/fuzzer/fuzzer.c b/test/test-automation/fuzzer/fuzzer.c index 97a09d8fd..17ed7cc9d 100644 --- a/test/test-automation/fuzzer/fuzzer.c +++ b/test/test-automation/fuzzer/fuzzer.c @@ -7,14 +7,14 @@ //! context for test-specific random number generator static RND_CTX rndContext; -char * +int GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iterationNumber) { if(runSeed == NULL || suiteName == NULL || testName == NULL || iterationNumber < 0) { fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n"); - return NULL; + return -1; } char iterationString[256]; @@ -34,14 +34,12 @@ GenerateExecKey(char *runSeed, char *suiteName, char *buffer = SDL_malloc(entireString); if(!buffer) { - return NULL; + return -1; } SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName, testName, iterationNumber); - //printf("Debug: %s", buffer); - MD5_CTX md5Context; utl_md5Init(&md5Context); @@ -50,21 +48,20 @@ GenerateExecKey(char *runSeed, char *suiteName, SDL_free(buffer); - const int keyLength = SDL_strlen(md5Context.digest); - char *key = SDL_malloc(keyLength); - SDL_snprintf(key, keyLength, "%s", md5Context.digest); + char *execKey = md5Context.digest; - return key; + int key = execKey[4] << 24 | + execKey[9] << 16 | + execKey[13] << 8 | + execKey[3] << 0; + + return abs(key); } void -InitFuzzer(char *execKey) +InitFuzzer(int execKey) { - //int a = execKey[8,9,10,11]; - int a = execKey[8] | execKey[9] | execKey[10] | execKey[11]; - int b = execKey[12] | execKey[13] | execKey[14] | execKey[15]; - - utl_randomInit(&rndContext, a, b); + utl_randomInit(&rndContext, execKey, execKey / 0xfafafafa); } void diff --git a/test/test-automation/fuzzer/fuzzer.h b/test/test-automation/fuzzer/fuzzer.h index 6a981dd74..ccb296d72 100644 --- a/test/test-automation/fuzzer/fuzzer.h +++ b/test/test-automation/fuzzer/fuzzer.h @@ -29,7 +29,7 @@ /*! * Inits the fuzzer for a test */ -void InitFuzzer(char *execKey); +void InitFuzzer(int execKey); /*! @@ -113,6 +113,6 @@ char *RandomAsciiStringWithMaximumLength(int maxLength); * \return Generated execution key as blob of 16 bytes. It needs be deallocated. * On error, returns NULL. */ -char *GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber); +int GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber); #endif diff --git a/test/test-automation/logger.h b/test/test-automation/logger.h index 56ccb86f1..33497357d 100644 --- a/test/test-automation/logger.h +++ b/test/test-automation/logger.h @@ -55,7 +55,7 @@ typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped, time_t endTime, double totalRuntime); typedef void (*TestStartedFp)(const char *testName, const char *suiteName, - const char *testDescription, char *execKey, time_t startTime); + const char *testDescription, int execKey, time_t startTime); typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult, time_t endTime, double totalRuntime); @@ -86,7 +86,7 @@ extern AssertSummaryFp AssertSummary; extern LogFp Log; //! \todo move these two away from here -extern char *globalExecKey; +extern int globalExecKey; //! Run seed for harness extern char *runSeed; diff --git a/test/test-automation/plain_logger.c b/test/test-automation/plain_logger.c index 15dda5d14..728b6c2e1 100644 --- a/test/test-automation/plain_logger.c +++ b/test/test-automation/plain_logger.c @@ -119,7 +119,7 @@ PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, void PlainTestStarted(const char *testName, const char *suiteName, - const char *testDescription, char *execKey, time_t startTime) + const char *testDescription, int execKey, time_t startTime) { Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey); } diff --git a/test/test-automation/plain_logger.h b/test/test-automation/plain_logger.h index 5bdec3d3a..a685a81b3 100644 --- a/test/test-automation/plain_logger.h +++ b/test/test-automation/plain_logger.h @@ -60,7 +60,7 @@ void PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, * \param startTime When the test started to execute */ void PlainTestStarted(const char *testName, const char *suiteName, - const char *testDescription, char *execKey, time_t startTime); + const char *testDescription, int execKey, time_t startTime); /*! * Prints information about the test test that was just executed diff --git a/test/test-automation/runner.c b/test/test-automation/runner.c index 3aee5d6a2..c1ed1f7fa 100644 --- a/test/test-automation/runner.c +++ b/test/test-automation/runner.c @@ -112,10 +112,10 @@ char *runSeed = NULL; //! Variable is used to pass the generated execution key to a test -char *globalExecKey = NULL; +int globalExecKey = 0; //! Execution key that user supplied via command options -char *userExecKey = NULL; +int userExecKey = 0; //! How man time a test will be invocated int testInvocationCount = 1; @@ -716,7 +716,7 @@ CheckTestRequirements(TestCase *testCase) * \param test result */ int -RunTest(TestCase *testCase, char *execKey) +RunTest(TestCase *testCase, int execKey) { if(!testCase) { return -1; @@ -765,7 +765,7 @@ RunTest(TestCase *testCase, char *execKey) * \return The return value of the test. Zero means success, non-zero failure. */ int -ExecuteTest(TestCase *testItem, char *execKey) { +ExecuteTest(TestCase *testItem, int execKey) { int retVal = -1; if(execute_inproc) { @@ -1121,7 +1121,9 @@ ParseOptions(int argc, char *argv[]) exit(1); } - userExecKey = execKeyString; + // \todo User given string should be handled as a string + // representing a hex digit + userExecKey = atoi(execKeyString); } else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) { only_selected_test = 1; @@ -1341,7 +1343,7 @@ main(int argc, char *argv[]) } UnloadTestCases(testCases); - UnloadTestSuites(suites); // crashes here with -ts case1 + UnloadTestSuites(suites); const Uint32 endTicks = SDL_GetTicks(); const double totalRunTime = (endTicks - startTicks) / 1000.0f; diff --git a/test/test-automation/xml_logger.c b/test/test-automation/xml_logger.c index a576584a5..937c13f8a 100644 --- a/test/test-automation/xml_logger.c +++ b/test/test-automation/xml_logger.c @@ -351,7 +351,7 @@ XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, void XMLTestStarted(const char *testName, const char *suiteName, - const char *testDescription, char *execKey, time_t startTime) + const char *testDescription, int execKey, time_t startTime) { char * output = XMLOpenElement(testElementName); XMLOutputter(indentLevel++, YES, output); diff --git a/test/test-automation/xml_logger.h b/test/test-automation/xml_logger.h index 2a27a64aa..ec2c67be4 100644 --- a/test/test-automation/xml_logger.h +++ b/test/test-automation/xml_logger.h @@ -59,7 +59,7 @@ void XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, * \param startTime When the test started to execute */ void XMLTestStarted(const char *testName, const char *suiteName, - const char *testDescription, char *execKey, time_t startTime); + const char *testDescription, int execKey, time_t startTime); /*! * Prints information about the test test that was just executed in XML