Navigation Menu

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

Commit

Permalink
Added elementary fuzzer-randgen invocation count.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Aug 28, 2011
1 parent 0963c40 commit adadcbc
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 10 deletions.
30 changes: 24 additions & 6 deletions test/test-automation/src/libSDLtest/SDL_test.c
Expand Up @@ -65,6 +65,8 @@ _QuitTestEnvironment()
_testReturnValue = TEST_RESULT_NO_ASSERT;
}

Log(time(0), "Fuzzer invocation count: %d", GetInvocationCount());

DeinitFuzzer();

return _testReturnValue;
Expand All @@ -75,6 +77,25 @@ _CountFailedAsserts() {
return _testAssertsFailed;
}

/*!
* Bail out from test case. For example, function is used to bail out
* after failed assert.
*/
void
_BailOut()
{
if(!canBailOut)
return ;

AssertSummary(_testAssertsFailed + _testAssertsPassed,
_testAssertsFailed, _testAssertsPassed, time(0));

Log(time(0), "Fuzzer invocation count: %d", GetInvocationCount());

DeinitFuzzer();

exit(TEST_RESULT_FAILURE); // bail out from the test
}

void
AssertEquals(int expected, int actual, char *message, ...)
Expand All @@ -93,8 +114,7 @@ AssertEquals(int expected, int actual, char *message, ...)
_testReturnValue = TEST_RESULT_FAILURE;
_testAssertsFailed++;

if(canBailOut)
exit(TEST_RESULT_FAILURE); // bail out from the test
_BailOut();
} else {
AssertWithValues("AssertEquals", 1, buf,
actual, expected, time(0));
Expand All @@ -119,8 +139,7 @@ AssertTrue(int condition, char *message, ...)
_testReturnValue = TEST_RESULT_FAILURE;
_testAssertsFailed++;

if(canBailOut)
exit(TEST_RESULT_FAILURE); // bail out from the test
_BailOut();
} else {
Assert("AssertTrue", 1, buf, time(0));

Expand Down Expand Up @@ -159,7 +178,6 @@ AssertFail(char *message, ...)
_testReturnValue = TEST_RESULT_FAILURE;
_testAssertsFailed++;

if(canBailOut)
exit(TEST_RESULT_FAILURE); // bail out from the test
_BailOut();
}

52 changes: 50 additions & 2 deletions test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
Expand Up @@ -33,6 +33,9 @@
//! context for test-specific random number generator
static RND_CTX rndContext;

//! Counts invocation of fuzzer generator functions
int invocationCounter = 0;

Uint64
GenerateExecKey(char *runSeed, char *suiteName,
char *testName, int iterationNumber)
Expand Down Expand Up @@ -99,45 +102,63 @@ InitFuzzer(Uint64 execKey)
utl_randomInit(&rndContext, a, b);
}

int
GetInvocationCount()
{
return invocationCounter;
}

void
DeinitFuzzer()
{

invocationCounter = 0;
}

Uint8
RandomUint8()
{
invocationCounter++;

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

Sint8
RandomSint8()
{
invocationCounter++;

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

Uint16
RandomUint16()
{
invocationCounter++;

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

Sint16
RandomSint16()
{
invocationCounter++;

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

Sint32
RandomSint32()
{
invocationCounter++;

return (Sint32) utl_randomInt(&rndContext);
}

Uint32
RandomUint32()
{
invocationCounter++;

return (Uint32) utl_randomInt(&rndContext);
}

Expand All @@ -146,6 +167,8 @@ RandomUint64()
{
Uint64 value;

invocationCounter++;

Uint32 *vp = (Uint32*)&value;
vp[0] = RandomSint32();
vp[1] = RandomSint32();
Expand All @@ -158,6 +181,8 @@ RandomSint64()
{
Uint64 value;

invocationCounter++;

Uint32 *vp = (Uint32*)&value;
vp[0] = RandomSint32();
vp[1] = RandomSint32();
Expand All @@ -180,7 +205,7 @@ RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
return min;
}

Sint32 number = RandomSint32();
Sint32 number = RandomSint32(); // invocation count increment in there

return (number % ((max + 1) - min)) + min;
}
Expand Down Expand Up @@ -292,6 +317,8 @@ RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain)

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -316,6 +343,8 @@ RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDoma

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -340,6 +369,8 @@ RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDoma

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -364,6 +395,8 @@ RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDoma

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand Down Expand Up @@ -481,6 +514,8 @@ RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain)

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -506,6 +541,8 @@ RandomSint16BoundaryValue(Sint16 boundary1, Sint16 boundary2, SDL_bool validDoma

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -531,6 +568,8 @@ RandomSint32BoundaryValue(Sint32 boundary1, Sint32 boundary2, SDL_bool validDoma

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -556,6 +595,8 @@ RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDoma

SDL_free(buffer);

invocationCounter++;

return retVal;
}

Expand All @@ -574,13 +615,17 @@ RandomUnitDouble()
float
RandomFloat()
{
invocationCounter++;

// \todo to be implemented
return 0.0f;
}

double
RandomDouble()
{
invocationCounter++;

// \todo to be implemented
return 0.0f;
}
Expand All @@ -589,12 +634,15 @@ RandomDouble()
char *
RandomAsciiString()
{
// note: invocationCounter is increment in the RandomAsciiStringWithMaximumLenght
return RandomAsciiStringWithMaximumLength(255);
}

char *
RandomAsciiStringWithMaximumLength(int maxSize)
{
invocationCounter++;

if(maxSize < 1) {
return NULL;
}
Expand Down
4 changes: 4 additions & 0 deletions test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
Expand Up @@ -353,5 +353,9 @@ char *RandomAsciiStringWithMaximumLength(int maxLength);
*/
Uint64 GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iterationNumber);

/*!
* Returns test specific invocation count for the fuzzer.
*/
int GetInvocationCount();

#endif
5 changes: 3 additions & 2 deletions test/test-automation/tests/testdummy/testdummy.c
Expand Up @@ -103,8 +103,9 @@ test_dummy1(void *arg)

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

for(; 1 ; )
printf("%f\n", RandomUnitFloat());
int c = 0;
//for(; c < 100 ; c++)
printf("%f\n", RandomUnitFloat());

for(; 0 ; )
printf("%d\n", RandomSint16());
Expand Down

0 comments on commit adadcbc

Please sign in to comment.