Possible to execute only selected tests or suites.
authorMarkus Kauppila
Sun, 05 Jun 2011 16:10:10 +0300
changeset 5682a04cb565aed2
parent 5681 7abfcc71aa7d
child 5683 1905dcc7ad20
Possible to execute only selected tests or suites.
test/test-automation/runner.c
     1.1 --- a/test/test-automation/runner.c	Sat Jun 04 18:50:41 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Sun Jun 05 16:10:10 2011 +0300
     1.3 @@ -23,6 +23,8 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6  #include <unistd.h>
     1.7 +#include <string.h>
     1.8 +
     1.9  #include <sys/types.h>
    1.10  
    1.11  #include "SDL_test.h"
    1.12 @@ -37,6 +39,17 @@
    1.13  //!< Flag for executing tests in-process
    1.14  static int execute_inproc = 0;
    1.15  
    1.16 +//!< Flag for executing only test with selected name
    1.17 +static int only_selected_test  = 0;
    1.18 +//!< Flag for executing only the selected test suite
    1.19 +static int only_selected_suite = 0;
    1.20 +
    1.21 +//<! Size of the test and suite name buffers
    1.22 +#define NAME_BUFFER_SIZE 256
    1.23 +//!< Name of the selected test
    1.24 +char selected_test_name[NAME_BUFFER_SIZE];
    1.25 +//!< Name of the selected suite
    1.26 +char selected_suite_name[NAME_BUFFER_SIZE];
    1.27  
    1.28  //!< Temporary array to hold test suite names
    1.29  #if defined(linux) || defined( __linux)
    1.30 @@ -81,6 +94,7 @@
    1.31  	return library;
    1.32  }
    1.33  
    1.34 +
    1.35  /*!
    1.36   * Loads the test case references from the given test suite.
    1.37  
    1.38 @@ -128,6 +142,7 @@
    1.39  	return test;
    1.40  }
    1.41  
    1.42 +
    1.43  /*!
    1.44   * Loads function that initialises the test case from the
    1.45   * given test suite.
    1.46 @@ -147,6 +162,7 @@
    1.47  	return testCaseInit;
    1.48  }
    1.49  
    1.50 +
    1.51  /*!
    1.52   * Loads function that deinitialises the executed test case from the
    1.53   * given test suite.
    1.54 @@ -166,6 +182,7 @@
    1.55  	return testCaseQuit;
    1.56  }
    1.57  
    1.58 +
    1.59  /*!
    1.60   * If using out-of-proc execution of tests. This function
    1.61   * will handle the return value of the child process
    1.62 @@ -193,6 +210,7 @@
    1.63  	return returnValue;
    1.64  }
    1.65  
    1.66 +
    1.67  /*!
    1.68   * Executes a test case. Loads the test, executes it and
    1.69   * returns the tests return value to the caller.
    1.70 @@ -203,11 +221,9 @@
    1.71   */
    1.72  int
    1.73  ExecuteTest(void *suite, TestCaseReference *testReference) {
    1.74 -	char *testname = testReference->name;
    1.75 -
    1.76  	TestCaseInit testCaseInit = LoadTestCaseInit(suite);
    1.77  	TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite);
    1.78 -	TestCase test = (TestCase) LoadTestCase(suite, testname);
    1.79 +	TestCase test = (TestCase) LoadTestCase(suite, testReference->name);
    1.80  
    1.81  	int retVal = 1;
    1.82  	if(execute_inproc) {
    1.83 @@ -246,6 +262,7 @@
    1.84  	  printf(" --help           Print this help\n");
    1.85  }
    1.86  
    1.87 +
    1.88  /*!
    1.89   * Parse command line arguments
    1.90   *
    1.91 @@ -265,7 +282,22 @@
    1.92        else if(SDL_strcmp(arg, "--help") == 0 || SDL_strcmp(arg, "-h") == 0) {
    1.93      	  printUsage();
    1.94      	  exit(0);
    1.95 -      } else {
    1.96 +      }
    1.97 +      else if(SDL_strcmp(arg, "--test") == 0 || SDL_strcmp(arg, "-t") == 0) {
    1.98 +    	  only_selected_test = 1;
    1.99 +    	  char *testName = argv[++i]; //!< \todo fixme what if i == argc? segfault?
   1.100 +
   1.101 +    	  memset(selected_test_name, 0, NAME_BUFFER_SIZE); // unnecessary?
   1.102 +    	  strcpy(selected_test_name, testName);
   1.103 +      }
   1.104 +      else if(SDL_strcmp(arg, "--suite") == 0 || SDL_strcmp(arg, "-s") == 0) {
   1.105 +    	  only_selected_suite = 1;
   1.106 +    	  char *suiteName = argv[++i]; //!< \todo fixme what if i == argc? segfault?
   1.107 +
   1.108 +    	  memset(selected_suite_name, 0, NAME_BUFFER_SIZE); // unnecessary?
   1.109 +    	  strcpy(selected_suite_name, suiteName);
   1.110 +      }
   1.111 +      else {
   1.112      	  printf("runner: unknown command '%s'\n", arg);
   1.113      	  printUsage();
   1.114      	  exit(0);
   1.115 @@ -273,6 +305,7 @@
   1.116     }
   1.117  }
   1.118  
   1.119 +
   1.120  /*!
   1.121   * Entry point for test runner
   1.122   *
   1.123 @@ -295,13 +328,34 @@
   1.124  	char *testSuiteName = NULL;
   1.125  	int suiteCounter = 0;
   1.126  	for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) {
   1.127 +
   1.128 +		if(only_selected_suite)	{
   1.129 +			// extract the suite name. Rips the tests/ and file suffix from the suite name
   1.130 +			char buffer[32];
   1.131 +			int len = strlen(testSuiteName);
   1.132 +			int copy = len - 6 - 6;
   1.133 +			memcpy(buffer, testSuiteName + 6, copy);
   1.134 +			//printf("%s\n", buffer);
   1.135 +			//char *name = strndup(testSuiteName[5], 32);
   1.136 +
   1.137 +			if(SDL_strncmp(selected_suite_name, buffer, NAME_BUFFER_SIZE) != 0) {
   1.138 +				continue;
   1.139 +			}
   1.140 +		}
   1.141 +
   1.142  		void *suite = LoadTestSuite(testSuiteName);
   1.143  		TestCaseReference **tests = QueryTestCases(suite);
   1.144  
   1.145  		TestCaseReference *reference = NULL;
   1.146  		int counter = 0;
   1.147 +		for(reference = tests[counter]; reference; reference = tests[++counter]) {
   1.148  
   1.149 -		for(reference = tests[counter]; reference; reference = tests[++counter]) {
   1.150 +			if(only_selected_test) {
   1.151 +				if(SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
   1.152 +					continue;
   1.153 +				}
   1.154 +			}
   1.155 +
   1.156  			if(reference->enabled == TEST_DISABLED) {
   1.157  				printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
   1.158  			} else {