Changing the execution key generator.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Mon, 25 Jul 2011 20:32:31 +0300
changeset 5784 676f4613ee14
parent 5783 236ed35e4b34
child 5785 7fc252ce5d1d
Changing the execution key generator. Fixed --iterations option.
test/test-automation/SDL_test.c
test/test-automation/SDL_test.h
test/test-automation/fuzzer/fuzzer.c
test/test-automation/fuzzer/fuzzer.h
test/test-automation/logger.h
test/test-automation/plain_logger.c
test/test-automation/plain_logger.h
test/test-automation/runner.c
test/test-automation/testdummy/testdummy.c
test/test-automation/xml_logger.c
test/test-automation/xml_logger.h
--- a/test/test-automation/SDL_test.c	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/SDL_test.c	Mon Jul 25 20:32:31 2011 +0300
@@ -37,7 +37,7 @@
 int _testAssertsPassed;
 
 void
-_InitTestEnvironment(const int execKey)
+_InitTestEnvironment(char *execKey)
 {
 	// The execKey gets corrupted while passing arguments
 	// hence the global variable to circumvent the problem
--- a/test/test-automation/SDL_test.h	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/SDL_test.h	Mon Jul 25 20:32:31 2011 +0300
@@ -69,7 +69,7 @@
  *  Initialized the test environment such as asserts. Must be called at
  *  the beginning of every test case, before doing anything else.
  */
-void _InitTestEnvironment(const int execKey);
+void _InitTestEnvironment(char *execKey);
 
 /*!
  *  Deinitializes the test environment and
--- a/test/test-automation/fuzzer/fuzzer.c	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.c	Mon Jul 25 20:32:31 2011 +0300
@@ -5,16 +5,16 @@
 
 
 //! context for test-specific random number generator
-RND_CTX rndContext3;
+static RND_CTX rndContext;
 
-int
-GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName,
+char *
+GenerateExecKey(char *runSeed, char *suiteName,
 				char *testName, int iterationNumber)
 {
 	if(runSeed == NULL || suiteName == NULL ||
 	   testName == NULL || iterationNumber < 0) {
-		fprintf(stderr, "Incorrect parameter given to GenerateExecKey function\n");
-		return -1;
+		fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
+		return NULL;
 	}
 
 	char iterationString[256];
@@ -30,33 +30,41 @@
 
 	// size of the entire + 3 for slashes and + 1 for '\0'
 	const int entireString  = runSeedLength + suiteNameLength +
-							  testNameLength + iterationString + 3 + 1;
-
-	int result = 0;
+							  testNameLength + iterationStringLength + 3 + 1;
 
-	/* Let's take a hash from the strings separately because
-	 * it's really slow to calculate md5 or crc32 for a really long string
-	 * like 'runSeed/testSuiteName/testName/iteration'
-	 */
+	char *buffer = SDL_malloc(entireString);
+	if(!buffer) {
+		return NULL;
+	}
+
+	SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName,
+			testName, iterationNumber);
+
+	//printf("Debug: %s", buffer);
+
 	MD5_CTX md5Context;
 	utl_md5Init(&md5Context);
 
-	utl_md5Update(&md5Context, runSeed, runSeedLength);
-	utl_md5Update(&md5Context, suiteName, suiteNameLength);
-	utl_md5Update(&md5Context, testName, testNameLength);
-	utl_md5Update(&md5Context, iterationString, iterationStringLength);
-
+	utl_md5Update(&md5Context, buffer, entireString);
 	utl_md5Final(&md5Context);
 
-	utl_crc32Calc(&crcContext, md5Context.digest, sizeof(md5Context.digest), &result);
+	SDL_free(buffer);
 
-	return abs(result); // makes sure that the key is positive
+	const int keyLength = SDL_strlen(md5Context.digest);
+	char *key = SDL_malloc(keyLength);
+	SDL_snprintf(key, keyLength, "%s", md5Context.digest);
+
+	return key;
 }
 
 void
-InitFuzzer(const int execKey)
+InitFuzzer(char *execKey)
 {
-	utl_randomInit(&rndContext3, globalExecKey, globalExecKey / 0xfafafafa);
+	//int a = execKey[8,9,10,11];
+	int a = execKey[8] | execKey[9] | execKey[10] | execKey[11];
+	int b =  execKey[12] | execKey[13] | execKey[14] | execKey[15];
+
+	utl_randomInit(&rndContext, a, b);
 }
 
 void
@@ -68,13 +76,13 @@
 int
 RandomInteger()
 {
-	return utl_randomInt(&rndContext3);
+	return utl_randomInt(&rndContext);
 }
 
 int
 RandomPositiveInteger()
 {
-	return abs(utl_randomInt(&rndContext3));
+	return abs(utl_randomInt(&rndContext));
 }
 
 int
@@ -84,7 +92,7 @@
 		return -1; // Doesn't really make sense to return -1 on error?
 	}
 
-	int number = utl_randomInt(&rndContext3);
+	int number = utl_randomInt(&rndContext);
 	number = abs(number);
 
 	return (number % ((max + 1) - min)) + min;
@@ -130,13 +138,12 @@
 		return NULL;
 	}
 
-	const int size = abs(RandomInteger) % maxSize;
+	int size = abs(RandomInteger) % maxSize;
 	char *string = SDL_malloc(size * sizeof(size));
 
 	int counter = 0;
 	for( ; counter < size; ++counter) {
-		char character = (char) RandomIntegerInRange(1, 127);
-		string[counter] = character;
+		string[counter] = (char) RandomIntegerInRange(1, 127);
 	}
 
 	string[counter] = '\0';
--- a/test/test-automation/fuzzer/fuzzer.h	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.h	Mon Jul 25 20:32:31 2011 +0300
@@ -29,7 +29,7 @@
 /*!
  * Inits the fuzzer for a test
  */
-void InitFuzzer(const int execKey);
+void InitFuzzer(char *execKey);
 
 
 /*!
@@ -110,8 +110,9 @@
  * \param testName Test name
  * \param iteration Number of test iteration
  *
- * \return Generated execution key
+ * \return Generated execution key as blob of 16 bytes. It needs be deallocated.
+ * 			On error, returns NULL.
  */
-int GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, char *testName, int interationNumber);
+char *GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
 
 #endif
--- a/test/test-automation/logger.h	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/logger.h	Mon Jul 25 20:32:31 2011 +0300
@@ -37,7 +37,7 @@
 		                time_t endTime, double totalRuntime);
 
 typedef	void (*TestStartedFp)(const char *testName, const char *suiteName,
-                              const char *testDescription, int execKey, time_t startTime);
+                              const char *testDescription, char *execKey, time_t startTime);
 typedef	void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult,
                             time_t endTime, double totalRuntime);
 
@@ -67,9 +67,10 @@
 extern AssertSummaryFp AssertSummary;
 extern LogFp Log;
 
-extern int globalExecKey;
+//! \todo move these two away from here
+extern char *globalExecKey;
 //! Run seed for harness
-extern const char *runSeed;
+extern char *runSeed;
 
 
 #endif
--- a/test/test-automation/plain_logger.c	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/plain_logger.c	Mon Jul 25 20:32:31 2011 +0300
@@ -82,7 +82,7 @@
 
 void
 PlainTestStarted(const char *testName, const char *suiteName,
-				const char *testDescription, int execKey, time_t startTime)
+				const char *testDescription, char *execKey, time_t startTime)
 {
 	Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
 }
--- a/test/test-automation/plain_logger.h	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/plain_logger.h	Mon Jul 25 20:32:31 2011 +0300
@@ -60,7 +60,7 @@
  * \param startTime When the test started to execute
  */
 void PlainTestStarted(const char *testName, const char *suiteName,
-                      const char *testDescription, int execKey, time_t startTime);
+                      const char *testDescription, char *execKey, time_t startTime);
 
 /*!
  * Prints information about the test test that was just executed
--- a/test/test-automation/runner.c	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/runner.c	Mon Jul 25 20:32:31 2011 +0300
@@ -91,10 +91,10 @@
 //! Default directory of the test suites
 #define DEFAULT_TEST_DIRECTORY "tests/"
 
-int globalExecKey = -1;
-const char *runSeed = "seed";
+char *globalExecKey = NULL;
+char *runSeed = "seed";
 
-int userExecKey = 0;
+char *userExecKey = NULL;
 
 //! How man time a test will be invocated
 int testInvocationCount = 1;
@@ -689,7 +689,7 @@
  * \param test result
  */
 int
-RunTest(TestCase *testCase, const int execKey)
+RunTest(TestCase *testCase, char *execKey)
 {
 	if(!testCase) {
 		return -1;
@@ -738,7 +738,7 @@
  * \return The return value of the test. Zero means success, non-zero failure.
  */
 int
-ExecuteTest(TestCase *testItem, const int execKey) {
+ExecuteTest(TestCase *testItem, char *execKey) {
 	int retVal = -1;
 
 	if(execute_inproc) {
@@ -948,6 +948,10 @@
     	  }
 
     	  testInvocationCount = atoi(iterationsString);
+    	  if(testInvocationCount < 1) {
+    		  printf("Iteration value has to bigger than 0.\n");
+    		  exit(1);
+    	  }
       }
       else if(SDL_strcmp(arg, "--exec-key") == 0) {
     	  char *execKeyString = NULL;
@@ -959,7 +963,7 @@
     		  exit(1);
     	  }
 
-    	  userExecKey = atoi(execKeyString);
+    	  userExecKey = execKeyString;
       }
       else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
     	  only_selected_test = 1;
@@ -1047,9 +1051,6 @@
 {
 	ParseOptions(argc, argv);
 
-	CRC32_CTX crcContext;
-	utl_crc32Init(&crcContext);
-
 	// print: Testing against SDL version fuu (rev: bar) if verbose == true
 
 	char *testSuiteName = NULL;
@@ -1122,10 +1123,10 @@
 
 		int currentIteration = testInvocationCount;
 		while(currentIteration > 0) {
-			if(userExecKey != 0) {
+			if(userExecKey != NULL) {
 				globalExecKey = userExecKey;
 			} else {
-				const int execKey = GenerateExecKey(crcContext, runSeed, testItem->suiteName,
+				char *execKey = GenerateExecKey(runSeed, testItem->suiteName,
 											  testItem->testName, currentIteration);
 				globalExecKey = execKey;
 			}
@@ -1142,6 +1143,9 @@
 			TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
 
 			currentIteration--;
+
+			SDL_free(globalExecKey);
+			globalExecKey = NULL;
 		}
 	}
 
@@ -1162,7 +1166,5 @@
 	// Some SDL subsystem might be init'ed so shut them down
 	SDL_Quit();
 
-	utl_crc32Done(&crcContext);
-
 	return (totalTestFailureCount ? 1 : 0);
 }
--- a/test/test-automation/testdummy/testdummy.c	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/testdummy/testdummy.c	Mon Jul 25 20:32:31 2011 +0300
@@ -107,7 +107,7 @@
 		Log(0, "%d", random);
 	}
 
-	//Log(0, "Random: %s", RandomAsciiStringWithMaximumLength(2));
+	Log(0, "Random: %s", RandomAsciiString());
 }
 
 void
@@ -121,7 +121,7 @@
 void
 dummycase3(void *arg)
 {
-	while(1);
+	while(0);
 	//AssertTrue(1, "Assert message");
 }
 
--- a/test/test-automation/xml_logger.c	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/xml_logger.c	Mon Jul 25 20:32:31 2011 +0300
@@ -324,7 +324,7 @@
 
 void
 XMLTestStarted(const char *testName, const char *suiteName,
-			  const char *testDescription, int execKey, time_t startTime)
+			  const char *testDescription, char *execKey, time_t startTime)
 {
 	char * output = XMLOpenElement(testElementName);
 	XMLOutputter(indentLevel++, YES, output);
--- a/test/test-automation/xml_logger.h	Mon Jul 25 19:33:32 2011 +0300
+++ b/test/test-automation/xml_logger.h	Mon Jul 25 20:32:31 2011 +0300
@@ -59,7 +59,7 @@
  * \param startTime When the test started to execute
  */
 void XMLTestStarted(const char *testName, const char *suiteName,
-					const char *testDescription, int execKey, time_t startTime);
+					const char *testDescription, char *execKey, time_t startTime);
 
 /*!
  * Prints information about the test test that was just executed in XML