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

Commit

Permalink
Added random number generators for Uint8, Sint8, Uint16, Sint16,
Browse files Browse the repository at this point in the history
Uint64 and Sint64.
  • Loading branch information
mkauppila committed Aug 11, 2011
1 parent 5c0b15b commit 24ce23c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
63 changes: 62 additions & 1 deletion test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
Expand Up @@ -26,6 +26,9 @@

#include "fuzzer.h"

/*!
* Note: doxygen documentation markup is in the header file.
*/

//! context for test-specific random number generator
static RND_CTX rndContext;
Expand Down Expand Up @@ -105,6 +108,30 @@ DeinitFuzzer()

}

Uint8
RandomUint8()
{
return (Uint8) utl_randomInt(&rndContext) & 0x000000FF;
}

Sint8
RandomSint8()
{
return (Sint8) utl_randomInt(&rndContext) & 0x000000FF;
}

Uint16
RandomUint16()
{
return (Uint16) utl_randomInt(&rndContext) & 0x0000FFFF;
}

Sint16
RandomSint16()
{
return (Sint16) utl_randomInt(&rndContext) & 0x0000FFFF;
}

Sint32
RandomInteger()
{
Expand All @@ -117,6 +144,36 @@ RandomPositiveInteger()
return (Uint32) utl_randomInt(&rndContext);
}

Uint64
RandomUint64()
{
Uint8 string[16];

int counter = 0;
for( ; counter < 16; ++counter) {
string[counter] = (Uint8) RandomIntegerInRange(0, 255);
}

Uint64 *value = (Uint64 *)string;
return value[0];
}

Sint64
RandomSint64()
{
Uint8 string[16];

int counter = 0;
for( ; counter < 16; ++counter) {
string[counter] = (Uint8) RandomIntegerInRange(0, 255);
}

Sint64 *value = (Sint64 *)string;
return value[0];
}



Sint32
RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
{
Expand Down Expand Up @@ -507,6 +564,10 @@ RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDoma
return retVal;
}

float RandomFloat() {
return (float) utl_randomInt(&rndContext) / UINT_MAX;
}

char *
RandomAsciiString()
{
Expand All @@ -521,7 +582,7 @@ RandomAsciiStringWithMaximumLength(int maxSize)
}

int size = (abs(RandomInteger()) % (maxSize + 1)) + 1;
char *string = SDL_malloc(size * sizeof(size));
char *string = SDL_malloc(size * sizeof(char));

int counter = 0;
for( ; counter < size; ++counter) {
Expand Down
49 changes: 49 additions & 0 deletions test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
Expand Up @@ -40,6 +40,36 @@ void InitFuzzer(Uint64 execKey);
void DeinitFuzzer();


/*!
* Returns a random Uint8
*
* \returns Generated integer
*/
Uint8 RandomUint8();

/*!
* Returns a random Sint8
*
* \returns Generated signed integer
*/
Sint8 RandomSint8();


/*!
* Returns a random Uint16
*
* \returns Generated integer
*/
Uint16 RandomUint16();

/*!
* Returns a random Sint16
*
* \returns Generated signed integer
*/
Sint16 RandomSint16();


/*!
* Returns a random integer
*
Expand All @@ -55,6 +85,25 @@ Sint32 RandomInteger();
*/
Uint32 RandomPositiveInteger();

/*!
* Returns random Uint64.
*
* \returns Generated integer
*/
Uint64 RandomUint64();


/*!
* Returns random Sint64.
*
* \returns Generated signed integer
*/
Sint64 RandomSint64();

/*!
* Returns random float in range [0.0 - 1.0] (inclusive)
*/
float RandomFloat();

/*!
* Returns a random boundary value for Uint8 within the given boundaries.
Expand Down
2 changes: 2 additions & 0 deletions test/test-automation/tests/testdummy/testdummy.c
Expand Up @@ -100,6 +100,8 @@ dummycase1(void *arg)

//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));

for(; 01 ; )
printf("%d\n", RandomSint16());

for( ; 0 ; ) {
//Log(0, "sint8: %d", RandomSint8BoundaryValue(-11, 10, SDL_TRUE));
Expand Down

0 comments on commit 24ce23c

Please sign in to comment.