Added randomly generated harness seed.
authorMarkus Kauppila
Wed, 27 Jul 2011 18:37:47 +0300
changeset 5786b6df0fc13504
parent 5785 7fc252ce5d1d
child 5787 46cddba50600
Added randomly generated harness seed.
test/test-automation/logger.h
test/test-automation/runner.c
     1.1 --- a/test/test-automation/logger.h	Wed Jul 27 17:48:07 2011 +0300
     1.2 +++ b/test/test-automation/logger.h	Wed Jul 27 18:37:47 2011 +0300
     1.3 @@ -40,7 +40,7 @@
     1.4   * logging interface. See the headers of implementations (plain_logger.h or
     1.5   * xml_logger.h) for more information.
     1.6   */
     1.7 -typedef	void (*RunStartedFp)(int parameterCount, char *runnerParameters[], char *runSeed, time_t eventTime, void *data);
     1.8 +typedef	void (*RunStartedFp)(int parameterCount, char *runnerParameters[], char *runSeed, time_t eventTime, LoggerData *data);
     1.9  typedef	void (*RunEndedFp)(int testCount, int suiteCount, int testPassCount, int testFailCount,
    1.10                             int testSkippedCount, time_t endTime, double totalRuntime);
    1.11  
     2.1 --- a/test/test-automation/runner.c	Wed Jul 27 17:48:07 2011 +0300
     2.2 +++ b/test/test-automation/runner.c	Wed Jul 27 18:37:47 2011 +0300
     2.3 @@ -74,6 +74,8 @@
     2.4  static int universal_timeout_enabled = 0;
     2.5  //! Flag for enabling verbose logging
     2.6  static int enable_verbose_logger = 0;
     2.7 +//! Flag for using user supplied run seed
     2.8 +static int userRunSeed = 0;
     2.9  
    2.10  
    2.11  //!< Size of the test and suite name buffers
    2.12 @@ -94,15 +96,20 @@
    2.13  //! Default directory of the test suites
    2.14  #define DEFAULT_TEST_DIRECTORY "tests/"
    2.15  
    2.16 +//! Fuzzer seed for the harness
    2.17 +char *runSeed = NULL;
    2.18 +
    2.19 +
    2.20 +//! Variable is used to pass the generated execution key to a test
    2.21  char *globalExecKey = NULL;
    2.22 -char *runSeed = "seed";
    2.23  
    2.24 +//! Execution key that user supplied via command options
    2.25  char *userExecKey = NULL;
    2.26  
    2.27  //! How man time a test will be invocated
    2.28  int testInvocationCount = 1;
    2.29  
    2.30 -// \todo move this upper!! (and add comments)
    2.31 +// \todo add comments
    2.32  int totalTestFailureCount = 0, totalTestPassCount = 0, totalTestSkipCount = 0;
    2.33  int testFailureCount = 0, testPassCount = 0, testSkipCount = 0;
    2.34  
    2.35 @@ -805,6 +812,40 @@
    2.36  
    2.37  
    2.38  /*!
    2.39 + * Generates a random run seed for the harness.
    2.40 + *
    2.41 + * \param length The length of the generated seed
    2.42 + *
    2.43 + * \returns The generated seed
    2.44 + */
    2.45 +char *
    2.46 +GenerateRunSeed(const int length)
    2.47 +{
    2.48 +	if(length <= 0) {
    2.49 +		fprintf(stderr, "Error: lenght of harness seed can't be less than zero\n");
    2.50 +		return NULL;
    2.51 +	}
    2.52 +
    2.53 +	char *seed = SDL_malloc(length * sizeof(8));
    2.54 +	if(seed == NULL) {
    2.55 +		fprintf(stderr, "Error: malloc for run seed failed\n");
    2.56 +		return NULL;
    2.57 +	}
    2.58 +
    2.59 +	RND_CTX randomContext;
    2.60 +
    2.61 +	utl_randomInitTime(&randomContext);
    2.62 +
    2.63 +	int counter = 0;
    2.64 +	for( ; counter < length; ++counter) {
    2.65 +		int number = abs(utl_random(&randomContext));
    2.66 +		seed[counter] = (char) (number % (127-34)) + 34;
    2.67 +	}
    2.68 +
    2.69 +	return seed;
    2.70 +}
    2.71 +
    2.72 +/*!
    2.73   * Sets up the logger.
    2.74   *
    2.75   * \return Logger data structure (that needs be deallocated)
    2.76 @@ -943,6 +984,8 @@
    2.77      	  universal_timeout = atoi(timeoutString);
    2.78        }
    2.79        else if(SDL_strcmp(arg, "--seed") == 0) {
    2.80 +    	  userRunSeed = 1;
    2.81 +
    2.82      	  if( (i + 1) < argc)  {
    2.83      		  runSeed = argv[++i];
    2.84      	  }  else {
    2.85 @@ -1077,6 +1120,14 @@
    2.86  	char *extension = "dylib";
    2.87  #endif
    2.88  
    2.89 +	if(userRunSeed == 0) {
    2.90 +		runSeed = GenerateRunSeed(16);
    2.91 +		if(runSeed == NULL) {
    2.92 +			fprintf(stderr, "Error: Generating harness seed failed\n");
    2.93 +			return 1;
    2.94 +		}
    2.95 +	}
    2.96 +
    2.97  	LoggerData *loggerData = SetUpLogger();
    2.98  
    2.99  	const Uint32 startTicks = SDL_GetTicks();