Runner can execute multiple test suites consecutively.
authorMarkus Kauppila
Sat, 04 Jun 2011 18:50:41 +0300
changeset 56817abfcc71aa7d
parent 5680 e61bdd43a2c3
child 5682 a04cb565aed2
Runner can execute multiple test suites consecutively.
test/test-automation/SDL_test.c
test/test-automation/SDL_test.h
test/test-automation/runner.c
     1.1 --- a/test/test-automation/SDL_test.c	Sat Jun 04 18:08:54 2011 +0300
     1.2 +++ b/test/test-automation/SDL_test.c	Sat Jun 04 18:50:41 2011 +0300
     1.3 @@ -56,15 +56,6 @@
     1.4  	return _testReturnValue;
     1.5  }
     1.6  
     1.7 -
     1.8 -/*!
     1.9 - *  Assert function. Tests if the expected value equals the actual value, then
    1.10 - *  the test assert succeeds, otherwise it fails and warns about it.
    1.11 - *
    1.12 - * \param expected Value user expects to have
    1.13 - * \param actual The actual value of tested variable
    1.14 - * \param message Message that will be printed if assert fails
    1.15 - */
    1.16  void
    1.17  AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
    1.18  {
    1.19 @@ -83,14 +74,6 @@
    1.20     }
    1.21  }
    1.22  
    1.23 -/*!
    1.24 - *  Assert function. Tests if the given condition is true. True in
    1.25 - *  this case means non-zero value. If the condition is true, the
    1.26 - *  assert passes, otherwise it fails.
    1.27 - *
    1.28 - * \param condition Condition which will be evaluated
    1.29 - * \param message Message that will be printed if assert fails
    1.30 - */
    1.31  void
    1.32  AssertTrue(int condition, char *message, ...)
    1.33  {
     2.1 --- a/test/test-automation/SDL_test.h	Sat Jun 04 18:08:54 2011 +0300
     2.2 +++ b/test/test-automation/SDL_test.h	Sat Jun 04 18:50:41 2011 +0300
     2.3 @@ -56,12 +56,22 @@
     2.4  int _TestCaseQuit();
     2.5  
     2.6  /*!
     2.7 - * todo add comment
     2.8 + *  Assert function. Tests if the expected value equals the actual value, then
     2.9 + *  the test assert succeeds, otherwise it fails and warns about it.
    2.10 + *
    2.11 + * \param expected Value user expects to have
    2.12 + * \param actual The actual value of tested variable
    2.13 + * \param message Message that will be printed if assert fails
    2.14   */
    2.15  void AssertEquals(Uint32 expected, Uint32 actual, char *message, ...);
    2.16  
    2.17  /*!
    2.18 - * todo add comment
    2.19 + *  Assert function. Tests if the given condition is true. True in
    2.20 + *  this case means non-zero value. If the condition is true, the
    2.21 + *  assert passes, otherwise it fails.
    2.22 + *
    2.23 + * \param condition Condition which will be evaluated
    2.24 + * \param message Message that will be printed if assert fails
    2.25   */
    2.26  void AssertTrue(int condition, char *message, ...);
    2.27  
     3.1 --- a/test/test-automation/runner.c	Sat Jun 04 18:08:54 2011 +0300
     3.2 +++ b/test/test-automation/runner.c	Sat Jun 04 18:50:41 2011 +0300
     3.3 @@ -37,6 +37,15 @@
     3.4  //!< Flag for executing tests in-process
     3.5  static int execute_inproc = 0;
     3.6  
     3.7 +
     3.8 +//!< Temporary array to hold test suite names
     3.9 +#if defined(linux) || defined( __linux)
    3.10 +	char *testSuites[] = { "tests/libtest.so", "tests/libtestrect.so", NULL};
    3.11 +#else
    3.12 +	char *testSuites[] = { "tests/libtest.dylib", "tests/libtestrect.dylib", NULL};
    3.13 +#endif
    3.14 +
    3.15 +
    3.16  /*!
    3.17   * Returns the name for the dynamic library
    3.18   * which implements the test suite.
    3.19 @@ -45,16 +54,11 @@
    3.20   * returns the names of the dynamic libraries
    3.21   * implementing the test suites)
    3.22   *
    3.23 - * \return Name of the dummy test suite
    3.24 + * \return Array of test suite names
    3.25   */
    3.26 -char *
    3.27 +char **
    3.28  ScanForTestSuites() {
    3.29 -#if defined(linux) || defined( __linux)
    3.30 -	char *libName = "tests/libtest.so";
    3.31 -#else
    3.32 -	char *libName = "tests/libtest.dylib";
    3.33 -#endif
    3.34 -	return libName;
    3.35 +	return testSuites;
    3.36  }
    3.37  
    3.38  
    3.39 @@ -190,6 +194,49 @@
    3.40  }
    3.41  
    3.42  /*!
    3.43 + * Executes a test case. Loads the test, executes it and
    3.44 + * returns the tests return value to the caller.
    3.45 + *
    3.46 + * \param suite The suite from which the test will be loaded
    3.47 + * \param testReference TestCaseReference of the test under execution
    3.48 + * \return The return value of the test. Zero means success, non-zero failure.
    3.49 + */
    3.50 +int
    3.51 +ExecuteTest(void *suite, TestCaseReference *testReference) {
    3.52 +	char *testname = testReference->name;
    3.53 +
    3.54 +	TestCaseInit testCaseInit = LoadTestCaseInit(suite);
    3.55 +	TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite);
    3.56 +	TestCase test = (TestCase) LoadTestCase(suite, testname);
    3.57 +
    3.58 +	int retVal = 1;
    3.59 +	if(execute_inproc) {
    3.60 +		testCaseInit();
    3.61 +
    3.62 +		test(0x0);
    3.63 +
    3.64 +		retVal = testCaseQuit();
    3.65 +	} else {
    3.66 +		int childpid = fork();
    3.67 +		if(childpid == 0) {
    3.68 +			testCaseInit();
    3.69 +
    3.70 +			test(0x0);
    3.71 +
    3.72 +			exit(testCaseQuit());
    3.73 +		} else {
    3.74 +			int stat_lock = -1;
    3.75 +			int child = wait(&stat_lock);
    3.76 +
    3.77 +			retVal = HandleTestReturnValue(stat_lock);
    3.78 +		}
    3.79 +	}
    3.80 +
    3.81 +	return retVal;
    3.82 +}
    3.83 +
    3.84 +
    3.85 +/*!
    3.86   * Prints usage information
    3.87   */
    3.88  void printUsage() {
    3.89 @@ -243,65 +290,43 @@
    3.90  
    3.91  	const Uint32 startTicks = SDL_GetTicks();
    3.92  
    3.93 -	char *testSuiteName = ScanForTestSuites();
    3.94 -	void *suite = LoadTestSuite(testSuiteName);
    3.95 -	TestCaseReference **tests = QueryTestCases(suite);
    3.96 -
    3.97 -	TestCaseReference *reference = NULL;
    3.98 -	int counter = 0;
    3.99 +	char **testSuiteNames = ScanForTestSuites();
   3.100  
   3.101 -	for(reference = tests[counter]; reference; reference = tests[++counter]) {
   3.102 -		if(reference->enabled == TEST_DISABLED) {
   3.103 -			printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
   3.104 -		} else {
   3.105 -			char *testname = reference->name;
   3.106 +	char *testSuiteName = NULL;
   3.107 +	int suiteCounter = 0;
   3.108 +	for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) {
   3.109 +		void *suite = LoadTestSuite(testSuiteName);
   3.110 +		TestCaseReference **tests = QueryTestCases(suite);
   3.111  
   3.112 -			printf("Running %s (in %s):\n", testname, testSuiteName);
   3.113 -
   3.114 -			TestCaseInit testCaseInit = LoadTestCaseInit(suite);
   3.115 -			TestCaseQuit testCaseQuit = LoadTestCaseQuit(suite);
   3.116 -			TestCase test = (TestCase) LoadTestCase(suite, testname);
   3.117 +		TestCaseReference *reference = NULL;
   3.118 +		int counter = 0;
   3.119  
   3.120 -			int retVal = 1;
   3.121 -			if(execute_inproc) {
   3.122 -				testCaseInit();
   3.123 -
   3.124 -				test(0x0);
   3.125 -
   3.126 -				retVal = testCaseQuit();
   3.127 +		for(reference = tests[counter]; reference; reference = tests[++counter]) {
   3.128 +			if(reference->enabled == TEST_DISABLED) {
   3.129 +				printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
   3.130  			} else {
   3.131 -				int childpid = fork();
   3.132 -				if(childpid == 0) {
   3.133 -					testCaseInit();
   3.134 +				printf("Executing %s (in %s):\n", reference->name, testSuiteName);
   3.135  
   3.136 -					test(0x0);
   3.137 +				int retVal = ExecuteTest(suite, reference);
   3.138  
   3.139 -					return testCaseQuit();
   3.140 +				if(retVal) {
   3.141 +					failureCount++;
   3.142 +					if(retVal == 2) {
   3.143 +						printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
   3.144 +					} else {
   3.145 +						printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
   3.146 +					}
   3.147  				} else {
   3.148 -					int stat_lock = -1;
   3.149 -					int child = wait(&stat_lock);
   3.150 -
   3.151 -					retVal = HandleTestReturnValue(stat_lock);
   3.152 +					passCount++;
   3.153 +					printf("%s (in %s): ok\n", reference->name, testSuiteName);
   3.154  				}
   3.155  			}
   3.156  
   3.157 -			if(retVal) {
   3.158 -				failureCount++;
   3.159 -				if(retVal == 2) {
   3.160 -					printf("%s (in %s): FAILED -> No asserts\n", testname, testSuiteName);
   3.161 -				} else {
   3.162 -					printf("%s (in %s): FAILED\n", testname, testSuiteName);
   3.163 -				}
   3.164 -			} else {
   3.165 -				passCount++;
   3.166 -				printf("%s (in %s): ok\n", testname, testSuiteName);
   3.167 -			}
   3.168 +			printf("\n");
   3.169  		}
   3.170  
   3.171 -		printf("\n");
   3.172 +		SDL_UnloadObject(suite);
   3.173  	}
   3.174 -	
   3.175 -	SDL_UnloadObject(suite);
   3.176  
   3.177  	const Uint32 endTicks = SDL_GetTicks();
   3.178