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

Commit

Permalink
Fixing execution key generation based on CR.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Aug 2, 2011
1 parent cdafcf8 commit 9cf79d1
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 59 deletions.
9 changes: 4 additions & 5 deletions test/test-automation/SDL_test.c
Expand Up @@ -22,6 +22,8 @@
#include <stdarg.h> /* va_list */
#include <time.h>

#include <SDL/SDL_stdinc.h>

#include "logger.h"
#include "fuzzer/fuzzer.h"

Expand All @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions test/test-automation/SDL_test.h
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
70 changes: 49 additions & 21 deletions test/test-automation/fuzzer/fuzzer.c
@@ -1,4 +1,7 @@

#include <stdio.h>
#include <stdlib.h>

#include "../SDL_test.h"

#include "fuzzer.h"
Expand All @@ -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;
}

if(testName == NULL) {
fprintf(stderr, "Error: Incorrect testName given to GenerateExecKey function\n");
return -1;
}

snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber);
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);
Expand All @@ -48,21 +65,32 @@ GenerateExecKey(char *runSeed, char *suiteName,

SDL_free(buffer);

char *execKey = md5Context.digest;
const char *execKey = md5Context.digest;

//printf("Debug: digest = %s\n", execKey);

//! \todo could this be enhanced?
int key = execKey[4] << 24 |
execKey[9] << 16 |
execKey[13] << 8 |
execKey[3] << 0;
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 abs(key);
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
Expand Down
6 changes: 4 additions & 2 deletions test/test-automation/fuzzer/fuzzer.h
Expand Up @@ -21,6 +21,8 @@
#ifndef _FUZZER_H
#define _FUZZER_H

#include <SDL/SDL_stdinc.h>

#include "utl_crc32.h"
#include "utl_md5.h"
#include "utl_random.h"
Expand All @@ -29,7 +31,7 @@
/*!
* Inits the fuzzer for a test
*/
void InitFuzzer(int execKey);
void InitFuzzer(Uint64 execKey);


/*!
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/test-automation/logger.h
Expand Up @@ -21,6 +21,8 @@
#ifndef _LOGGER_H
#define _LOGGER_H

#include <SDL/SDL_stdinc.h>

#include <time.h>

/* Logging levels */
Expand Down Expand Up @@ -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);

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

Expand Down
4 changes: 2 additions & 2 deletions test/test-automation/logger_helpers.c
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/logger_helpers.h
Expand Up @@ -5,7 +5,7 @@

char *IntToString(const int integer);

char *IntToHexString(const int integer);
char *IntToHexString(const Uint64 integer);

char *DoubleToString(const double decimal);

Expand Down
4 changes: 2 additions & 2 deletions test/test-automation/plain_logger.c
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/test-automation/plain_logger.h
Expand Up @@ -2,6 +2,8 @@
#define _PLAIN_LOGGER_H

#include "logger.h"
#include <SDL/SDL_stdinc.h>


/*!
* Prints out information about starting the test run.
Expand Down Expand Up @@ -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
Expand Down
24 changes: 11 additions & 13 deletions test/test-automation/runner.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -782,7 +779,7 @@ RunTest(TestCase *testCase, int execKey)
}
}

testCase->initTestEnvironment();
testCase->initTestEnvironment(execKey);

if(testCase->testSetUp) {
testCase->testSetUp(0x0);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

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, int execKey, time_t startTime)
const char *testDescription, Uint64 execKey, time_t startTime)
{
char * output = XMLOpenElement(testElementName);
XMLOutputter(indentLevel++, YES, output);
Expand Down
4 changes: 3 additions & 1 deletion test/test-automation/xml_logger.h
@@ -1,6 +1,8 @@
#ifndef _XML_LOGGER_H
#define _XML_LOGGER_H

#include <SDL/SDL_stdinc.h>

#include "logger.h"

/*!
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9cf79d1

Please sign in to comment.