Changing the execution key generator.
authorMarkus Kauppila
Mon, 25 Jul 2011 20:32:31 +0300
changeset 5784676f4613ee14
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
     1.1 --- a/test/test-automation/SDL_test.c	Mon Jul 25 19:33:32 2011 +0300
     1.2 +++ b/test/test-automation/SDL_test.c	Mon Jul 25 20:32:31 2011 +0300
     1.3 @@ -37,7 +37,7 @@
     1.4  int _testAssertsPassed;
     1.5  
     1.6  void
     1.7 -_InitTestEnvironment(const int execKey)
     1.8 +_InitTestEnvironment(char *execKey)
     1.9  {
    1.10  	// The execKey gets corrupted while passing arguments
    1.11  	// hence the global variable to circumvent the problem
     2.1 --- a/test/test-automation/SDL_test.h	Mon Jul 25 19:33:32 2011 +0300
     2.2 +++ b/test/test-automation/SDL_test.h	Mon Jul 25 20:32:31 2011 +0300
     2.3 @@ -69,7 +69,7 @@
     2.4   *  Initialized the test environment such as asserts. Must be called at
     2.5   *  the beginning of every test case, before doing anything else.
     2.6   */
     2.7 -void _InitTestEnvironment(const int execKey);
     2.8 +void _InitTestEnvironment(char *execKey);
     2.9  
    2.10  /*!
    2.11   *  Deinitializes the test environment and
     3.1 --- a/test/test-automation/fuzzer/fuzzer.c	Mon Jul 25 19:33:32 2011 +0300
     3.2 +++ b/test/test-automation/fuzzer/fuzzer.c	Mon Jul 25 20:32:31 2011 +0300
     3.3 @@ -5,16 +5,16 @@
     3.4  
     3.5  
     3.6  //! context for test-specific random number generator
     3.7 -RND_CTX rndContext3;
     3.8 +static RND_CTX rndContext;
     3.9  
    3.10 -int
    3.11 -GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName,
    3.12 +char *
    3.13 +GenerateExecKey(char *runSeed, char *suiteName,
    3.14  				char *testName, int iterationNumber)
    3.15  {
    3.16  	if(runSeed == NULL || suiteName == NULL ||
    3.17  	   testName == NULL || iterationNumber < 0) {
    3.18 -		fprintf(stderr, "Incorrect parameter given to GenerateExecKey function\n");
    3.19 -		return -1;
    3.20 +		fprintf(stderr, "Error: Incorrect parameter given to GenerateExecKey function\n");
    3.21 +		return NULL;
    3.22  	}
    3.23  
    3.24  	char iterationString[256];
    3.25 @@ -30,33 +30,41 @@
    3.26  
    3.27  	// size of the entire + 3 for slashes and + 1 for '\0'
    3.28  	const int entireString  = runSeedLength + suiteNameLength +
    3.29 -							  testNameLength + iterationString + 3 + 1;
    3.30 -
    3.31 -	int result = 0;
    3.32 +							  testNameLength + iterationStringLength + 3 + 1;
    3.33  
    3.34 -	/* Let's take a hash from the strings separately because
    3.35 -	 * it's really slow to calculate md5 or crc32 for a really long string
    3.36 -	 * like 'runSeed/testSuiteName/testName/iteration'
    3.37 -	 */
    3.38 +	char *buffer = SDL_malloc(entireString);
    3.39 +	if(!buffer) {
    3.40 +		return NULL;
    3.41 +	}
    3.42 +
    3.43 +	SDL_snprintf(buffer, entireString, "%s/%s/%s/%d", runSeed, suiteName,
    3.44 +			testName, iterationNumber);
    3.45 +
    3.46 +	//printf("Debug: %s", buffer);
    3.47 +
    3.48  	MD5_CTX md5Context;
    3.49  	utl_md5Init(&md5Context);
    3.50  
    3.51 -	utl_md5Update(&md5Context, runSeed, runSeedLength);
    3.52 -	utl_md5Update(&md5Context, suiteName, suiteNameLength);
    3.53 -	utl_md5Update(&md5Context, testName, testNameLength);
    3.54 -	utl_md5Update(&md5Context, iterationString, iterationStringLength);
    3.55 -
    3.56 +	utl_md5Update(&md5Context, buffer, entireString);
    3.57  	utl_md5Final(&md5Context);
    3.58  
    3.59 -	utl_crc32Calc(&crcContext, md5Context.digest, sizeof(md5Context.digest), &result);
    3.60 +	SDL_free(buffer);
    3.61  
    3.62 -	return abs(result); // makes sure that the key is positive
    3.63 +	const int keyLength = SDL_strlen(md5Context.digest);
    3.64 +	char *key = SDL_malloc(keyLength);
    3.65 +	SDL_snprintf(key, keyLength, "%s", md5Context.digest);
    3.66 +
    3.67 +	return key;
    3.68  }
    3.69  
    3.70  void
    3.71 -InitFuzzer(const int execKey)
    3.72 +InitFuzzer(char *execKey)
    3.73  {
    3.74 -	utl_randomInit(&rndContext3, globalExecKey, globalExecKey / 0xfafafafa);
    3.75 +	//int a = execKey[8,9,10,11];
    3.76 +	int a = execKey[8] | execKey[9] | execKey[10] | execKey[11];
    3.77 +	int b =  execKey[12] | execKey[13] | execKey[14] | execKey[15];
    3.78 +
    3.79 +	utl_randomInit(&rndContext, a, b);
    3.80  }
    3.81  
    3.82  void
    3.83 @@ -68,13 +76,13 @@
    3.84  int
    3.85  RandomInteger()
    3.86  {
    3.87 -	return utl_randomInt(&rndContext3);
    3.88 +	return utl_randomInt(&rndContext);
    3.89  }
    3.90  
    3.91  int
    3.92  RandomPositiveInteger()
    3.93  {
    3.94 -	return abs(utl_randomInt(&rndContext3));
    3.95 +	return abs(utl_randomInt(&rndContext));
    3.96  }
    3.97  
    3.98  int
    3.99 @@ -84,7 +92,7 @@
   3.100  		return -1; // Doesn't really make sense to return -1 on error?
   3.101  	}
   3.102  
   3.103 -	int number = utl_randomInt(&rndContext3);
   3.104 +	int number = utl_randomInt(&rndContext);
   3.105  	number = abs(number);
   3.106  
   3.107  	return (number % ((max + 1) - min)) + min;
   3.108 @@ -130,13 +138,12 @@
   3.109  		return NULL;
   3.110  	}
   3.111  
   3.112 -	const int size = abs(RandomInteger) % maxSize;
   3.113 +	int size = abs(RandomInteger) % maxSize;
   3.114  	char *string = SDL_malloc(size * sizeof(size));
   3.115  
   3.116  	int counter = 0;
   3.117  	for( ; counter < size; ++counter) {
   3.118 -		char character = (char) RandomIntegerInRange(1, 127);
   3.119 -		string[counter] = character;
   3.120 +		string[counter] = (char) RandomIntegerInRange(1, 127);
   3.121  	}
   3.122  
   3.123  	string[counter] = '\0';
     4.1 --- a/test/test-automation/fuzzer/fuzzer.h	Mon Jul 25 19:33:32 2011 +0300
     4.2 +++ b/test/test-automation/fuzzer/fuzzer.h	Mon Jul 25 20:32:31 2011 +0300
     4.3 @@ -29,7 +29,7 @@
     4.4  /*!
     4.5   * Inits the fuzzer for a test
     4.6   */
     4.7 -void InitFuzzer(const int execKey);
     4.8 +void InitFuzzer(char *execKey);
     4.9  
    4.10  
    4.11  /*!
    4.12 @@ -110,8 +110,9 @@
    4.13   * \param testName Test name
    4.14   * \param iteration Number of test iteration
    4.15   *
    4.16 - * \return Generated execution key
    4.17 + * \return Generated execution key as blob of 16 bytes. It needs be deallocated.
    4.18 + * 			On error, returns NULL.
    4.19   */
    4.20 -int GenerateExecKey(CRC32_CTX crcContext, char *runSeed, char *suiteName, char *testName, int interationNumber);
    4.21 +char *GenerateExecKey(char *runSeed, char *suiteName, char *testName, int interationNumber);
    4.22  
    4.23  #endif
     5.1 --- a/test/test-automation/logger.h	Mon Jul 25 19:33:32 2011 +0300
     5.2 +++ b/test/test-automation/logger.h	Mon Jul 25 20:32:31 2011 +0300
     5.3 @@ -37,7 +37,7 @@
     5.4  		                time_t endTime, double totalRuntime);
     5.5  
     5.6  typedef	void (*TestStartedFp)(const char *testName, const char *suiteName,
     5.7 -                              const char *testDescription, int execKey, time_t startTime);
     5.8 +                              const char *testDescription, char *execKey, time_t startTime);
     5.9  typedef	void (*TestEndedFp)(const char *testName, const char *suiteName, int testResult,
    5.10                              time_t endTime, double totalRuntime);
    5.11  
    5.12 @@ -67,9 +67,10 @@
    5.13  extern AssertSummaryFp AssertSummary;
    5.14  extern LogFp Log;
    5.15  
    5.16 -extern int globalExecKey;
    5.17 +//! \todo move these two away from here
    5.18 +extern char *globalExecKey;
    5.19  //! Run seed for harness
    5.20 -extern const char *runSeed;
    5.21 +extern char *runSeed;
    5.22  
    5.23  
    5.24  #endif
     6.1 --- a/test/test-automation/plain_logger.c	Mon Jul 25 19:33:32 2011 +0300
     6.2 +++ b/test/test-automation/plain_logger.c	Mon Jul 25 20:32:31 2011 +0300
     6.3 @@ -82,7 +82,7 @@
     6.4  
     6.5  void
     6.6  PlainTestStarted(const char *testName, const char *suiteName,
     6.7 -				const char *testDescription, int execKey, time_t startTime)
     6.8 +				const char *testDescription, char *execKey, time_t startTime)
     6.9  {
    6.10  	Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
    6.11  }
     7.1 --- a/test/test-automation/plain_logger.h	Mon Jul 25 19:33:32 2011 +0300
     7.2 +++ b/test/test-automation/plain_logger.h	Mon Jul 25 20:32:31 2011 +0300
     7.3 @@ -60,7 +60,7 @@
     7.4   * \param startTime When the test started to execute
     7.5   */
     7.6  void PlainTestStarted(const char *testName, const char *suiteName,
     7.7 -                      const char *testDescription, int execKey, time_t startTime);
     7.8 +                      const char *testDescription, char *execKey, time_t startTime);
     7.9  
    7.10  /*!
    7.11   * Prints information about the test test that was just executed
     8.1 --- a/test/test-automation/runner.c	Mon Jul 25 19:33:32 2011 +0300
     8.2 +++ b/test/test-automation/runner.c	Mon Jul 25 20:32:31 2011 +0300
     8.3 @@ -91,10 +91,10 @@
     8.4  //! Default directory of the test suites
     8.5  #define DEFAULT_TEST_DIRECTORY "tests/"
     8.6  
     8.7 -int globalExecKey = -1;
     8.8 -const char *runSeed = "seed";
     8.9 +char *globalExecKey = NULL;
    8.10 +char *runSeed = "seed";
    8.11  
    8.12 -int userExecKey = 0;
    8.13 +char *userExecKey = NULL;
    8.14  
    8.15  //! How man time a test will be invocated
    8.16  int testInvocationCount = 1;
    8.17 @@ -689,7 +689,7 @@
    8.18   * \param test result
    8.19   */
    8.20  int
    8.21 -RunTest(TestCase *testCase, const int execKey)
    8.22 +RunTest(TestCase *testCase, char *execKey)
    8.23  {
    8.24  	if(!testCase) {
    8.25  		return -1;
    8.26 @@ -738,7 +738,7 @@
    8.27   * \return The return value of the test. Zero means success, non-zero failure.
    8.28   */
    8.29  int
    8.30 -ExecuteTest(TestCase *testItem, const int execKey) {
    8.31 +ExecuteTest(TestCase *testItem, char *execKey) {
    8.32  	int retVal = -1;
    8.33  
    8.34  	if(execute_inproc) {
    8.35 @@ -948,6 +948,10 @@
    8.36      	  }
    8.37  
    8.38      	  testInvocationCount = atoi(iterationsString);
    8.39 +    	  if(testInvocationCount < 1) {
    8.40 +    		  printf("Iteration value has to bigger than 0.\n");
    8.41 +    		  exit(1);
    8.42 +    	  }
    8.43        }
    8.44        else if(SDL_strcmp(arg, "--exec-key") == 0) {
    8.45      	  char *execKeyString = NULL;
    8.46 @@ -959,7 +963,7 @@
    8.47      		  exit(1);
    8.48      	  }
    8.49  
    8.50 -    	  userExecKey = atoi(execKeyString);
    8.51 +    	  userExecKey = execKeyString;
    8.52        }
    8.53        else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
    8.54      	  only_selected_test = 1;
    8.55 @@ -1047,9 +1051,6 @@
    8.56  {
    8.57  	ParseOptions(argc, argv);
    8.58  
    8.59 -	CRC32_CTX crcContext;
    8.60 -	utl_crc32Init(&crcContext);
    8.61 -
    8.62  	// print: Testing against SDL version fuu (rev: bar) if verbose == true
    8.63  
    8.64  	char *testSuiteName = NULL;
    8.65 @@ -1122,10 +1123,10 @@
    8.66  
    8.67  		int currentIteration = testInvocationCount;
    8.68  		while(currentIteration > 0) {
    8.69 -			if(userExecKey != 0) {
    8.70 +			if(userExecKey != NULL) {
    8.71  				globalExecKey = userExecKey;
    8.72  			} else {
    8.73 -				const int execKey = GenerateExecKey(crcContext, runSeed, testItem->suiteName,
    8.74 +				char *execKey = GenerateExecKey(runSeed, testItem->suiteName,
    8.75  											  testItem->testName, currentIteration);
    8.76  				globalExecKey = execKey;
    8.77  			}
    8.78 @@ -1142,6 +1143,9 @@
    8.79  			TestEnded(testItem->testName, testItem->suiteName, retVal, time(0), testTotalRuntime);
    8.80  
    8.81  			currentIteration--;
    8.82 +
    8.83 +			SDL_free(globalExecKey);
    8.84 +			globalExecKey = NULL;
    8.85  		}
    8.86  	}
    8.87  
    8.88 @@ -1162,7 +1166,5 @@
    8.89  	// Some SDL subsystem might be init'ed so shut them down
    8.90  	SDL_Quit();
    8.91  
    8.92 -	utl_crc32Done(&crcContext);
    8.93 -
    8.94  	return (totalTestFailureCount ? 1 : 0);
    8.95  }
     9.1 --- a/test/test-automation/testdummy/testdummy.c	Mon Jul 25 19:33:32 2011 +0300
     9.2 +++ b/test/test-automation/testdummy/testdummy.c	Mon Jul 25 20:32:31 2011 +0300
     9.3 @@ -107,7 +107,7 @@
     9.4  		Log(0, "%d", random);
     9.5  	}
     9.6  
     9.7 -	//Log(0, "Random: %s", RandomAsciiStringWithMaximumLength(2));
     9.8 +	Log(0, "Random: %s", RandomAsciiString());
     9.9  }
    9.10  
    9.11  void
    9.12 @@ -121,7 +121,7 @@
    9.13  void
    9.14  dummycase3(void *arg)
    9.15  {
    9.16 -	while(1);
    9.17 +	while(0);
    9.18  	//AssertTrue(1, "Assert message");
    9.19  }
    9.20  
    10.1 --- a/test/test-automation/xml_logger.c	Mon Jul 25 19:33:32 2011 +0300
    10.2 +++ b/test/test-automation/xml_logger.c	Mon Jul 25 20:32:31 2011 +0300
    10.3 @@ -324,7 +324,7 @@
    10.4  
    10.5  void
    10.6  XMLTestStarted(const char *testName, const char *suiteName,
    10.7 -			  const char *testDescription, int execKey, time_t startTime)
    10.8 +			  const char *testDescription, char *execKey, time_t startTime)
    10.9  {
   10.10  	char * output = XMLOpenElement(testElementName);
   10.11  	XMLOutputter(indentLevel++, YES, output);
    11.1 --- a/test/test-automation/xml_logger.h	Mon Jul 25 19:33:32 2011 +0300
    11.2 +++ b/test/test-automation/xml_logger.h	Mon Jul 25 20:32:31 2011 +0300
    11.3 @@ -59,7 +59,7 @@
    11.4   * \param startTime When the test started to execute
    11.5   */
    11.6  void XMLTestStarted(const char *testName, const char *suiteName,
    11.7 -					const char *testDescription, int execKey, time_t startTime);
    11.8 +					const char *testDescription, char *execKey, time_t startTime);
    11.9  
   11.10  /*!
   11.11   * Prints information about the test test that was just executed in XML