Fixing execution key generation based on CR.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Tue, 02 Aug 2011 12:46:40 +0300
changeset 5797 4936c840d128
parent 5796 610df1cc7b4a
child 5798 40d11e399784
Fixing execution key generation based on CR.
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/logger_helpers.c
test/test-automation/logger_helpers.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/SDL_test.c	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/SDL_test.c	Tue Aug 02 12:46:40 2011 +0300
@@ -22,6 +22,8 @@
 #include <stdarg.h> /* va_list */
 #include <time.h>
 
+#include <SDL/SDL_stdinc.h>
+
 #include "logger.h"
 #include "fuzzer/fuzzer.h"
 
@@ -37,12 +39,9 @@
 int _testAssertsPassed;
 
 void
-_InitTestEnvironment(char *execKey)
+_InitTestEnvironment(Uint64 execKey)
 {
-	// The execKey gets corrupted while passing arguments
-	// hence the global variable to circumvent the problem
-	InitFuzzer(globalExecKey);
-
+	InitFuzzer(execKey);
 
 	_testReturnValue = TEST_RESULT_PASS;
 	_testAssertsFailed = 0;
--- a/test/test-automation/SDL_test.h	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/SDL_test.h	Tue Aug 02 12:46:40 2011 +0300
@@ -28,12 +28,6 @@
 
 #include "fuzzer/fuzzer.h"
 
-/*
-extern int _testReturnValue;
-extern int _testAssertsFailed;
-extern int _testAssertsPassed;
-*/
-
 #define TEST_ENABLED  1
 #define TEST_DISABLED 0
 
@@ -71,8 +65,10 @@
 /*!
  *  Initialized the test environment such as asserts. Must be called at
  *  the beginning of every test case, before doing anything else.
+ *
+ *  \param execKey Execution key for the test
  */
-void _InitTestEnvironment(char *execKey);
+void _InitTestEnvironment(Uint64 execKey);
 
 /*!
  *  Deinitializes the test environment and
--- a/test/test-automation/fuzzer/fuzzer.c	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.c	Tue Aug 02 12:46:40 2011 +0300
@@ -1,3 +1,6 @@
+
+#include <stdio.h>
+#include <stdlib.h>
 
 #include "../SDL_test.h"
 
@@ -7,29 +10,43 @@
 //! context for test-specific random number generator
 static RND_CTX rndContext;
 
-int
+Uint64
 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");
+	if(runSeed == NULL) {
+		fprintf(stderr, "Error: Incorrect runSeed given to GenerateExecKey function\n");
+		return -1;
+	}
+
+	if(suiteName == NULL) {
+		fprintf(stderr, "Error: Incorrect suiteName given to GenerateExecKey function\n");
+		return -1;
+	}
+
+	if(testName == NULL) {
+		fprintf(stderr, "Error: Incorrect testName given to GenerateExecKey function\n");
 		return -1;
 	}
 
-	char iterationString[256];
+	if(iterationNumber < 0) {
+		fprintf(stderr, "Error: Incorrect iteration number given to GenerateExecKey function\n");
+		return -1;
+	}
+
+
+	char iterationString[16];
 	memset(iterationString, 0, sizeof(iterationString));
-
-	snprintf(iterationString, sizeof(iterationString), "%d", iterationNumber);
+	SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iterationNumber);
 
 	// combine the parameters
-	const int runSeedLength = strlen(runSeed);
-	const int suiteNameLength = strlen(suiteName);
-	const int testNameLength = strlen(testName);
-	const int iterationStringLength = strlen(iterationString);
+	const Uint32 runSeedLength = strlen(runSeed);
+	const Uint32 suiteNameLength = strlen(suiteName);
+	const Uint32 testNameLength = strlen(testName);
+	const Uint32 iterationStringLength = strlen(iterationString);
 
 	// size of the entire + 3 for slashes and + 1 for '\0'
-	const int entireString  = runSeedLength + suiteNameLength +
+	const Uint32 entireString  = runSeedLength + suiteNameLength +
 							  testNameLength + iterationStringLength + 3 + 1;
 
 	char *buffer = SDL_malloc(entireString);
@@ -48,21 +65,32 @@
 
 	SDL_free(buffer);
 
-	char *execKey = md5Context.digest;
+	const char *execKey = md5Context.digest;
+
+	//printf("Debug: digest = %s\n", execKey);
 
-	//! \todo could this be enhanced?
-	int key = execKey[4] << 24 |
-			  execKey[9] << 16 |
-			  execKey[13] << 8 |
-			  execKey[3] << 0;
+	Uint64 key = execKey[8]  << 56 |
+				 execKey[9]  << 48 |
+				 execKey[10] << 40 |
+				 execKey[11] << 32 |
+				 execKey[12] << 24 |
+				 execKey[13] << 16 |
+				 execKey[14] << 8  |
+				 execKey[15] << 0;
 
-	return abs(key);
+	return key;
 }
 
 void
-InitFuzzer(int execKey)
+InitFuzzer(Uint64 execKey)
 {
-	utl_randomInit(&rndContext, execKey, execKey / 0xfafafafa);
+	Uint32 a = (execKey >> 32)  & 0x00000000FFFFFFFF;
+	Uint32 b = execKey & 0x00000000FFFFFFFF;
+
+	//printf("Debug: execKey: %llx\n", execKey);
+	//printf("Debug: a = %x - b = %x\n", a, b);
+
+	utl_randomInit(&rndContext, a, b);
 }
 
 void
--- a/test/test-automation/fuzzer/fuzzer.h	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.h	Tue Aug 02 12:46:40 2011 +0300
@@ -21,6 +21,8 @@
 #ifndef _FUZZER_H
 #define _FUZZER_H
 
+#include <SDL/SDL_stdinc.h>
+
 #include "utl_crc32.h"
 #include "utl_md5.h"
 #include "utl_random.h"
@@ -29,7 +31,7 @@
 /*!
  * Inits the fuzzer for a test
  */
-void InitFuzzer(int execKey);
+void InitFuzzer(Uint64 execKey);
 
 
 /*!
@@ -113,6 +115,6 @@
  * \return Generated execution key as blob of 16 bytes. It needs be deallocated.
  * 			On error, returns NULL.
  */
-int GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
+Uint64 GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
 
 #endif
--- a/test/test-automation/logger.h	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/logger.h	Tue Aug 02 12:46:40 2011 +0300
@@ -21,6 +21,8 @@
 #ifndef _LOGGER_H
 #define _LOGGER_H
 
+#include <SDL/SDL_stdinc.h>
+
 #include <time.h>
 
 /* Logging levels */
@@ -56,7 +58,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, Uint64 execKey, time_t startTime);
 typedef	void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult,
                             time_t endTime, double totalRuntime);
 
@@ -86,8 +88,6 @@
 extern AssertSummaryFp AssertSummary;
 extern LogFp Log;
 
-//! \todo move these two away from here
-extern int globalExecKey;
 //! Run seed for harness
 extern char *runSeed;
 
--- a/test/test-automation/logger_helpers.c	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/logger_helpers.c	Tue Aug 02 12:46:40 2011 +0300
@@ -33,11 +33,11 @@
  *  \param integer The converted integer
  *  \returns Given integer as string in hex fomat
  */
-char *IntToHexString(const int integer) {
+char *IntToHexString(const Uint64 integer) {
 	static char buffer[256]; // malloc might work better
 	memset(buffer, 0, sizeof(buffer));
 
-	SDL_snprintf(buffer, sizeof(buffer), "%X", integer);
+	SDL_snprintf(buffer, sizeof(buffer), "%llX", integer);
 
 	return buffer;
 }
--- a/test/test-automation/logger_helpers.h	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/logger_helpers.h	Tue Aug 02 12:46:40 2011 +0300
@@ -5,7 +5,7 @@
 
 char *IntToString(const int integer);
 
-char *IntToHexString(const int integer);
+char *IntToHexString(const Uint64 integer);
 
 char *DoubleToString(const double decimal);
 
--- a/test/test-automation/plain_logger.c	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/plain_logger.c	Tue Aug 02 12:46:40 2011 +0300
@@ -119,9 +119,9 @@
 
 void
 PlainTestStarted(const char *testName, const char *suiteName,
-				const char *testDescription, int execKey, time_t startTime)
+				const char *testDescription, Uint64 execKey, time_t startTime)
 {
-	Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
+	Output(indentLevel++, "Executing test: %s (in %s). Exec key: %llX", testName, suiteName, execKey);
 }
 
 void
--- a/test/test-automation/plain_logger.h	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/plain_logger.h	Tue Aug 02 12:46:40 2011 +0300
@@ -2,6 +2,8 @@
 #define _PLAIN_LOGGER_H
 
 #include "logger.h"
+#include <SDL/SDL_stdinc.h>
+
 
 /*!
  * Prints out information about starting the test run.
@@ -60,7 +62,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, Uint64 execKey, time_t startTime);
 
 /*!
  * Prints information about the test test that was just executed
--- a/test/test-automation/runner.c	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/runner.c	Tue Aug 02 12:46:40 2011 +0300
@@ -43,7 +43,7 @@
 //!< Function pointer to a test case function
 typedef void (*TestCaseFp)(void *arg);
 //!< Function pointer to a test case init function
-typedef void (*InitTestInvironmentFp)(void);
+typedef void (*InitTestInvironmentFp)(Uint64);
 //!< Function pointer to a test case quit function
 typedef int  (*QuitTestInvironmentFp)(void);
 //!< Function pointer to a test case set up function
@@ -115,11 +115,8 @@
 //! Fuzzer seed for the harness
 char *runSeed = NULL;
 
-//! Variable is used to pass the generated execution key to a test
-int globalExecKey = 0;
-
 //! Execution key that user supplied via command options
-int userExecKey = 0;
+Uint64 userExecKey = 0;
 
 //! How man time a test will be invocated
 int testInvocationCount = 1;
@@ -762,7 +759,7 @@
  * \param test result
  */
 int
-RunTest(TestCase *testCase, int execKey)
+RunTest(TestCase *testCase, Uint64 execKey)
 {
 	if(!testCase) {
 		return -1;
@@ -782,7 +779,7 @@
 		}
 	}
 
-	testCase->initTestEnvironment();
+	testCase->initTestEnvironment(execKey);
 
 	if(testCase->testSetUp) {
 		testCase->testSetUp(0x0);
@@ -811,7 +808,7 @@
  * \return The return value of the test. Zero means success, non-zero failure.
  */
 int
-ExecuteTest(TestCase *testItem, int execKey) {
+ExecuteTest(TestCase *testItem, Uint64 execKey) {
 	int retVal = -1;
 
 	if(execute_inproc) {
@@ -1388,19 +1385,20 @@
 
 		int currentIteration = testInvocationCount;
 		while(currentIteration > 0) {
-			if(userExecKey != NULL) {
-				globalExecKey = userExecKey;
+			Uint64 execKey = 5;
+			if(userExecKey != 0) {
+				execKey = userExecKey;
 			} else {
-				globalExecKey  = GenerateExecKey(runSeed, testItem->suiteName,
+				execKey  = GenerateExecKey(runSeed, testItem->suiteName,
 											  testItem->testName, currentIteration);
 			}
 
 			TestStarted(testItem->testName, testItem->suiteName,
-						testItem->description, globalExecKey, time(0));
+						testItem->description, execKey, time(0));
 
 			const Uint32 testTimeStart = SDL_GetTicks();
 
-			int retVal = ExecuteTest(testItem, globalExecKey);
+			int retVal = ExecuteTest(testItem, execKey);
 
 			const double testTotalRuntime = (SDL_GetTicks() - testTimeStart) / 1000.0f;
 
--- a/test/test-automation/xml_logger.c	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/xml_logger.c	Tue Aug 02 12:46:40 2011 +0300
@@ -351,7 +351,7 @@
 
 void
 XMLTestStarted(const char *testName, const char *suiteName,
-			  const char *testDescription, int execKey, time_t startTime)
+			  const char *testDescription, Uint64 execKey, time_t startTime)
 {
 	char * output = XMLOpenElement(testElementName);
 	XMLOutputter(indentLevel++, YES, output);
--- a/test/test-automation/xml_logger.h	Tue Aug 02 11:20:11 2011 +0300
+++ b/test/test-automation/xml_logger.h	Tue Aug 02 12:46:40 2011 +0300
@@ -1,6 +1,8 @@
 #ifndef _XML_LOGGER_H
 #define _XML_LOGGER_H
 
+#include <SDL/SDL_stdinc.h>
+
 #include "logger.h"
 
 /*!
@@ -59,7 +61,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, Uint64 execKey, time_t startTime);
 
 /*!
  * Prints information about the test test that was just executed in XML