diff --git a/test/test-automation/SDL_test.c b/test/test-automation/SDL_test.c index 89c4a486e..28488bdc5 100644 --- a/test/test-automation/SDL_test.c +++ b/test/test-automation/SDL_test.c @@ -37,7 +37,7 @@ int _testAssertsFailed; int _testAssertsPassed; void -_InitTestEnvironment(const int execKey) +_InitTestEnvironment(char *execKey) { // The execKey gets corrupted while passing arguments // hence the global variable to circumvent the problem diff --git a/test/test-automation/SDL_test.h b/test/test-automation/SDL_test.h index db42dddea..4c8c6cc49 100644 --- a/test/test-automation/SDL_test.h +++ b/test/test-automation/SDL_test.h @@ -69,7 +69,7 @@ typedef struct TestCaseReference { * Initialized the test environment such as asserts. Must be called at * the beginning of every test case, before doing anything else. */ -void _InitTestEnvironment(const int execKey); +void _InitTestEnvironment(char *execKey); /*! * Deinitializes the test environment and diff --git a/test/test-automation/fuzzer/fuzzer.c b/test/test-automation/fuzzer/fuzzer.c index 8ee310108..97a09d8fd 100644 --- a/test/test-automation/fuzzer/fuzzer.c +++ b/test/test-automation/fuzzer/fuzzer.c @@ -5,16 +5,16 @@ //! context for test-specific random number generator -RND_CTX rndContext3; +static RND_CTX rndContext; -int -GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, +char * +GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iterationNumber) { if(runSeed == NULL || suiteName == NULL || testName == NULL || iterationNumber < 0) { - fprintf(stderr, "Incorrect parameter given to GenerateExecKey function\n"); - return -1; + fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n"); + return NULL; } char iterationString[256]; @@ -30,33 +30,41 @@ GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, // size of the entire + 3 for slashes and + 1 for '\0' const int entireString = runSeedLength + suiteNameLength + - testNameLength + iterationString + 3 + 1; + testNameLength + iterationStringLength + 3 + 1; - int result = 0; + char *buffer = SDL_malloc(entireString); + if(!buffer) { + return NULL; + } + + SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName, + testName, iterationNumber); + + //printf("Debug: %s", buffer); - /* Let's take a hash from the strings separately because - * it's really slow to calculate md5 or crc32 for a really long string - * like 'runSeed/testSuiteName/testName/iteration' - */ MD5_CTX md5Context; utl_md5Init(&md5Context); - utl_md5Update(&md5Context, runSeed, runSeedLength); - utl_md5Update(&md5Context, suiteName, suiteNameLength); - utl_md5Update(&md5Context, testName, testNameLength); - utl_md5Update(&md5Context, iterationString, iterationStringLength); - + utl_md5Update(&md5Context, buffer, entireString); utl_md5Final(&md5Context); - utl_crc32Calc(&crcContext, md5Context.digest, sizeof(md5Context.digest), &result); + SDL_free(buffer); - return abs(result); // makes sure that the key is positive + const int keyLength = SDL_strlen(md5Context.digest); + char *key = SDL_malloc(keyLength); + SDL_snprintf(key, keyLength, "%s", md5Context.digest); + + return key; } void -InitFuzzer(const int execKey) +InitFuzzer(char *execKey) { - utl_randomInit(&rndContext3, globalExecKey, globalExecKey / 0xfafafafa); + //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); } void @@ -68,13 +76,13 @@ DeinitFuzzer() int RandomInteger() { - return utl_randomInt(&rndContext3); + return utl_randomInt(&rndContext); } int RandomPositiveInteger() { - return abs(utl_randomInt(&rndContext3)); + return abs(utl_randomInt(&rndContext)); } int @@ -84,7 +92,7 @@ RandomIntegerInRange(int min, int max) return -1; // Doesn't really make sense to return -1 on error? } - int number = utl_randomInt(&rndContext3); + int number = utl_randomInt(&rndContext); number = abs(number); return (number % ((max + 1) - min)) + min; @@ -130,13 +138,12 @@ RandomAsciiStringWithMaximumLength(int maxSize) return NULL; } - const int size = abs(RandomInteger) % maxSize; + int size = abs(RandomInteger) % maxSize; char *string = SDL_malloc(size * sizeof(size)); int counter = 0; for( ; counter < size; ++counter) { - char character = (char) RandomIntegerInRange(1, 127); - string[counter] = character; + string[counter] = (char) RandomIntegerInRange(1, 127); } string[counter] = '\0'; diff --git a/test/test-automation/fuzzer/fuzzer.h b/test/test-automation/fuzzer/fuzzer.h index fc5117b42..6a981dd74 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(const int execKey); +void InitFuzzer(char *execKey); /*! @@ -110,8 +110,9 @@ char *RandomAsciiStringWithMaximumLength(int maxLength); * \param testName Test name * \param iteration Number of test iteration * - * \return Generated execution key + * \return Generated execution key as blob of 16 bytes. It needs be deallocated. + * On error, returns NULL. */ -int GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, char *testName, int interationNumber); +char *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 49780ba32..43546e8a4 100644 --- a/test/test-automation/logger.h +++ b/test/test-automation/logger.h @@ -37,7 +37,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, char *execKey, time_t startTime); typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult, time_t endTime, double totalRuntime); @@ -67,9 +67,10 @@ extern AssertWithValuesFp AssertWithValues; extern AssertSummaryFp AssertSummary; extern LogFp Log; -extern int globalExecKey; +//! \todo move these two away from here +extern char *globalExecKey; //! Run seed for harness -extern const char *runSeed; +extern char *runSeed; #endif diff --git a/test/test-automation/plain_logger.c b/test/test-automation/plain_logger.c index 0b7e71455..d99835009 100644 --- a/test/test-automation/plain_logger.c +++ b/test/test-automation/plain_logger.c @@ -82,7 +82,7 @@ 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, char *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 90c652024..f47af222e 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, int execKey, time_t startTime); + const char *testDescription, char *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 1eecbe03c..a9b856342 100644 --- a/test/test-automation/runner.c +++ b/test/test-automation/runner.c @@ -91,10 +91,10 @@ int universal_timeout = -1; //! Default directory of the test suites #define DEFAULT_TEST_DIRECTORY "tests/" -int globalExecKey = -1; -const char *runSeed = "seed"; +char *globalExecKey = NULL; +char *runSeed = "seed"; -int userExecKey = 0; +char *userExecKey = NULL; //! How man time a test will be invocated int testInvocationCount = 1; @@ -689,7 +689,7 @@ CheckTestRequirements(TestCase *testCase) * \param test result */ int -RunTest(TestCase *testCase, const int execKey) +RunTest(TestCase *testCase, char *execKey) { if(!testCase) { return -1; @@ -738,7 +738,7 @@ RunTest(TestCase *testCase, const int execKey) * \return The return value of the test. Zero means success, non-zero failure. */ int -ExecuteTest(TestCase *testItem, const int execKey) { +ExecuteTest(TestCase *testItem, char *execKey) { int retVal = -1; if(execute_inproc) { @@ -948,6 +948,10 @@ ParseOptions(int argc, char *argv[]) } testInvocationCount = atoi(iterationsString); + if(testInvocationCount < 1) { + printf("Iteration value has to bigger than 0.\n"); + exit(1); + } } else if(SDL_strcmp(arg, "--exec-key") == 0) { char *execKeyString = NULL; @@ -959,7 +963,7 @@ ParseOptions(int argc, char *argv[]) exit(1); } - userExecKey = atoi(execKeyString); + userExecKey = execKeyString; } else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) { only_selected_test = 1; @@ -1047,9 +1051,6 @@ main(int argc, char *argv[]) { ParseOptions(argc, argv); - CRC32_CTX crcContext; - utl_crc32Init(&crcContext); - // print: Testing against SDL version fuu (rev: bar) if verbose == true char *testSuiteName = NULL; @@ -1122,10 +1123,10 @@ main(int argc, char *argv[]) int currentIteration = testInvocationCount; while(currentIteration > 0) { - if(userExecKey != 0) { + if(userExecKey != NULL) { globalExecKey = userExecKey; } else { - const int execKey = GenerateExecKey(crcContext, runSeed, testItem->suiteName, + char *execKey = GenerateExecKey(runSeed, testItem->suiteName, testItem->testName, currentIteration); globalExecKey = execKey; } @@ -1142,6 +1143,9 @@ main(int argc, char *argv[]) TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime); currentIteration--; + + SDL_free(globalExecKey); + globalExecKey = NULL; } } @@ -1162,7 +1166,5 @@ main(int argc, char *argv[]) // Some SDL subsystem might be init'ed so shut them down SDL_Quit(); - utl_crc32Done(&crcContext); - return (totalTestFailureCount ? 1 : 0); } diff --git a/test/test-automation/testdummy/testdummy.c b/test/test-automation/testdummy/testdummy.c index 8fd9afc8c..096dbe216 100644 --- a/test/test-automation/testdummy/testdummy.c +++ b/test/test-automation/testdummy/testdummy.c @@ -107,7 +107,7 @@ dummycase1(void *arg) Log(0, "%d", random); } - //Log(0, "Random: %s", RandomAsciiStringWithMaximumLength(2)); + Log(0, "Random: %s", RandomAsciiString()); } void @@ -121,7 +121,7 @@ dummycase2(void *arg) void dummycase3(void *arg) { - while(1); + while(0); //AssertTrue(1, "Assert message"); } diff --git a/test/test-automation/xml_logger.c b/test/test-automation/xml_logger.c index 47d6f3df6..59b7f365c 100644 --- a/test/test-automation/xml_logger.c +++ b/test/test-automation/xml_logger.c @@ -324,7 +324,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, char *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 faa19f8df..8c56d9fd7 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, int execKey, time_t startTime); + const char *testDescription, char *execKey, time_t startTime); /*! * Prints information about the test test that was just executed in XML