Refining boundary value generator.
This commit is contained in:
parent
c2b70264ed
commit
e45c8d7526
3 changed files with 151 additions and 43 deletions
|
@ -35,6 +35,7 @@ GenerateExecKey(char *runSeed, char *suiteName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Change to itoa
|
||||||
char iterationString[16];
|
char iterationString[16];
|
||||||
memset(iterationString, 0, sizeof(iterationString));
|
memset(iterationString, 0, sizeof(iterationString));
|
||||||
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iterationNumber);
|
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iterationNumber);
|
||||||
|
@ -69,14 +70,15 @@ GenerateExecKey(char *runSeed, char *suiteName,
|
||||||
|
|
||||||
//printf("Debug: digest = %s\n", execKey);
|
//printf("Debug: digest = %s\n", execKey);
|
||||||
|
|
||||||
Uint64 key = execKey[8] << 56 |
|
// Casting fixes compiler warnings
|
||||||
execKey[9] << 48 |
|
Uint64 key = ((Uint64) execKey[8]) << 56 |
|
||||||
execKey[10] << 40 |
|
((Uint64) execKey[9]) << 48 |
|
||||||
execKey[11] << 32 |
|
((Uint64) execKey[10]) << 40 |
|
||||||
execKey[12] << 24 |
|
((Uint64) execKey[11]) << 32 |
|
||||||
execKey[13] << 16 |
|
((Uint64) execKey[12]) << 24 |
|
||||||
execKey[14] << 8 |
|
((Uint64) execKey[13]) << 16 |
|
||||||
execKey[15] << 0;
|
((Uint64) execKey[14]) << 8 |
|
||||||
|
((Uint64) execKey[15]) << 0;
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
@ -99,54 +101,150 @@ DeinitFuzzer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Sint32
|
||||||
RandomInteger()
|
RandomInteger()
|
||||||
{
|
{
|
||||||
return utl_randomInt(&rndContext);
|
return utl_randomInt(&rndContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Uint32
|
||||||
RandomPositiveInteger()
|
RandomPositiveInteger()
|
||||||
{
|
{
|
||||||
return abs(utl_randomInt(&rndContext));
|
return utl_randomInt(&rndContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Sint32
|
||||||
RandomIntegerInRange(int min, int max)
|
RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
|
||||||
{
|
{
|
||||||
if(min > max || (min - max) == 0) {
|
Sint64 min = (Sint64) pMin, max = (Sint64) pMax;
|
||||||
return -1; // Doesn't really make sense to return -1 on error?
|
|
||||||
|
if(min > max) {
|
||||||
|
Sint64 temp = min;
|
||||||
|
min = max;
|
||||||
|
max = temp;
|
||||||
|
} else if(min == max) {
|
||||||
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
int number = utl_randomInt(&rndContext);
|
Sint32 number = abs(utl_randomInt(&rndContext));
|
||||||
number = abs(number);
|
|
||||||
|
|
||||||
return (number % ((max + 1) - min)) + min;
|
return (number % ((max + 1) - min)) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/*!
|
||||||
GenerateBoundaryValueForSize(const int size)
|
* Generates boundary values between the given boundaries.
|
||||||
|
* Boundary values are inclusive. See the examples below.
|
||||||
|
* If boundary2 < boundary1, the values are swapped.
|
||||||
|
* If boundary1 == boundary2, value of boundary1 will be returned
|
||||||
|
*
|
||||||
|
* Generating boundary values for Uint8
|
||||||
|
* BoundaryValues(sizeof(Uint8), 10, 20, True) -> [10,11,19,20]
|
||||||
|
* BoundaryValues(sizeof(Uint8), 10, 20, False) -> [9,21]
|
||||||
|
* BoundaryValues(sizeof(Uint8), 0, 15, True) -> [0, 1, 14, 15]
|
||||||
|
* BoundaryValues(sizeof(Uint8), 0, 15, False) -> [16]
|
||||||
|
* BoundaryValues(sizeof(Uint8), 0, 255, False) -> []
|
||||||
|
*
|
||||||
|
* \param maxValue The biggest value that is acceptable for this data type.
|
||||||
|
* For instance, for Uint8 -> 255, Uint16 -> 65536 etc.
|
||||||
|
* \param pBoundary1 defines lower boundary
|
||||||
|
* \param pBoundary2 defines upper boundary
|
||||||
|
* \param validDomain Generate only for valid domain (for the data type)
|
||||||
|
*
|
||||||
|
* \param outBuffer The generated boundary values are put here
|
||||||
|
* \param outBufferSize Size of outBuffer
|
||||||
|
*
|
||||||
|
* \returns NULL on error, outBuffer on success
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Uint64 *
|
||||||
|
GenerateUnsignedBoundaryValues(const Uint64 maxValue,
|
||||||
|
Uint64 pBoundary1, Uint64 pBoundary2, SDL_bool validDomain,
|
||||||
|
Uint64 *outBuffer, Uint32 *outBufferSize)
|
||||||
{
|
{
|
||||||
if(size < 0) {
|
Uint64 boundary1 = pBoundary1, boundary2 = pBoundary2;
|
||||||
return -1;
|
|
||||||
|
if(outBuffer != NULL) {
|
||||||
|
SDL_free(outBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int adjustment = RandomIntegerInRange(-1, 1);
|
if(boundary1 > boundary2) {
|
||||||
int retValue = (1 << (RandomPositiveInteger() % size)) + adjustment;
|
Uint64 temp = boundary1;
|
||||||
|
boundary1 = boundary2;
|
||||||
|
boundary2 = temp;
|
||||||
|
}
|
||||||
|
|
||||||
return retValue;
|
Uint64 tempBuf[8];
|
||||||
|
memset(tempBuf, 0, 8 * sizeof(Uint64));
|
||||||
|
|
||||||
|
Uint64 index = 0;
|
||||||
|
|
||||||
|
if(boundary1 == boundary2) {
|
||||||
|
tempBuf[index++] = boundary1;
|
||||||
|
}
|
||||||
|
else if(validDomain) {
|
||||||
|
tempBuf[index++] = boundary1;
|
||||||
|
tempBuf[index++] = boundary1 + 1;
|
||||||
|
|
||||||
|
tempBuf[index++] = boundary2 - 1;
|
||||||
|
tempBuf[index++] = boundary2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(boundary1 != 0) {
|
||||||
|
tempBuf[index++] = boundary1 - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(boundary2 != maxValue) {
|
||||||
|
tempBuf[index++] = boundary2 + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(index == 0) {
|
||||||
|
// There are no valid boundaries
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the return buffer
|
||||||
|
outBuffer = SDL_malloc(index * sizeof(Uint64));
|
||||||
|
if(outBuffer == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_memcpy(outBuffer, tempBuf, index * sizeof(Uint64));
|
||||||
|
|
||||||
|
*outBufferSize = index;
|
||||||
|
|
||||||
|
return outBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Uint8
|
||||||
RandomUint8BoundaryValue()
|
RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain)
|
||||||
{
|
{
|
||||||
return GenerateBoundaryValueForSize(8);
|
Uint64 *buffer = NULL;
|
||||||
|
Uint32 size;
|
||||||
|
|
||||||
|
// max value for Uint8
|
||||||
|
const Uint64 maxValue = 255;
|
||||||
|
|
||||||
|
buffer = GenerateUnsignedBoundaryValues(maxValue,
|
||||||
|
(Uint64) boundary1, (Uint64) boundary2,
|
||||||
|
validDomain, buffer, &size);
|
||||||
|
if(buffer == NULL) {
|
||||||
|
return 0; // Change to some better error value? What would be better?
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint32 index = RandomInteger() % size;
|
||||||
|
Uint8 retVal = (Uint8) buffer[index];
|
||||||
|
|
||||||
|
SDL_free(buffer);
|
||||||
|
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
RandomInt8BoundaryValue()
|
Sint8
|
||||||
|
RandomSint8BoundaryValue()
|
||||||
{
|
{
|
||||||
int value = GenerateBoundaryValueForSize(8);
|
int value = 0; //GenerateBoundaryValueForSize(8);
|
||||||
|
|
||||||
return (RandomPositiveInteger() % 2 == 0 ? value : -value);
|
return (RandomPositiveInteger() % 2 == 0 ? value : -value);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +262,7 @@ RandomAsciiStringWithMaximumLength(int maxSize)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -45,7 +45,7 @@ void DeinitFuzzer();
|
||||||
*
|
*
|
||||||
* \returns Generated integer
|
* \returns Generated integer
|
||||||
*/
|
*/
|
||||||
int RandomInteger();
|
Sint32 RandomInteger();
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -53,29 +53,30 @@ int RandomInteger();
|
||||||
*
|
*
|
||||||
* \returns Generated integer
|
* \returns Generated integer
|
||||||
*/
|
*/
|
||||||
int RandomPositiveInteger();
|
Uint32 RandomPositiveInteger();
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* todo add markup
|
* todo add markup
|
||||||
*/
|
*/
|
||||||
int RandomUint8BoundaryValue();
|
Uint8 RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* todo add markup
|
* todo add markup
|
||||||
*/
|
*/
|
||||||
int RandomInt8BoundaryValue();
|
Sint8 RandomSint8BoundaryValue();
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns integer in range [min, max]. Min and max
|
* Returns integer in range [min, max] (inclusive).
|
||||||
* value can be negative values as long as min is smaller than max.
|
* Min and max values can be negative values.
|
||||||
* Min and max also can't be the same value.
|
* If Max in smaller tham min, then the values are swapped.
|
||||||
|
* Min and max are the same value, that value will be returned.
|
||||||
*
|
*
|
||||||
* \returns Generated integer or ? in error
|
* \returns Generated integer
|
||||||
*/
|
*/
|
||||||
int RandomIntegerInRange(int min, int max);
|
Sint32 RandomIntegerInRange(Sint32 min, Sint32 max);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -117,4 +118,5 @@ char *RandomAsciiStringWithMaximumLength(int maxLength);
|
||||||
*/
|
*/
|
||||||
Uint64 GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
|
Uint64 GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -91,10 +91,18 @@ dummycase1(void *arg)
|
||||||
{
|
{
|
||||||
AssertEquals(5, 5, "Assert message");
|
AssertEquals(5, 5, "Assert message");
|
||||||
|
|
||||||
for(; 0 ;) {
|
/*
|
||||||
Log(0, "uint8: %d", RandomUint8BoundaryValue());
|
for( ; 1 ; )
|
||||||
Log(0, "int8: %d", RandomInt8BoundaryValue());
|
Log(0, "uint8 (same value): %u", RandomPositiveInteger());
|
||||||
|
// */
|
||||||
|
|
||||||
|
|
||||||
|
//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));
|
||||||
|
|
||||||
|
|
||||||
|
for(; 1 ;) {
|
||||||
|
Log(0, "uint8: %u", RandomUint8BoundaryValue(10, 20, SDL_FALSE));
|
||||||
|
//Log(0, "int8: %d", RandomInt8BoundaryValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; 0 ;) {
|
for(; 0 ;) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue