Test cases executed in their own process can now bail out if
authorMarkus Kauppila <markus.kauppila@gmail.com>
Sun, 28 Aug 2011 21:00:38 +0300
changeset 5845 02eace7c44a5
parent 5844 fa860270f65c
child 5846 33be0a40bc11
Test cases executed in their own process can now bail out if assertion fails. Note: Bailing out doesn't work with --in-proc option.
test/test-automation/include/SDL_test.h
test/test-automation/src/libSDLtest/SDL_test.c
test/test-automation/src/runner/runner.c
test/test-automation/tests/testdummy/testdummy.c
--- a/test/test-automation/include/SDL_test.h	Sun Aug 28 20:27:25 2011 +0300
+++ b/test/test-automation/include/SDL_test.h	Sun Aug 28 21:00:38 2011 +0300
@@ -69,7 +69,7 @@
  *
  *  \param execKey Execution key for the test
  */
-void _InitTestEnvironment(Uint64 execKey);
+void _InitTestEnvironment(Uint64 execKey, SDL_bool inproc);
 
 /*!
  *  Deinitializes the test environment and
--- a/test/test-automation/src/libSDLtest/SDL_test.c	Sun Aug 28 20:27:25 2011 +0300
+++ b/test/test-automation/src/libSDLtest/SDL_test.c	Sun Aug 28 21:00:38 2011 +0300
@@ -40,11 +40,16 @@
 /*! \brief counts the passed asserts */
 int _testAssertsPassed;
 
+/*! \brief is the execution done in-process? */
+SDL_bool canBailOut;
+
 void
-_InitTestEnvironment(Uint64 execKey)
+_InitTestEnvironment(Uint64 execKey, SDL_bool inproc)
 {
 	InitFuzzer(execKey);
 
+	canBailOut = inproc == 0;
+
 	_testReturnValue = TEST_RESULT_PASS;
 	_testAssertsFailed = 0;
 	_testAssertsPassed = 0;
@@ -87,7 +92,10 @@
 
       _testReturnValue = TEST_RESULT_FAILURE;
       _testAssertsFailed++;
-   } else {
+
+      if(canBailOut)
+    	  exit(TEST_RESULT_FAILURE); // bail out from the test
+      } else {
 	   AssertWithValues("AssertEquals", 1, buf,
     		  actual, expected, time(0));
 
@@ -95,6 +103,7 @@
    }
 }
 
+
 void
 AssertTrue(int condition, char *message, ...)
 {
@@ -109,6 +118,9 @@
 
       _testReturnValue = TEST_RESULT_FAILURE;
       _testAssertsFailed++;
+
+      if(canBailOut)
+    	  exit(TEST_RESULT_FAILURE); // bail out from the test
    } else {
 		Assert("AssertTrue", 1, buf, time(0));
 
@@ -131,6 +143,7 @@
    _testAssertsPassed++;
 }
 
+
 void
 AssertFail(char *message, ...)
 {
@@ -145,5 +158,8 @@
 
    _testReturnValue = TEST_RESULT_FAILURE;
    _testAssertsFailed++;
+
+   if(canBailOut)
+	   exit(TEST_RESULT_FAILURE); // bail out from the test
 }
 
--- a/test/test-automation/src/runner/runner.c	Sun Aug 28 20:27:25 2011 +0300
+++ b/test/test-automation/src/runner/runner.c	Sun Aug 28 21:00:38 2011 +0300
@@ -44,7 +44,7 @@
 //!< Function pointer to a test case function
 typedef void (*TestCaseFp)(void *arg);
 //!< Function pointer to a test case init function
-typedef void (*InitTestInvironmentFp)(Uint64);
+typedef void (*InitTestInvironmentFp)(Uint64, SDL_bool);
 //!< Function pointer to a test case quit function
 typedef int  (*QuitTestInvironmentFp)(void);
 //!< Function pointer to a test case set up function
@@ -825,7 +825,7 @@
 		}
 	}
 
-	testCase->initTestEnvironment(execKey);
+	testCase->initTestEnvironment(execKey, execute_inproc);
 
 	if(testCase->testSetUp) {
 		testCase->testSetUp(0x0);
--- a/test/test-automation/tests/testdummy/testdummy.c	Sun Aug 28 20:27:25 2011 +0300
+++ b/test/test-automation/tests/testdummy/testdummy.c	Sun Aug 28 21:00:38 2011 +0300
@@ -142,6 +142,8 @@
 	char *msg = "eello";
 	//msg[0] = 'H';
 	AssertTrue(1, "Assert message");
+	AssertTrue(0, "Assert message");
+	AssertTrue(1, "Assert message");
 }
 
 void