summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authornsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-03 21:35:23 +0000
committernsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-03 21:35:23 +0000
commitabad279b801b510207621d7b5a535bacd6aceb9c (patch)
tree7231819a0b6700fd762293c2e890861e52cd5c05 /base
parentbbd3c356a8b1e272900a7c94e5308a0d0e9b2869 (diff)
downloadchromium_src-abad279b801b510207621d7b5a535bacd6aceb9c.zip
chromium_src-abad279b801b510207621d7b5a535bacd6aceb9c.tar.gz
chromium_src-abad279b801b510207621d7b5a535bacd6aceb9c.tar.bz2
Add support for flaky gtests.
BUG:21793 Review URL: http://codereview.chromium.org/243088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27957 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/test_suite.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/base/test_suite.h b/base/test_suite.h
index 4a90a23..8967fbd 100644
--- a/base/test_suite.h
+++ b/base/test_suite.h
@@ -57,6 +57,9 @@ inline long WINAPI UnitTestExceptionFilter(EXCEPTION_POINTERS* info) {
}
#endif // OS_WIN
+// Match function used by the GetTestCount method.
+typedef bool (*TestMatch)(const testing::TestInfo&);
+
class TestSuite {
public:
TestSuite(int argc, char** argv) {
@@ -75,6 +78,38 @@ class TestSuite {
CommandLine::Terminate();
}
+ // Returns true if a string starts with FLAKY_.
+ static bool IsFlaky(const char* name) {
+ return strncmp(name, "FLAKY_", 6) == 0;
+ }
+
+ // Returns true if the test is marked as flaky.
+ static bool FlakyTest(const testing::TestInfo& test) {
+ return IsFlaky(test.name()) || IsFlaky(test.test_case_name());
+ }
+
+ // Returns true if the test failed and is not marked as flaky.
+ static bool NonFlakyFailures(const testing::TestInfo& test) {
+ return test.should_run() && test.result()->Failed() && !FlakyTest(test);
+ }
+
+ // Returns the number of tests where the match function returns true.
+ int GetTestCount(TestMatch test_match) {
+ testing::UnitTest* instance = testing::UnitTest::GetInstance();
+ int count = 0;
+
+ for (int i = 0; i < instance->total_test_case_count(); ++i) {
+ const testing::TestCase& test_case = *instance->GetTestCase(i);
+ for (int j = 0; j < test_case.total_test_count(); ++j) {
+ if (test_match(*test_case.GetTestInfo(j))) {
+ count++;
+ }
+ }
+ }
+
+ return count;
+ }
+
// Don't add additional code to this method. Instead add it to
// Initialize(). See bug 6436.
int Run() {
@@ -92,6 +127,16 @@ class TestSuite {
}
int result = RUN_ALL_TESTS();
+ // Reset the result code if only flaky test failed.
+ if (result != 0 && GetTestCount(&TestSuite::NonFlakyFailures) == 0) {
+ result = 0;
+ }
+
+ // Display the number of flaky tests.
+ int flaky_count = GetTestCount(&TestSuite::FlakyTest);
+ printf(" YOU HAVE %d FLAKY %s\n\n", flaky_count,
+ flaky_count == 1 ? "TEST" : "TESTS");
+
// This MUST happen before Shutdown() since Shutdown() tears down
// objects (such as NotificationService::current()) that Cocoa
// objects use to remove themselves as observers.