diff --git a/test/test-automation/SDL_test.c b/test/test-automation/SDL_test.c index 28488bdc5..6feff93da 100644 --- a/test/test-automation/SDL_test.c +++ b/test/test-automation/SDL_test.c @@ -22,6 +22,8 @@ #include /* va_list */ #include +#include + #include "logger.h" #include "fuzzer/fuzzer.h" @@ -37,12 +39,9 @@ int _testAssertsFailed; int _testAssertsPassed; void -_InitTestEnvironment(char *execKey) +_InitTestEnvironment(Uint64 execKey) { - // The execKey gets corrupted while passing arguments - // hence the global variable to circumvent the problem - InitFuzzer(globalExecKey); - + InitFuzzer(execKey); _testReturnValue = TEST_RESULT_PASS; _testAssertsFailed = 0; diff --git a/test/test-automation/SDL_test.h b/test/test-automation/SDL_test.h index 7536b6d32..5de42f820 100644 --- a/test/test-automation/SDL_test.h +++ b/test/test-automation/SDL_test.h @@ -28,12 +28,6 @@ #include "fuzzer/fuzzer.h" -/* -extern int _testReturnValue; -extern int _testAssertsFailed; -extern int _testAssertsPassed; -*/ - #define TEST_ENABLED 1 #define TEST_DISABLED 0 @@ -71,8 +65,10 @@ typedef struct TestCaseReference { /*! * Initialized the test environment such as asserts. Must be called at * the beginning of every test case, before doing anything else. + * + * \param execKey Execution key for the test */ -void _InitTestEnvironment(char *execKey); +void _InitTestEnvironment(Uint64 execKey); /*! * Deinitializes the test environment and diff --git a/test/test-automation/fuzzer/fuzzer.c b/test/test-automation/fuzzer/fuzzer.c index 3b2e4215a..baa3396a4 100644 --- a/test/test-automation/fuzzer/fuzzer.c +++ b/test/test-automation/fuzzer/fuzzer.c @@ -1,4 +1,7 @@ +#include +#include + #include "../SDL_test.h" #include "fuzzer.h" @@ -7,29 +10,43 @@ //! context for test-specific random number generator static RND_CTX rndContext; -int +Uint64 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"); + if(runSeed == NULL) { + fprintf(stderr, "Error: Incorrect runSeed given to GenerateExecKey function\n"); return -1; } - char iterationString[256]; - memset(iterationString, 0, sizeof(iterationString)); + if(suiteName == NULL) { + fprintf(stderr, "Error: Incorrect suiteName given to GenerateExecKey function\n"); + return -1; + } - snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber); + if(testName == NULL) { + fprintf(stderr, "Error: Incorrect testName given to GenerateExecKey function\n"); + return -1; + } + + if(iterationNumber < 0) { + fprintf(stderr, "Error: Incorrect iteration number given to GenerateExecKey function\n"); + return -1; + } + + + char iterationString[16]; + memset(iterationString, 0, sizeof(iterationString)); + SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iterationNumber); // combine the parameters - const int runSeedLength = strlen(runSeed); - const int suiteNameLength = strlen(suiteName); - const int testNameLength = strlen(testName); - const int iterationStringLength = strlen(iterationString); + const Uint32 runSeedLength = strlen(runSeed); + const Uint32 suiteNameLength = strlen(suiteName); + const Uint32 testNameLength = strlen(testName); + const Uint32 iterationStringLength = strlen(iterationString); // size of the entire + 3 for slashes and + 1 for '\0' - const int entireString = runSeedLength + suiteNameLength + + const Uint32 entireString = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 3 + 1; char *buffer = SDL_malloc(entireString); @@ -48,21 +65,32 @@ GenerateExecKey(char *runSeed, char *suiteName, SDL_free(buffer); - char *execKey = md5Context.digest; + const char *execKey = md5Context.digest; - //! \todo could this be enhanced? - int key = execKey[4] << 24 | - execKey[9] << 16 | - execKey[13] << 8 | - execKey[3] << 0; + //printf("Debug: digest = %s\n", execKey); - return abs(key); + Uint64 key = execKey[8] << 56 | + execKey[9] << 48 | + execKey[10] << 40 | + execKey[11] << 32 | + execKey[12] << 24 | + execKey[13] << 16 | + execKey[14] << 8 | + execKey[15] << 0; + + return key; } void -InitFuzzer(int execKey) +InitFuzzer(Uint64 execKey) { - utl_randomInit(&rndContext, execKey, execKey / 0xfafafafa); + Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF; + Uint32 b = execKey & 0x00000000FFFFFFFF; + + //printf("Debug: execKey: %llx\n", execKey); + //printf("Debug: a = %x - b = %x\n", a, b); + + utl_randomInit(&rndContext, a, b); } void diff --git a/test/test-automation/fuzzer/fuzzer.h b/test/test-automation/fuzzer/fuzzer.h index ccb296d72..32b82c05b 100644 --- a/test/test-automation/fuzzer/fuzzer.h +++ b/test/test-automation/fuzzer/fuzzer.h @@ -21,6 +21,8 @@ #ifndef _FUZZER_H #define _FUZZER_H +#include + #include "utl_crc32.h" #include "utl_md5.h" #include "utl_random.h" @@ -29,7 +31,7 @@ /*! * Inits the fuzzer for a test */ -void InitFuzzer(int execKey); +void InitFuzzer(Uint64 execKey); /*! @@ -113,6 +115,6 @@ char *RandomAsciiStringWithMaximumLength(int maxLength); * \return Generated execution key as blob of 16 bytes. It needs be deallocated. * On error, returns NULL. */ -int GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber); +Uint64 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 2441baecc..b2cf42a94 100644 --- a/test/test-automation/logger.h +++ b/test/test-automation/logger.h @@ -21,6 +21,8 @@ #ifndef _LOGGER_H #define _LOGGER_H +#include + #include /* Logging levels */ @@ -56,7 +58,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, int execKey, time_t startTime); + const char *testDescription, Uint64 execKey, time_t startTime); typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult, time_t endTime, double totalRuntime); @@ -86,8 +88,6 @@ extern AssertWithValuesFp AssertWithValues; extern AssertSummaryFp AssertSummary; extern LogFp Log; -//! \todo move these two away from here -extern int globalExecKey; //! Run seed for harness extern char *runSeed; diff --git a/test/test-automation/logger_helpers.c b/test/test-automation/logger_helpers.c index eefb8ba88..3b5ecff6e 100644 --- a/test/test-automation/logger_helpers.c +++ b/test/test-automation/logger_helpers.c @@ -33,11 +33,11 @@ char *IntToString(const int integer) { * \param integer The converted integer * \returns Given integer as string in hex fomat */ -char *IntToHexString(const int integer) { +char *IntToHexString(const Uint64 integer) { static char buffer[256]; // malloc might work better memset(buffer, 0, sizeof(buffer)); - SDL_snprintf(buffer, sizeof(buffer), "%X", integer); + SDL_snprintf(buffer, sizeof(buffer), "%llX", integer); return buffer; } diff --git a/test/test-automation/logger_helpers.h b/test/test-automation/logger_helpers.h index a50fe89d4..f1f2a04d0 100644 --- a/test/test-automation/logger_helpers.h +++ b/test/test-automation/logger_helpers.h @@ -5,7 +5,7 @@ char *IntToString(const int integer); -char *IntToHexString(const int integer); +char *IntToHexString(const Uint64 integer); char *DoubleToString(const double decimal); diff --git a/test/test-automation/plain_logger.c b/test/test-automation/plain_logger.c index 2b43fbf7f..2e51dfaf6 100644 --- a/test/test-automation/plain_logger.c +++ b/test/test-automation/plain_logger.c @@ -119,9 +119,9 @@ PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, void PlainTestStarted(const char *testName, const char *suiteName, - const char *testDescription, int execKey, time_t startTime) + const char *testDescription, Uint64 execKey, time_t startTime) { - Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey); + Output(indentLevel++, "Executing test: %s (in %s). Exec key: %llX", testName, suiteName, execKey); } void diff --git a/test/test-automation/plain_logger.h b/test/test-automation/plain_logger.h index a685a81b3..52fe02eda 100644 --- a/test/test-automation/plain_logger.h +++ b/test/test-automation/plain_logger.h @@ -2,6 +2,8 @@ #define _PLAIN_LOGGER_H #include "logger.h" +#include + /*! * Prints out information about starting the test run. @@ -60,7 +62,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, int execKey, time_t startTime); + const char *testDescription, Uint64 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 e7a510fd9..5e6ea7869 100644 --- a/test/test-automation/runner.c +++ b/test/test-automation/runner.c @@ -43,7 +43,7 @@ //!< Function pointer to a test case function typedef void (*TestCaseFp)(void *arg); //!< Function pointer to a test case init function -typedef void (*InitTestInvironmentFp)(void); +typedef void (*InitTestInvironmentFp)(Uint64); //!< Function pointer to a test case quit function typedef int (*QuitTestInvironmentFp)(void); //!< Function pointer to a test case set up function @@ -115,11 +115,8 @@ const char *defaultXSLStylesheet = "style.xsl"; //! Fuzzer seed for the harness char *runSeed = NULL; -//! Variable is used to pass the generated execution key to a test -int globalExecKey = 0; - //! Execution key that user supplied via command options -int userExecKey = 0; +Uint64 userExecKey = 0; //! How man time a test will be invocated int testInvocationCount = 1; @@ -762,7 +759,7 @@ CheckTestRequirements(TestCase *testCase) * \param test result */ int -RunTest(TestCase *testCase, int execKey) +RunTest(TestCase *testCase, Uint64 execKey) { if(!testCase) { return -1; @@ -782,7 +779,7 @@ RunTest(TestCase *testCase, int execKey) } } - testCase->initTestEnvironment(); + testCase->initTestEnvironment(execKey); if(testCase->testSetUp) { testCase->testSetUp(0x0); @@ -811,7 +808,7 @@ RunTest(TestCase *testCase, int execKey) * \return The return value of the test. Zero means success, non-zero failure. */ int -ExecuteTest(TestCase *testItem, int execKey) { +ExecuteTest(TestCase *testItem, Uint64 execKey) { int retVal = -1; if(execute_inproc) { @@ -1388,19 +1385,20 @@ main(int argc, char *argv[]) int currentIteration = testInvocationCount; while(currentIteration > 0) { - if(userExecKey != NULL) { - globalExecKey = userExecKey; + Uint64 execKey = 5; + if(userExecKey != 0) { + execKey = userExecKey; } else { - globalExecKey = GenerateExecKey(runSeed, testItem->suiteName, + execKey = GenerateExecKey(runSeed, testItem->suiteName, testItem->testName, currentIteration); } TestStarted(testItem->testName, testItem->suiteName, - testItem->description, globalExecKey, time(0)); + testItem->description, execKey, time(0)); const Uint32 testTimeStart = SDL_GetTicks(); - int retVal = ExecuteTest(testItem, globalExecKey); + int retVal = ExecuteTest(testItem, execKey); const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f; diff --git a/test/test-automation/xml_logger.c b/test/test-automation/xml_logger.c index 62986e905..e13c7d226 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, int execKey, time_t startTime) + const char *testDescription, Uint64 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 ec2c67be4..f2f1a76dd 100644 --- a/test/test-automation/xml_logger.h +++ b/test/test-automation/xml_logger.h @@ -1,6 +1,8 @@ #ifndef _XML_LOGGER_H #define _XML_LOGGER_H +#include + #include "logger.h" /*! @@ -59,7 +61,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, int execKey, time_t startTime); + const char *testDescription, Uint64 execKey, time_t startTime); /*! * Prints information about the test test that was just executed in XML