Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Changing the execution key generator.
Browse files Browse the repository at this point in the history
Fixed --iterations option.
  • Loading branch information
mkauppila committed Jul 25, 2011
1 parent 1d4ab24 commit 426fc75
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 53 deletions.
2 changes: 1 addition & 1 deletion test/test-automation/SDL_test.c
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/SDL_test.h
Expand Up @@ -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
Expand Down
59 changes: 33 additions & 26 deletions test/test-automation/fuzzer/fuzzer.c
Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions test/test-automation/fuzzer/fuzzer.h
Expand Up @@ -29,7 +29,7 @@
/*!
* Inits the fuzzer for a test
*/
void InitFuzzer(const int execKey);
void InitFuzzer(char *execKey);


/*!
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions test/test-automation/logger.h
Expand Up @@ -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);

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/test-automation/plain_logger.c
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/plain_logger.h
Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions test/test-automation/runner.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -1142,6 +1143,9 @@ main(int argc, char *argv[])
TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);

currentIteration--;

SDL_free(globalExecKey);
globalExecKey = NULL;
}
}

Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions test/test-automation/testdummy/testdummy.c
Expand Up @@ -107,7 +107,7 @@ dummycase1(void *arg)
Log(0, "%d", random);
}

//Log(0, "Random: %s", RandomAsciiStringWithMaximumLength(2));
Log(0, "Random: %s", RandomAsciiString());
}

void
Expand All @@ -121,7 +121,7 @@ dummycase2(void *arg)
void
dummycase3(void *arg)
{
while(1);
while(0);
//AssertTrue(1, "Assert message");
}

2 changes: 1 addition & 1 deletion test/test-automation/xml_logger.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/xml_logger.h
Expand Up @@ -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
Expand Down

0 comments on commit 426fc75

Please sign in to comment.