Fixed an issue with fuzzing seeds.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Thu, 28 Jul 2011 22:11:30 +0300
changeset 5789 d2123992108f
parent 5788 eeb5431a8cbf
child 5790 7a2531e260b2
Fixed an issue with fuzzing seeds.
test/test-automation/build-scripts/install-tests.sh
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/xml_logger.c
test/test-automation/xml_logger.h
--- a/test/test-automation/build-scripts/install-tests.sh	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/build-scripts/install-tests.sh	Thu Jul 28 22:11:30 2011 +0300
@@ -21,6 +21,6 @@
 	cp -f "$suite/.libs/lib$suite.$EXT" $DIRECTORY
 done
 
-sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib
+#sudo cp .libs/libtest.0.dylib /usr/local/lib/libtest.0.dylib
 
 echo "Test suites installed."
--- a/test/test-automation/fuzzer/fuzzer.c	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.c	Thu Jul 28 22:11:30 2011 +0300
@@ -7,14 +7,14 @@
 //! context for test-specific random number generator
 static RND_CTX rndContext;
 
-char *
+int
 GenerateExecKey(char *runSeed, char *suiteName,
 				char *testName, int iterationNumber)
 {
 	if(runSeed == NULL || suiteName == NULL ||
 	   testName == NULL || iterationNumber < 0) {
 		fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
-		return NULL;
+		return -1;
 	}
 
 	char iterationString[256];
@@ -34,14 +34,12 @@
 
 	char *buffer = SDL_malloc(entireString);
 	if(!buffer) {
-		return NULL;
+		return -1;
 	}
 
 	SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName,
 			testName, iterationNumber);
 
-	//printf("Debug: %s", buffer);
-
 	MD5_CTX md5Context;
 	utl_md5Init(&md5Context);
 
@@ -50,21 +48,20 @@
 
 	SDL_free(buffer);
 
-	const int keyLength = SDL_strlen(md5Context.digest);
-	char *key = SDL_malloc(keyLength);
-	SDL_snprintf(key, keyLength, "%s", md5Context.digest);
+	char *execKey = md5Context.digest;
 
-	return key;
+	int key = execKey[4] << 24 |
+			  execKey[9] << 16 |
+			  execKey[13] << 8 |
+			  execKey[3] << 0;
+
+	return abs(key);
 }
 
 void
-InitFuzzer(char *execKey)
+InitFuzzer(int execKey)
 {
-	//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);
+	utl_randomInit(&rndContext, execKey, execKey / 0xfafafafa);
 }
 
 void
--- a/test/test-automation/fuzzer/fuzzer.h	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.h	Thu Jul 28 22:11:30 2011 +0300
@@ -29,7 +29,7 @@
 /*!
  * Inits the fuzzer for a test
  */
-void InitFuzzer(char *execKey);
+void InitFuzzer(int execKey);
 
 
 /*!
@@ -113,6 +113,6 @@
  * \return Generated execution key as blob of 16 bytes. It needs be deallocated.
  * 			On error, returns NULL.
  */
-char *GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
+int GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
 
 #endif
--- a/test/test-automation/logger.h	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/logger.h	Thu Jul 28 22:11:30 2011 +0300
@@ -55,7 +55,7 @@
 		                time_t endTime, double totalRuntime);
 
 typedef	void (*TestStartedFp)(const char *testName, const char *suiteName,
-                              const char *testDescription, char *execKey, time_t startTime);
+                              const char *testDescription, int execKey, time_t startTime);
 typedef	void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult,
                             time_t endTime, double totalRuntime);
 
@@ -86,7 +86,7 @@
 extern LogFp Log;
 
 //! \todo move these two away from here
-extern char *globalExecKey;
+extern int globalExecKey;
 //! Run seed for harness
 extern char *runSeed;
 
--- a/test/test-automation/plain_logger.c	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/plain_logger.c	Thu Jul 28 22:11:30 2011 +0300
@@ -119,7 +119,7 @@
 
 void
 PlainTestStarted(const char *testName, const char *suiteName,
-				const char *testDescription, char *execKey, time_t startTime)
+				const char *testDescription, int execKey, time_t startTime)
 {
 	Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
 }
--- a/test/test-automation/plain_logger.h	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/plain_logger.h	Thu Jul 28 22:11:30 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, char *execKey, time_t startTime);
+                      const char *testDescription, int execKey, time_t startTime);
 
 /*!
  * Prints information about the test test that was just executed
--- a/test/test-automation/runner.c	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/runner.c	Thu Jul 28 22:11:30 2011 +0300
@@ -112,10 +112,10 @@
 
 
 //! Variable is used to pass the generated execution key to a test
-char *globalExecKey = NULL;
+int globalExecKey = 0;
 
 //! Execution key that user supplied via command options
-char *userExecKey = NULL;
+int userExecKey = 0;
 
 //! How man time a test will be invocated
 int testInvocationCount = 1;
@@ -716,7 +716,7 @@
  * \param test result
  */
 int
-RunTest(TestCase *testCase, char *execKey)
+RunTest(TestCase *testCase, int execKey)
 {
 	if(!testCase) {
 		return -1;
@@ -765,7 +765,7 @@
  * \return The return value of the test. Zero means success, non-zero failure.
  */
 int
-ExecuteTest(TestCase *testItem, char *execKey) {
+ExecuteTest(TestCase *testItem, int execKey) {
 	int retVal = -1;
 
 	if(execute_inproc) {
@@ -1121,7 +1121,9 @@
     		  exit(1);
     	  }
 
-    	  userExecKey = execKeyString;
+    	  // \todo User given string should be handled as a string
+    	  // representing a hex digit
+    	  userExecKey = atoi(execKeyString);
       }
       else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
     	  only_selected_test = 1;
@@ -1341,7 +1343,7 @@
 	}
 
 	UnloadTestCases(testCases);
-	UnloadTestSuites(suites); // crashes here with -ts case1
+	UnloadTestSuites(suites);
 
 	const Uint32 endTicks = SDL_GetTicks();
 	const double totalRunTime = (endTicks - startTicks) / 1000.0f;
--- a/test/test-automation/xml_logger.c	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/xml_logger.c	Thu Jul 28 22:11:30 2011 +0300
@@ -351,7 +351,7 @@
 
 void
 XMLTestStarted(const char *testName, const char *suiteName,
-			  const char *testDescription, char *execKey, time_t startTime)
+			  const char *testDescription, int execKey, time_t startTime)
 {
 	char * output = XMLOpenElement(testElementName);
 	XMLOutputter(indentLevel++, YES, output);
--- a/test/test-automation/xml_logger.h	Thu Jul 28 21:35:47 2011 +0300
+++ b/test/test-automation/xml_logger.h	Thu Jul 28 22:11:30 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, char *execKey, time_t startTime);
+					const char *testDescription, int execKey, time_t startTime);
 
 /*!
  * Prints information about the test test that was just executed in XML