Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: base/test/test_suite.cc

Issue 11664013: GTTF: No more FLAKY_ . (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/test_suite.h" 5 #include "base/test/test_suite.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 private: 73 private:
74 CommandLine old_command_line_; 74 CommandLine old_command_line_;
75 75
76 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); 76 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer);
77 }; 77 };
78 78
79 } // namespace 79 } // namespace
80 80
81 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling";
82
83 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { 81 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) {
84 PreInitialize(argc, argv, true); 82 PreInitialize(argc, argv, true);
85 } 83 }
86 84
87 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) 85 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager)
88 : initialized_command_line_(false) { 86 : initialized_command_line_(false) {
89 PreInitialize(argc, argv, create_at_exit_manager); 87 PreInitialize(argc, argv, create_at_exit_manager);
90 } 88 }
91 89
92 TestSuite::~TestSuite() { 90 TestSuite::~TestSuite() {
(...skipping 24 matching lines...) Expand all
117 if (create_at_exit_manager) 115 if (create_at_exit_manager)
118 at_exit_manager_.reset(new base::AtExitManager); 116 at_exit_manager_.reset(new base::AtExitManager);
119 #endif 117 #endif
120 118
121 // Don't add additional code to this function. Instead add it to 119 // Don't add additional code to this function. Instead add it to
122 // Initialize(). See bug 6436. 120 // Initialize(). See bug 6436.
123 } 121 }
124 122
125 123
126 // static 124 // static
127 bool TestSuite::IsMarkedFlaky(const testing::TestInfo& test) {
128 return strncmp(test.name(), "FLAKY_", 6) == 0;
129 }
130
131 // static
132 bool TestSuite::IsMarkedMaybe(const testing::TestInfo& test) { 125 bool TestSuite::IsMarkedMaybe(const testing::TestInfo& test) {
133 return strncmp(test.name(), "MAYBE_", 6) == 0; 126 return strncmp(test.name(), "MAYBE_", 6) == 0;
134 } 127 }
135 128
136 // static
137 bool TestSuite::ShouldIgnoreFailure(const testing::TestInfo& test) {
138 if (CommandLine::ForCurrentProcess()->HasSwitch(kStrictFailureHandling))
139 return false;
140 return IsMarkedFlaky(test);
141 }
142
143 // static
144 bool TestSuite::NonIgnoredFailures(const testing::TestInfo& test) {
145 return test.should_run() && test.result()->Failed() &&
146 !ShouldIgnoreFailure(test);
147 }
148
149 int TestSuite::GetTestCount(TestMatch test_match) {
150 testing::UnitTest* instance = testing::UnitTest::GetInstance();
151 int count = 0;
152
153 for (int i = 0; i < instance->total_test_case_count(); ++i) {
154 const testing::TestCase& test_case = *instance->GetTestCase(i);
155 for (int j = 0; j < test_case.total_test_count(); ++j) {
156 if (test_match(*test_case.GetTestInfo(j))) {
157 count++;
158 }
159 }
160 }
161
162 return count;
163 }
164
165 void TestSuite::CatchMaybeTests() { 129 void TestSuite::CatchMaybeTests() {
166 testing::TestEventListeners& listeners = 130 testing::TestEventListeners& listeners =
167 testing::UnitTest::GetInstance()->listeners(); 131 testing::UnitTest::GetInstance()->listeners();
168 listeners.Append(new MaybeTestDisabler); 132 listeners.Append(new MaybeTestDisabler);
169 } 133 }
170 134
171 void TestSuite::ResetCommandLine() { 135 void TestSuite::ResetCommandLine() {
172 testing::TestEventListeners& listeners = 136 testing::TestEventListeners& listeners =
173 testing::UnitTest::GetInstance()->listeners(); 137 testing::UnitTest::GetInstance()->listeners();
174 listeners.Append(new TestClientInitializer); 138 listeners.Append(new TestClientInitializer);
(...skipping 12 matching lines...) Expand all
187 switches::kTestChildProcess); 151 switches::kTestChildProcess);
188 152
189 // Check to see if we are being run as a client process. 153 // Check to see if we are being run as a client process.
190 if (!client_func.empty()) 154 if (!client_func.empty())
191 return multi_process_function_list::InvokeChildProcessTest(client_func); 155 return multi_process_function_list::InvokeChildProcessTest(client_func);
192 #if defined(OS_IOS) 156 #if defined(OS_IOS)
193 base::test_listener_ios::RegisterTestEndListener(); 157 base::test_listener_ios::RegisterTestEndListener();
194 #endif 158 #endif
195 int result = RUN_ALL_TESTS(); 159 int result = RUN_ALL_TESTS();
196 160
197 // If there are failed tests, see if we should ignore the failures.
198 if (result != 0 && GetTestCount(&TestSuite::NonIgnoredFailures) == 0)
199 result = 0;
200
201 // Display the number of flaky tests.
202 int flaky_count = GetTestCount(&TestSuite::IsMarkedFlaky);
203 if (flaky_count) {
204 printf(" YOU HAVE %d FLAKY %s\n\n", flaky_count,
205 flaky_count == 1 ? "TEST" : "TESTS");
206 }
207
208 #if defined(OS_MACOSX) 161 #if defined(OS_MACOSX)
209 // This MUST happen before Shutdown() since Shutdown() tears down 162 // This MUST happen before Shutdown() since Shutdown() tears down
210 // objects (such as NotificationService::current()) that Cocoa 163 // objects (such as NotificationService::current()) that Cocoa
211 // objects use to remove themselves as observers. 164 // objects use to remove themselves as observers.
212 scoped_pool.Recycle(); 165 scoped_pool.Recycle();
213 #endif 166 #endif
214 167
215 Shutdown(); 168 Shutdown();
216 169
217 return result; 170 return result;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 icu_util::Initialize(); 242 icu_util::Initialize();
290 243
291 CatchMaybeTests(); 244 CatchMaybeTests();
292 ResetCommandLine(); 245 ResetCommandLine();
293 246
294 TestTimeouts::Initialize(); 247 TestTimeouts::Initialize();
295 } 248 }
296 249
297 void TestSuite::Shutdown() { 250 void TestSuite::Shutdown() {
298 } 251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698