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

Commit

Permalink
Fixed an issue with fuzzing seeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jul 28, 2011
1 parent 8ed21cd commit 760d708
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/test-automation/build-scripts/install-tests.sh
Expand Up @@ -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."
27 changes: 12 additions & 15 deletions test/test-automation/fuzzer/fuzzer.c
Expand Up @@ -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];
Expand All @@ -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);

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test-automation/fuzzer/fuzzer.h
Expand Up @@ -29,7 +29,7 @@
/*!
* Inits the fuzzer for a test
*/
void InitFuzzer(char *execKey);
void InitFuzzer(int execKey);


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

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/plain_logger.c
Expand Up @@ -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);
}
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, char *execKey, time_t startTime);
const char *testDescription, int execKey, time_t startTime);

/*!
* Prints information about the test test that was just executed
Expand Down
14 changes: 8 additions & 6 deletions test/test-automation/runner.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/xml_logger.c
Expand Up @@ -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);
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, 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
Expand Down

0 comments on commit 760d708

Please sign in to comment.