Commit 6132d65f authored by Markus Kauppila's avatar Markus Kauppila

Changing the execution key generator.

Fixed --iterations option.
parent 46f39ab2
...@@ -37,7 +37,7 @@ int _testAssertsFailed; ...@@ -37,7 +37,7 @@ int _testAssertsFailed;
int _testAssertsPassed; int _testAssertsPassed;
void void
_InitTestEnvironment(const int execKey) _InitTestEnvironment(char *execKey)
{ {
// The execKey gets corrupted while passing arguments // The execKey gets corrupted while passing arguments
// hence the global variable to circumvent the problem // hence the global variable to circumvent the problem
......
...@@ -69,7 +69,7 @@ typedef struct TestCaseReference { ...@@ -69,7 +69,7 @@ typedef struct TestCaseReference {
* Initialized the test environment such as asserts. Must be called at * Initialized the test environment such as asserts. Must be called at
* the beginning of every test case, before doing anything else. * the beginning of every test case, before doing anything else.
*/ */
void _InitTestEnvironment(const int execKey); void _InitTestEnvironment(char *execKey);
/*! /*!
* Deinitializes the test environment and * Deinitializes the test environment and
......
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
//! context for test-specific random number generator //! context for test-specific random number generator
RND_CTX rndContext3; static RND_CTX rndContext;
int char *
GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, GenerateExecKey(char *runSeed, char *suiteName,
char *testName, int iterationNumber) char *testName, int iterationNumber)
{ {
if(runSeed == NULL || suiteName == NULL || if(runSeed == NULL || suiteName == NULL ||
testName == NULL || iterationNumber < 0) { testName == NULL || iterationNumber < 0) {
fprintf(stderr, "Incorrect parameter given to GenerateExecKey function\n"); fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
return -1; return NULL;
} }
char iterationString[256]; char iterationString[256];
...@@ -30,33 +30,41 @@ GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, ...@@ -30,33 +30,41 @@ GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName,
// size of the entire + 3 for slashes and + 1 for '\0' // size of the entire + 3 for slashes and + 1 for '\0'
const int entireString = runSeedLength + suiteNameLength + 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; MD5_CTX md5Context;
utl_md5Init(&md5Context); utl_md5Init(&md5Context);
utl_md5Update(&md5Context, runSeed, runSeedLength); utl_md5Update(&md5Context, buffer, entireString);
utl_md5Update(&md5Context, suiteName, suiteNameLength);
utl_md5Update(&md5Context, testName, testNameLength);
utl_md5Update(&md5Context, iterationString, iterationStringLength);
utl_md5Final(&md5Context); 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 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 void
...@@ -68,13 +76,13 @@ DeinitFuzzer() ...@@ -68,13 +76,13 @@ DeinitFuzzer()
int int
RandomInteger() RandomInteger()
{ {
return utl_randomInt(&rndContext3); return utl_randomInt(&rndContext);
} }
int int
RandomPositiveInteger() RandomPositiveInteger()
{ {
return abs(utl_randomInt(&rndContext3)); return abs(utl_randomInt(&rndContext));
} }
int int
...@@ -84,7 +92,7 @@ RandomIntegerInRange(int min, int max) ...@@ -84,7 +92,7 @@ RandomIntegerInRange(int min, int max)
return -1; // Doesn't really make sense to return -1 on error? 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); number = abs(number);
return (number % ((max + 1) - min)) + min; return (number % ((max + 1) - min)) + min;
...@@ -130,13 +138,12 @@ RandomAsciiStringWithMaximumLength(int maxSize) ...@@ -130,13 +138,12 @@ RandomAsciiStringWithMaximumLength(int maxSize)
return NULL; return NULL;
} }
const int size = abs(RandomInteger) % maxSize; int size = abs(RandomInteger) % maxSize;
char *string = SDL_malloc(size * sizeof(size)); char *string = SDL_malloc(size * sizeof(size));
int counter = 0; int counter = 0;
for( ; counter < size; ++counter) { for( ; counter < size; ++counter) {
char character = (char) RandomIntegerInRange(1, 127); string[counter] = (char) RandomIntegerInRange(1, 127);
string[counter] = character;
} }
string[counter] = '\0'; string[counter] = '\0';
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
/*! /*!
* Inits the fuzzer for a test * Inits the fuzzer for a test
*/ */
void InitFuzzer(const int execKey); void InitFuzzer(char *execKey);
/*! /*!
...@@ -110,8 +110,9 @@ char *RandomAsciiStringWithMaximumLength(int maxLength); ...@@ -110,8 +110,9 @@ char *RandomAsciiStringWithMaximumLength(int maxLength);
* \param testName Test name * \param testName Test name
* \param iteration Number of test iteration * \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 #endif
...@@ -37,7 +37,7 @@ typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped, ...@@ -37,7 +37,7 @@ typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped,
time_t endTime, double totalRuntime); time_t endTime, double totalRuntime);
typedef void (*TestStartedFp)(const char *testName, const char *suiteName, 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, typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult,
time_t endTime, double totalRuntime); time_t endTime, double totalRuntime);
...@@ -67,9 +67,10 @@ extern AssertWithValuesFp AssertWithValues; ...@@ -67,9 +67,10 @@ extern AssertWithValuesFp AssertWithValues;
extern AssertSummaryFp AssertSummary; extern AssertSummaryFp AssertSummary;
extern LogFp Log; extern LogFp Log;
extern int globalExecKey; //! \todo move these two away from here
extern char *globalExecKey;
//! Run seed for harness //! Run seed for harness
extern const char *runSeed; extern char *runSeed;
#endif #endif
...@@ -82,7 +82,7 @@ PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, ...@@ -82,7 +82,7 @@ PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
void void
PlainTestStarted(const char *testName, const char *suiteName, 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); Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
} }
......
...@@ -60,7 +60,7 @@ void PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, ...@@ -60,7 +60,7 @@ void PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
* \param startTime When the test started to execute * \param startTime When the test started to execute
*/ */
void PlainTestStarted(const char *testName, const char *suiteName, 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 * Prints information about the test test that was just executed
......
...@@ -91,10 +91,10 @@ int universal_timeout = -1; ...@@ -91,10 +91,10 @@ int universal_timeout = -1;
//! Default directory of the test suites //! Default directory of the test suites
#define DEFAULT_TEST_DIRECTORY "tests/" #define DEFAULT_TEST_DIRECTORY "tests/"
int globalExecKey = -1; char *globalExecKey = NULL;
const char *runSeed = "seed"; char *runSeed = "seed";
int userExecKey = 0; char *userExecKey = NULL;
//! How man time a test will be invocated //! How man time a test will be invocated
int testInvocationCount = 1; int testInvocationCount = 1;
...@@ -689,7 +689,7 @@ CheckTestRequirements(TestCase *testCase) ...@@ -689,7 +689,7 @@ CheckTestRequirements(TestCase *testCase)
* \param test result * \param test result
*/ */
int int
RunTest(TestCase *testCase, const int execKey) RunTest(TestCase *testCase, char *execKey)
{ {
if(!testCase) { if(!testCase) {
return -1; return -1;
...@@ -738,7 +738,7 @@ RunTest(TestCase *testCase, const int execKey) ...@@ -738,7 +738,7 @@ RunTest(TestCase *testCase, const int execKey)
* \return The return value of the test. Zero means success, non-zero failure. * \return The return value of the test. Zero means success, non-zero failure.
*/ */
int int
ExecuteTest(TestCase *testItem, const int execKey) { ExecuteTest(TestCase *testItem, char *execKey) {
int retVal = -1; int retVal = -1;
if(execute_inproc) { if(execute_inproc) {
...@@ -948,6 +948,10 @@ ParseOptions(int argc, char *argv[]) ...@@ -948,6 +948,10 @@ ParseOptions(int argc, char *argv[])
} }
testInvocationCount = atoi(iterationsString); 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) { else if(SDL_strcmp(arg, "--exec-key") == 0) {
char *execKeyString = NULL; char *execKeyString = NULL;
...@@ -959,7 +963,7 @@ ParseOptions(int argc, char *argv[]) ...@@ -959,7 +963,7 @@ ParseOptions(int argc, char *argv[])
exit(1); exit(1);
} }
userExecKey = atoi(execKeyString); userExecKey = execKeyString;
} }
else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) { else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
only_selected_test = 1; only_selected_test = 1;
...@@ -1047,9 +1051,6 @@ main(int argc, char *argv[]) ...@@ -1047,9 +1051,6 @@ main(int argc, char *argv[])
{ {
ParseOptions(argc, argv); ParseOptions(argc, argv);
CRC32_CTX crcContext;
utl_crc32Init(&crcContext);
// print: Testing against SDL version fuu (rev: bar) if verbose == true // print: Testing against SDL version fuu (rev: bar) if verbose == true
char *testSuiteName = NULL; char *testSuiteName = NULL;
...@@ -1122,10 +1123,10 @@ main(int argc, char *argv[]) ...@@ -1122,10 +1123,10 @@ main(int argc, char *argv[])
int currentIteration = testInvocationCount; int currentIteration = testInvocationCount;
while(currentIteration > 0) { while(currentIteration > 0) {
if(userExecKey != 0) { if(userExecKey != NULL) {
globalExecKey = userExecKey; globalExecKey = userExecKey;
} else { } else {
const int execKey = GenerateExecKey(crcContext, runSeed, testItem->suiteName, char *execKey = GenerateExecKey(runSeed, testItem->suiteName,
testItem->testName, currentIteration); testItem->testName, currentIteration);
globalExecKey = execKey; globalExecKey = execKey;
} }
...@@ -1142,6 +1143,9 @@ main(int argc, char *argv[]) ...@@ -1142,6 +1143,9 @@ main(int argc, char *argv[])
TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime); TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
currentIteration--; currentIteration--;
SDL_free(globalExecKey);
globalExecKey = NULL;
} }
} }
...@@ -1162,7 +1166,5 @@ main(int argc, char *argv[]) ...@@ -1162,7 +1166,5 @@ main(int argc, char *argv[])
// Some SDL subsystem might be init'ed so shut them down // Some SDL subsystem might be init'ed so shut them down
SDL_Quit(); SDL_Quit();
utl_crc32Done(&crcContext);
return (totalTestFailureCount ? 1 : 0); return (totalTestFailureCount ? 1 : 0);
} }
...@@ -107,7 +107,7 @@ dummycase1(void *arg) ...@@ -107,7 +107,7 @@ dummycase1(void *arg)
Log(0, "%d", random); Log(0, "%d", random);
} }
//Log(0, "Random: %s", RandomAsciiStringWithMaximumLength(2)); Log(0, "Random: %s", RandomAsciiString());
} }
void void
...@@ -121,7 +121,7 @@ dummycase2(void *arg) ...@@ -121,7 +121,7 @@ dummycase2(void *arg)
void void
dummycase3(void *arg) dummycase3(void *arg)
{ {
while(1); while(0);
//AssertTrue(1, "Assert message"); //AssertTrue(1, "Assert message");
} }
...@@ -324,7 +324,7 @@ XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, ...@@ -324,7 +324,7 @@ XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
void void
XMLTestStarted(const char *testName, const char *suiteName, 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); char * output = XMLOpenElement(testElementName);
XMLOutputter(indentLevel++, YES, output); XMLOutputter(indentLevel++, YES, output);
......
...@@ -59,7 +59,7 @@ void XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, ...@@ -59,7 +59,7 @@ void XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
* \param startTime When the test started to execute * \param startTime When the test started to execute
*/ */
void XMLTestStarted(const char *testName, const char *suiteName, 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 * Prints information about the test test that was just executed in XML
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment