From 867997f398892a67373bc76dfcfb99b26ccfd7b5 Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Fri, 1 Aug 2014 15:00:57 +1000 Subject: [PATCH] Allow stress tests to be quarantined. --- Engine/source/testing/unitTesting.cpp | 18 +++++++++++++++--- Engine/source/testing/unitTesting.h | 18 ++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Engine/source/testing/unitTesting.cpp b/Engine/source/testing/unitTesting.cpp index 7e1cd63ab..d9304e5b3 100644 --- a/Engine/source/testing/unitTesting.cpp +++ b/Engine/source/testing/unitTesting.cpp @@ -69,12 +69,24 @@ class TorqueUnitTestListener : public ::testing::EmptyTestEventListener } }; -DefineConsoleFunction( runAllUnitTests, int, (),, - "" ) +DefineConsoleFunction( runAllUnitTests, int, (bool includeStressTests), (false), + "Runs all engine unit tests. Some tests are marked as 'stress' tests which do " + "not necessarily check correctness, just performance or possible nondeterministic " + "glitches. These tests can take some time, so they are not included unless " + "specified.\n\n" + "@param includeStressTests Run stress tests as well as unit tests. Default is false." ) { - // Set-up some empty arguments. S32 testArgc = 0; char** testArgv = NULL; + if ( includeStressTests ) + { + // Yes, I never free this memory, because it seems to be mangled by gtest. + // Also it's a negligible space leak that will only occur once. + testArgv = new char*[2]; + testArgv[0] = new char( '\0' ); + testArgv[1] = new char[26]; + dStrcpy( testArgv[1], "--gtest_filter=-*Stress.*" ); + } // Initialize Google Test. testing::InitGoogleTest( &testArgc, testArgv ); diff --git a/Engine/source/testing/unitTesting.h b/Engine/source/testing/unitTesting.h index 7002de344..5db45d775 100644 --- a/Engine/source/testing/unitTesting.h +++ b/Engine/source/testing/unitTesting.h @@ -27,16 +27,26 @@ #include +/// Convenience to define a test fixture with a Fixture suffix for use with +/// TEST_FIX. +#define FIXTURE(test_fixture)\ + class test_fixture##Fixture : public ::testing::Test + /// Allow test fixtures named with a Fixture suffix, so that we can name tests /// after a class name rather than having to call them XXTest. #define TEST_FIX(test_fixture, test_name)\ GTEST_TEST_(test_fixture, test_name, test_fixture##Fixture, \ ::testing::internal::GetTypeId()) -/// Convenience to define a test fixture with a Fixture suffix for use with -/// TEST_FIX. -#define FIXTURE(test_fixture)\ - class test_fixture##Fixture : public ::testing::Test +/// Define a stress test. The test name is suffixed with Stress, so it will be +/// excluded from normal unit test runs. +#define TEST_STRESS(test_case_name, test_name)\ + TEST(test_case_name##Stress, test_name) + +/// Define a stress test with a fixture. +#define TEST_STRESS_FIX(test_fixture, test_name)\ + GTEST_TEST_(test_fixture##Stress, test_name, test_fixture##Fixture, \ + ::testing::internal::GetTypeId()) #endif // TORQUE_TESTS_ENABLED