Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Test cases executed in their own process can now bail out if
Browse files Browse the repository at this point in the history
assertion fails.

Note: Bailing out doesn't work with --in-proc option.
  • Loading branch information
mkauppila committed Aug 28, 2011
1 parent 1e85b6f commit 6a4f5fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/test-automation/include/SDL_test.h
Expand Up @@ -69,7 +69,7 @@ typedef struct TestCaseReference {
*
* \param execKey Execution key for the test
*/
void _InitTestEnvironment(Uint64 execKey);
void _InitTestEnvironment(Uint64 execKey, SDL_bool inproc);

/*!
* Deinitializes the test environment and
Expand Down
20 changes: 18 additions & 2 deletions test/test-automation/src/libSDLtest/SDL_test.c
Expand Up @@ -40,11 +40,16 @@ int _testAssertsFailed;
/*! \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;
Expand Down Expand Up @@ -87,14 +92,18 @@ AssertEquals(int expected, int actual, char *message, ...)

_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));

_testAssertsPassed++;
}
}


void
AssertTrue(int condition, char *message, ...)
{
Expand All @@ -109,6 +118,9 @@ AssertTrue(int condition, char *message, ...)

_testReturnValue = TEST_RESULT_FAILURE;
_testAssertsFailed++;

if(canBailOut)
exit(TEST_RESULT_FAILURE); // bail out from the test
} else {
Assert("AssertTrue", 1, buf, time(0));

Expand All @@ -131,6 +143,7 @@ AssertPass(char *message, ...)
_testAssertsPassed++;
}


void
AssertFail(char *message, ...)
{
Expand All @@ -145,5 +158,8 @@ AssertFail(char *message, ...)

_testReturnValue = TEST_RESULT_FAILURE;
_testAssertsFailed++;

if(canBailOut)
exit(TEST_RESULT_FAILURE); // bail out from the test
}

4 changes: 2 additions & 2 deletions test/test-automation/src/runner/runner.c
Expand Up @@ -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
Expand Down Expand Up @@ -825,7 +825,7 @@ RunTest(TestCase *testCase, Uint64 execKey)
}
}

testCase->initTestEnvironment(execKey);
testCase->initTestEnvironment(execKey, execute_inproc);

if(testCase->testSetUp) {
testCase->testSetUp(0x0);
Expand Down
2 changes: 2 additions & 0 deletions test/test-automation/tests/testdummy/testdummy.c
Expand Up @@ -142,6 +142,8 @@ test_dummy2(void *arg)
char *msg = "eello";
//msg[0] = 'H';
AssertTrue(1, "Assert message");
AssertTrue(0, "Assert message");
AssertTrue(1, "Assert message");
}

void
Expand Down

0 comments on commit 6a4f5fd

Please sign in to comment.