Fixing execution key generation based on CR.
This commit is contained in:
parent
1633238f90
commit
c2b70264ed
12 changed files with 86 additions and 59 deletions
|
@ -22,6 +22,8 @@
|
||||||
#include <stdarg.h> /* va_list */
|
#include <stdarg.h> /* va_list */
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <SDL/SDL_stdinc.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "fuzzer/fuzzer.h"
|
#include "fuzzer/fuzzer.h"
|
||||||
|
|
||||||
|
@ -37,12 +39,9 @@ int _testAssertsFailed;
|
||||||
int _testAssertsPassed;
|
int _testAssertsPassed;
|
||||||
|
|
||||||
void
|
void
|
||||||
_InitTestEnvironment(char *execKey)
|
_InitTestEnvironment(Uint64 execKey)
|
||||||
{
|
{
|
||||||
// The execKey gets corrupted while passing arguments
|
InitFuzzer(execKey);
|
||||||
// hence the global variable to circumvent the problem
|
|
||||||
InitFuzzer(globalExecKey);
|
|
||||||
|
|
||||||
|
|
||||||
_testReturnValue = TEST_RESULT_PASS;
|
_testReturnValue = TEST_RESULT_PASS;
|
||||||
_testAssertsFailed = 0;
|
_testAssertsFailed = 0;
|
||||||
|
|
|
@ -28,12 +28,6 @@
|
||||||
|
|
||||||
#include "fuzzer/fuzzer.h"
|
#include "fuzzer/fuzzer.h"
|
||||||
|
|
||||||
/*
|
|
||||||
extern int _testReturnValue;
|
|
||||||
extern int _testAssertsFailed;
|
|
||||||
extern int _testAssertsPassed;
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define TEST_ENABLED 1
|
#define TEST_ENABLED 1
|
||||||
#define TEST_DISABLED 0
|
#define TEST_DISABLED 0
|
||||||
|
|
||||||
|
@ -71,8 +65,10 @@ 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.
|
||||||
|
*
|
||||||
|
* \param execKey Execution key for the test
|
||||||
*/
|
*/
|
||||||
void _InitTestEnvironment(char *execKey);
|
void _InitTestEnvironment(Uint64 execKey);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Deinitializes the test environment and
|
* Deinitializes the test environment and
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "../SDL_test.h"
|
#include "../SDL_test.h"
|
||||||
|
|
||||||
#include "fuzzer.h"
|
#include "fuzzer.h"
|
||||||
|
@ -7,29 +10,43 @@
|
||||||
//! context for test-specific random number generator
|
//! context for test-specific random number generator
|
||||||
static RND_CTX rndContext;
|
static RND_CTX rndContext;
|
||||||
|
|
||||||
int
|
Uint64
|
||||||
GenerateExecKey(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) {
|
||||||
testName == NULL || iterationNumber < 0) {
|
fprintf(stderr, "Error: Incorrect runSeed given to GenerateExecKey function\n");
|
||||||
fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char iterationString[256];
|
if(suiteName == NULL) {
|
||||||
memset(iterationString, 0, sizeof(iterationString));
|
fprintf(stderr, "Error: Incorrect suiteName given to GenerateExecKey function\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber);
|
if(testName == NULL) {
|
||||||
|
fprintf(stderr, "Error: Incorrect testName given to GenerateExecKey function\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// combine the parameters
|
||||||
const int runSeedLength = strlen(runSeed);
|
const Uint32 runSeedLength = strlen(runSeed);
|
||||||
const int suiteNameLength = strlen(suiteName);
|
const Uint32 suiteNameLength = strlen(suiteName);
|
||||||
const int testNameLength = strlen(testName);
|
const Uint32 testNameLength = strlen(testName);
|
||||||
const int iterationStringLength = strlen(iterationString);
|
const Uint32 iterationStringLength = strlen(iterationString);
|
||||||
|
|
||||||
// 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 Uint32 entireString = runSeedLength + suiteNameLength +
|
||||||
testNameLength + iterationStringLength + 3 + 1;
|
testNameLength + iterationStringLength + 3 + 1;
|
||||||
|
|
||||||
char *buffer = SDL_malloc(entireString);
|
char *buffer = SDL_malloc(entireString);
|
||||||
|
@ -48,21 +65,32 @@ GenerateExecKey(char *runSeed, char *suiteName,
|
||||||
|
|
||||||
SDL_free(buffer);
|
SDL_free(buffer);
|
||||||
|
|
||||||
char *execKey = md5Context.digest;
|
const char *execKey = md5Context.digest;
|
||||||
|
|
||||||
//! \todo could this be enhanced?
|
//printf("Debug: digest = %s\n", execKey);
|
||||||
int key = execKey[4] << 24 |
|
|
||||||
execKey[9] << 16 |
|
|
||||||
execKey[13] << 8 |
|
|
||||||
execKey[3] << 0;
|
|
||||||
|
|
||||||
return abs(key);
|
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 key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
void
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#ifndef _FUZZER_H
|
#ifndef _FUZZER_H
|
||||||
#define _FUZZER_H
|
#define _FUZZER_H
|
||||||
|
|
||||||
|
#include <SDL/SDL_stdinc.h>
|
||||||
|
|
||||||
#include "utl_crc32.h"
|
#include "utl_crc32.h"
|
||||||
#include "utl_md5.h"
|
#include "utl_md5.h"
|
||||||
#include "utl_random.h"
|
#include "utl_random.h"
|
||||||
|
@ -29,7 +31,7 @@
|
||||||
/*!
|
/*!
|
||||||
* Inits the fuzzer for a test
|
* Inits the fuzzer for a test
|
||||||
*/
|
*/
|
||||||
void InitFuzzer(int execKey);
|
void InitFuzzer(Uint64 execKey);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -113,6 +115,6 @@ char *RandomAsciiStringWithMaximumLength(int maxLength);
|
||||||
* \return Generated execution key as blob of 16 bytes. It needs be deallocated.
|
* \return Generated execution key as blob of 16 bytes. It needs be deallocated.
|
||||||
* On error, returns NULL.
|
* 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
|
#endif
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#ifndef _LOGGER_H
|
#ifndef _LOGGER_H
|
||||||
#define _LOGGER_H
|
#define _LOGGER_H
|
||||||
|
|
||||||
|
#include <SDL/SDL_stdinc.h>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/* Logging levels */
|
/* Logging levels */
|
||||||
|
@ -56,7 +58,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, Uint64 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);
|
||||||
|
|
||||||
|
@ -86,8 +88,6 @@ extern AssertWithValuesFp AssertWithValues;
|
||||||
extern AssertSummaryFp AssertSummary;
|
extern AssertSummaryFp AssertSummary;
|
||||||
extern LogFp Log;
|
extern LogFp Log;
|
||||||
|
|
||||||
//! \todo move these two away from here
|
|
||||||
extern int globalExecKey;
|
|
||||||
//! Run seed for harness
|
//! Run seed for harness
|
||||||
extern char *runSeed;
|
extern char *runSeed;
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ char *IntToString(const int integer) {
|
||||||
* \param integer The converted integer
|
* \param integer The converted integer
|
||||||
* \returns Given integer as string in hex fomat
|
* \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
|
static char buffer[256]; // malloc might work better
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
SDL_snprintf(buffer, sizeof(buffer), "%X", integer);
|
SDL_snprintf(buffer, sizeof(buffer), "%llX", integer);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
char *IntToString(const int integer);
|
char *IntToString(const int integer);
|
||||||
|
|
||||||
char *IntToHexString(const int integer);
|
char *IntToHexString(const Uint64 integer);
|
||||||
|
|
||||||
char *DoubleToString(const double decimal);
|
char *DoubleToString(const double decimal);
|
||||||
|
|
||||||
|
|
|
@ -119,9 +119,9 @@ 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, 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
|
void
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#define _PLAIN_LOGGER_H
|
#define _PLAIN_LOGGER_H
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include <SDL/SDL_stdinc.h>
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Prints out information about starting the test run.
|
* Prints out information about starting the test run.
|
||||||
|
@ -60,7 +62,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, Uint64 execKey, time_t startTime);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Prints information about the test test that was just executed
|
* Prints information about the test test that was just executed
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
//!< Function pointer to a test case function
|
//!< Function pointer to a test case function
|
||||||
typedef void (*TestCaseFp)(void *arg);
|
typedef void (*TestCaseFp)(void *arg);
|
||||||
//!< Function pointer to a test case init function
|
//!< Function pointer to a test case init function
|
||||||
typedef void (*InitTestInvironmentFp)(void);
|
typedef void (*InitTestInvironmentFp)(Uint64);
|
||||||
//!< Function pointer to a test case quit function
|
//!< Function pointer to a test case quit function
|
||||||
typedef int (*QuitTestInvironmentFp)(void);
|
typedef int (*QuitTestInvironmentFp)(void);
|
||||||
//!< Function pointer to a test case set up function
|
//!< Function pointer to a test case set up function
|
||||||
|
@ -115,11 +115,8 @@ const char *defaultXSLStylesheet = "style.xsl";
|
||||||
//! Fuzzer seed for the harness
|
//! Fuzzer seed for the harness
|
||||||
char *runSeed = NULL;
|
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
|
//! Execution key that user supplied via command options
|
||||||
int userExecKey = 0;
|
Uint64 userExecKey = 0;
|
||||||
|
|
||||||
//! How man time a test will be invocated
|
//! How man time a test will be invocated
|
||||||
int testInvocationCount = 1;
|
int testInvocationCount = 1;
|
||||||
|
@ -762,7 +759,7 @@ CheckTestRequirements(TestCase *testCase)
|
||||||
* \param test result
|
* \param test result
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
RunTest(TestCase *testCase, int execKey)
|
RunTest(TestCase *testCase, Uint64 execKey)
|
||||||
{
|
{
|
||||||
if(!testCase) {
|
if(!testCase) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -782,7 +779,7 @@ RunTest(TestCase *testCase, int execKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testCase->initTestEnvironment();
|
testCase->initTestEnvironment(execKey);
|
||||||
|
|
||||||
if(testCase->testSetUp) {
|
if(testCase->testSetUp) {
|
||||||
testCase->testSetUp(0x0);
|
testCase->testSetUp(0x0);
|
||||||
|
@ -811,7 +808,7 @@ RunTest(TestCase *testCase, 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, int execKey) {
|
ExecuteTest(TestCase *testItem, Uint64 execKey) {
|
||||||
int retVal = -1;
|
int retVal = -1;
|
||||||
|
|
||||||
if(execute_inproc) {
|
if(execute_inproc) {
|
||||||
|
@ -1388,19 +1385,20 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
int currentIteration = testInvocationCount;
|
int currentIteration = testInvocationCount;
|
||||||
while(currentIteration > 0) {
|
while(currentIteration > 0) {
|
||||||
if(userExecKey != NULL) {
|
Uint64 execKey = 5;
|
||||||
globalExecKey = userExecKey;
|
if(userExecKey != 0) {
|
||||||
|
execKey = userExecKey;
|
||||||
} else {
|
} else {
|
||||||
globalExecKey = GenerateExecKey(runSeed, testItem->suiteName,
|
execKey = GenerateExecKey(runSeed, testItem->suiteName,
|
||||||
testItem->testName, currentIteration);
|
testItem->testName, currentIteration);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestStarted(testItem->testName, testItem->suiteName,
|
TestStarted(testItem->testName, testItem->suiteName,
|
||||||
testItem->description, globalExecKey, time(0));
|
testItem->description, execKey, time(0));
|
||||||
|
|
||||||
const Uint32 testTimeStart = SDL_GetTicks();
|
const Uint32 testTimeStart = SDL_GetTicks();
|
||||||
|
|
||||||
int retVal = ExecuteTest(testItem, globalExecKey);
|
int retVal = ExecuteTest(testItem, execKey);
|
||||||
|
|
||||||
const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
|
const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,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, Uint64 execKey, time_t startTime)
|
||||||
{
|
{
|
||||||
char * output = XMLOpenElement(testElementName);
|
char * output = XMLOpenElement(testElementName);
|
||||||
XMLOutputter(indentLevel++, YES, output);
|
XMLOutputter(indentLevel++, YES, output);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef _XML_LOGGER_H
|
#ifndef _XML_LOGGER_H
|
||||||
#define _XML_LOGGER_H
|
#define _XML_LOGGER_H
|
||||||
|
|
||||||
|
#include <SDL/SDL_stdinc.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -59,7 +61,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, Uint64 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue