Added elementary fuzzer-randgen invocation count.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Sun, 28 Aug 2011 22:06:56 +0300
changeset 5847 a711145cc9e2
parent 5846 33be0a40bc11
child 5848 7b1f38d183d0
Added elementary fuzzer-randgen invocation count.
test/test-automation/src/libSDLtest/SDL_test.c
test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
test/test-automation/tests/testdummy/testdummy.c
--- a/test/test-automation/src/libSDLtest/SDL_test.c	Sun Aug 28 21:06:00 2011 +0300
+++ b/test/test-automation/src/libSDLtest/SDL_test.c	Sun Aug 28 22:06:56 2011 +0300
@@ -65,6 +65,8 @@
 		_testReturnValue = TEST_RESULT_NO_ASSERT;
 	}
 
+	Log(time(0), "Fuzzer invocation count: %d", GetInvocationCount());
+
 	DeinitFuzzer();
 
 	return _testReturnValue;
@@ -75,6 +77,25 @@
 	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, ...)
@@ -93,8 +114,7 @@
       _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));
@@ -119,8 +139,7 @@
       _testReturnValue = TEST_RESULT_FAILURE;
       _testAssertsFailed++;
 
-      if(canBailOut)
-    	  exit(TEST_RESULT_FAILURE); // bail out from the test
+      _BailOut();
    } else {
 		Assert("AssertTrue", 1, buf, time(0));
 
@@ -159,7 +178,6 @@
    _testReturnValue = TEST_RESULT_FAILURE;
    _testAssertsFailed++;
 
-   if(canBailOut)
-	   exit(TEST_RESULT_FAILURE); // bail out from the test
+   _BailOut();
 }
 
--- a/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c	Sun Aug 28 21:06:00 2011 +0300
+++ b/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c	Sun Aug 28 22:06:56 2011 +0300
@@ -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)
@@ -99,45 +102,63 @@
 	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);
 }
 
@@ -146,6 +167,8 @@
 {
 	Uint64 value;
 
+	invocationCounter++;
+
 	Uint32 *vp = (Uint32*)&value;
 	vp[0] = RandomSint32();
 	vp[1] = RandomSint32();
@@ -158,6 +181,8 @@
 {
 	Uint64 value;
 
+	invocationCounter++;
+
 	Uint32 *vp = (Uint32*)&value;
 	vp[0] = RandomSint32();
 	vp[1] = RandomSint32();
@@ -180,7 +205,7 @@
 		return min;
 	}
 
-	Sint32 number = RandomSint32();
+	Sint32 number = RandomSint32(); // invocation count increment in there
 
 	return (number % ((max + 1) - min)) + min;
 }
@@ -292,6 +317,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -316,6 +343,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -340,6 +369,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -364,6 +395,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -481,6 +514,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -506,6 +541,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -531,6 +568,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -556,6 +595,8 @@
 
 	SDL_free(buffer);
 
+	invocationCounter++;
+
 	return retVal;
 }
 
@@ -574,6 +615,8 @@
 float
 RandomFloat()
 {
+	invocationCounter++;
+
 	// \todo to be implemented
 	return 0.0f;
 }
@@ -581,6 +624,8 @@
 double
 RandomDouble()
 {
+	invocationCounter++;
+
 	// \todo to be implemented
 	return 0.0f;
 }
@@ -589,12 +634,15 @@
 char *
 RandomAsciiString()
 {
+	// note: invocationCounter is increment in the RandomAsciiStringWithMaximumLenght
 	return RandomAsciiStringWithMaximumLength(255);
 }
 
 char *
 RandomAsciiStringWithMaximumLength(int maxSize)
 {
+	invocationCounter++;
+
 	if(maxSize < 1) {
 		return NULL;
 	}
--- a/test/test-automation/src/libSDLtest/fuzzer/fuzzer.h	Sun Aug 28 21:06:00 2011 +0300
+++ b/test/test-automation/src/libSDLtest/fuzzer/fuzzer.h	Sun Aug 28 22:06:56 2011 +0300
@@ -353,5 +353,9 @@
  */
 Uint64 GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iterationNumber);
 
+/*!
+ * Returns test specific invocation count for the fuzzer.
+ */
+int GetInvocationCount();
 
 #endif
--- a/test/test-automation/tests/testdummy/testdummy.c	Sun Aug 28 21:06:00 2011 +0300
+++ b/test/test-automation/tests/testdummy/testdummy.c	Sun Aug 28 22:06:56 2011 +0300
@@ -103,8 +103,9 @@
 
 	//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());