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

Side by Side Diff: content/public/test/test_launcher.cc

Issue 1406973006: Make retries in content (and above) test launcher really serial (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 5 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/test/test_launcher.h" 5 #include "content/public/test/test_launcher.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // base::TestLauncherDelegate: 123 // base::TestLauncherDelegate:
124 bool GetTests(std::vector<base::TestIdentifier>* output) override; 124 bool GetTests(std::vector<base::TestIdentifier>* output) override;
125 bool ShouldRunTest(const std::string& test_case_name, 125 bool ShouldRunTest(const std::string& test_case_name,
126 const std::string& test_name) override; 126 const std::string& test_name) override;
127 size_t RunTests(base::TestLauncher* test_launcher, 127 size_t RunTests(base::TestLauncher* test_launcher,
128 const std::vector<std::string>& test_names) override; 128 const std::vector<std::string>& test_names) override;
129 size_t RetryTests(base::TestLauncher* test_launcher, 129 size_t RetryTests(base::TestLauncher* test_launcher,
130 const std::vector<std::string>& test_names) override; 130 const std::vector<std::string>& test_names) override;
131 131
132 private: 132 private:
133 void DoRunTest(base::TestLauncher* test_launcher, 133 void DoRunTests(base::TestLauncher* test_launcher,
134 const std::string& test_name); 134 const std::vector<std::string>& test_names);
135 135
136 // Launches test named |test_name| using parallel launcher, 136 // Launches test named |test_name| using parallel launcher,
137 // given result of PRE_ test |pre_test_result|. 137 // given result of PRE_ test |pre_test_result|.
138 void RunDependentTest(base::TestLauncher* test_launcher, 138 void RunDependentTest(base::TestLauncher* test_launcher,
139 const std::string test_name, 139 const std::string test_name,
140 const base::TestResult& pre_test_result); 140 const base::TestResult& pre_test_result);
141 141
142 // Callback to receive result of a test. 142 // Callback to receive result of a test.
143 void GTestCallback( 143 void GTestCallback(
144 base::TestLauncher* test_launcher, 144 base::TestLauncher* test_launcher,
145 const std::vector<std::string>& test_names,
145 const std::string& test_name, 146 const std::string& test_name,
146 int exit_code, 147 int exit_code,
147 const base::TimeDelta& elapsed_time, 148 const base::TimeDelta& elapsed_time,
148 bool was_timeout, 149 bool was_timeout,
149 const std::string& output); 150 const std::string& output);
150 151
151 content::TestLauncherDelegate* launcher_delegate_; 152 content::TestLauncherDelegate* launcher_delegate_;
152 153
153 // Store dependent test name (map is indexed by full test name). 154 // Store dependent test name (map is indexed by full test name).
154 typedef std::map<std::string, std::string> DependentTestMap; 155 typedef std::map<std::string, std::string> DependentTestMap;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 base::FilePath temp_dir; 248 base::FilePath temp_dir;
248 CHECK(base::CreateTemporaryDirInDir(temp_dir_.path(), 249 CHECK(base::CreateTemporaryDirInDir(temp_dir_.path(),
249 FILE_PATH_LITERAL("d"), &temp_dir)); 250 FILE_PATH_LITERAL("d"), &temp_dir));
250 user_data_dir_map_[full_name] = temp_dir; 251 user_data_dir_map_[full_name] = temp_dir;
251 } 252 }
252 253
253 // If the test has any dependencies, get to the root and start with that. 254 // If the test has any dependencies, get to the root and start with that.
254 while (ContainsKey(reverse_dependent_test_map_, full_name)) 255 while (ContainsKey(reverse_dependent_test_map_, full_name))
255 full_name = GetPreTestName(full_name); 256 full_name = GetPreTestName(full_name);
256 257
257 DoRunTest(test_launcher, full_name); 258 std::vector<std::string> test_list;
259 test_list.push_back(full_name);
260 DoRunTests(test_launcher, test_list);
258 } 261 }
259 262
260 return test_names.size() + additional_tests_to_run_count; 263 return test_names.size() + additional_tests_to_run_count;
261 } 264 }
262 265
263 size_t WrapperTestLauncherDelegate::RetryTests( 266 size_t WrapperTestLauncherDelegate::RetryTests(
264 base::TestLauncher* test_launcher, 267 base::TestLauncher* test_launcher,
265 const std::vector<std::string>& test_names) { 268 const std::vector<std::string>& test_names) {
266 // List of tests we can kick off right now, depending on no other tests. 269 // List of tests we can kick off right now, depending on no other tests.
267 std::vector<std::string> tests_to_run_now; 270 std::vector<std::string> tests_to_run_now;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 size_t dot_pos = full_name.find('.'); 312 size_t dot_pos = full_name.find('.');
310 CHECK_NE(dot_pos, std::string::npos); 313 CHECK_NE(dot_pos, std::string::npos);
311 std::string test_case_name = full_name.substr(0, dot_pos); 314 std::string test_case_name = full_name.substr(0, dot_pos);
312 std::string test_name = full_name.substr(dot_pos + 1); 315 std::string test_name = full_name.substr(dot_pos + 1);
313 std::string pre_test_name( 316 std::string pre_test_name(
314 test_case_name + "." + kPreTestPrefix + test_name); 317 test_case_name + "." + kPreTestPrefix + test_name);
315 if (!ContainsKey(test_names_set, pre_test_name)) 318 if (!ContainsKey(test_names_set, pre_test_name))
316 tests_to_run_now.push_back(full_name); 319 tests_to_run_now.push_back(full_name);
317 } 320 }
318 321
319 for (size_t i = 0; i < tests_to_run_now.size(); i++) 322 DoRunTests(test_launcher, tests_to_run_now);
320 DoRunTest(test_launcher, tests_to_run_now[i]);
321 323
322 return test_names_set.size(); 324 return test_names_set.size();
323 } 325 }
324 326
325 void WrapperTestLauncherDelegate::DoRunTest(base::TestLauncher* test_launcher, 327 void WrapperTestLauncherDelegate::DoRunTests(
326 const std::string& test_name) { 328 base::TestLauncher* test_launcher,
329 const std::vector<std::string>& test_names) {
330 if (test_names.empty())
331 return;
332
333 std::string test_name(test_names.front());
334 std::vector<std::string> test_names_copy(
335 test_names.begin() + 1, test_names.end());
336
327 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name)); 337 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name));
328 338
329 base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess()); 339 base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess());
330 CHECK(launcher_delegate_->AdjustChildProcessCommandLine( 340 CHECK(launcher_delegate_->AdjustChildProcessCommandLine(
331 &cmd_line, user_data_dir_map_[test_name_no_pre])); 341 &cmd_line, user_data_dir_map_[test_name_no_pre]));
332 342
333 base::CommandLine new_cmd_line(cmd_line.GetProgram()); 343 base::CommandLine new_cmd_line(cmd_line.GetProgram());
334 base::CommandLine::SwitchMap switches = cmd_line.GetSwitches(); 344 base::CommandLine::SwitchMap switches = cmd_line.GetSwitches();
335 345
336 // Strip out gtest_output flag because otherwise we would overwrite results 346 // Strip out gtest_output flag because otherwise we would overwrite results
(...skipping 15 matching lines...) Expand all
352 362
353 test_launcher->LaunchChildGTestProcess( 363 test_launcher->LaunchChildGTestProcess(
354 new_cmd_line, 364 new_cmd_line,
355 browser_wrapper ? browser_wrapper : std::string(), 365 browser_wrapper ? browser_wrapper : std::string(),
356 TestTimeouts::action_max_timeout(), 366 TestTimeouts::action_max_timeout(),
357 base::TestLauncher::USE_JOB_OBJECTS | 367 base::TestLauncher::USE_JOB_OBJECTS |
358 base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB, 368 base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB,
359 base::Bind(&WrapperTestLauncherDelegate::GTestCallback, 369 base::Bind(&WrapperTestLauncherDelegate::GTestCallback,
360 base::Unretained(this), 370 base::Unretained(this),
361 test_launcher, 371 test_launcher,
372 test_names_copy,
362 test_name)); 373 test_name));
363 } 374 }
364 375
365 void WrapperTestLauncherDelegate::RunDependentTest( 376 void WrapperTestLauncherDelegate::RunDependentTest(
366 base::TestLauncher* test_launcher, 377 base::TestLauncher* test_launcher,
367 const std::string test_name, 378 const std::string test_name,
368 const base::TestResult& pre_test_result) { 379 const base::TestResult& pre_test_result) {
369 if (pre_test_result.status == base::TestResult::TEST_SUCCESS) { 380 if (pre_test_result.status == base::TestResult::TEST_SUCCESS) {
370 // Only run the dependent test if PRE_ test succeeded. 381 // Only run the dependent test if PRE_ test succeeded.
371 DoRunTest(test_launcher, test_name); 382 std::vector<std::string> test_list;
383 test_list.push_back(test_name);
384 DoRunTests(test_launcher, test_list);
372 } else { 385 } else {
373 // Otherwise skip the test. 386 // Otherwise skip the test.
374 base::TestResult test_result; 387 base::TestResult test_result;
375 test_result.full_name = test_name; 388 test_result.full_name = test_name;
376 test_result.status = base::TestResult::TEST_SKIPPED; 389 test_result.status = base::TestResult::TEST_SKIPPED;
377 test_launcher->OnTestFinished(test_result); 390 test_launcher->OnTestFinished(test_result);
378 391
379 if (ContainsKey(dependent_test_map_, test_name)) { 392 if (ContainsKey(dependent_test_map_, test_name)) {
380 RunDependentTest(test_launcher, 393 RunDependentTest(test_launcher,
381 dependent_test_map_[test_name], 394 dependent_test_map_[test_name],
382 test_result); 395 test_result);
383 } 396 }
384 } 397 }
385 } 398 }
386 399
387 void WrapperTestLauncherDelegate::GTestCallback( 400 void WrapperTestLauncherDelegate::GTestCallback(
388 base::TestLauncher* test_launcher, 401 base::TestLauncher* test_launcher,
402 const std::vector<std::string>& test_names,
389 const std::string& test_name, 403 const std::string& test_name,
390 int exit_code, 404 int exit_code,
391 const base::TimeDelta& elapsed_time, 405 const base::TimeDelta& elapsed_time,
392 bool was_timeout, 406 bool was_timeout,
393 const std::string& output) { 407 const std::string& output) {
394 base::TestResult result; 408 base::TestResult result;
395 result.full_name = test_name; 409 result.full_name = test_name;
396 410
397 // TODO(phajdan.jr): Recognize crashes. 411 // TODO(phajdan.jr): Recognize crashes.
398 if (exit_code == 0) 412 if (exit_code == 0)
(...skipping 16 matching lines...) Expand all
415 if (ContainsKey(user_data_dir_map_, test_name_no_pre)) { 429 if (ContainsKey(user_data_dir_map_, test_name_no_pre)) {
416 if (!base::DeleteFile(user_data_dir_map_[test_name_no_pre], true)) { 430 if (!base::DeleteFile(user_data_dir_map_[test_name_no_pre], true)) {
417 LOG(WARNING) << "Failed to delete " 431 LOG(WARNING) << "Failed to delete "
418 << user_data_dir_map_[test_name_no_pre].value(); 432 << user_data_dir_map_[test_name_no_pre].value();
419 } 433 }
420 user_data_dir_map_.erase(test_name_no_pre); 434 user_data_dir_map_.erase(test_name_no_pre);
421 } 435 }
422 } 436 }
423 437
424 test_launcher->OnTestFinished(result); 438 test_launcher->OnTestFinished(result);
439
440 DoRunTests(test_launcher, test_names);
425 } 441 }
426 442
427 } // namespace 443 } // namespace
428 444
429 const char kHelpFlag[] = "help"; 445 const char kHelpFlag[] = "help";
430 446
431 const char kLaunchAsBrowser[] = "as-browser"; 447 const char kLaunchAsBrowser[] = "as-browser";
432 448
433 // See kManualTestPrefix above. 449 // See kManualTestPrefix above.
434 const char kRunManualTestsFlag[] = "run-manual"; 450 const char kRunManualTestsFlag[] = "run-manual";
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 526
511 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { 527 TestLauncherDelegate* GetCurrentTestLauncherDelegate() {
512 return g_launcher_delegate; 528 return g_launcher_delegate;
513 } 529 }
514 530
515 ContentMainParams* GetContentMainParams() { 531 ContentMainParams* GetContentMainParams() {
516 return g_params; 532 return g_params;
517 } 533 }
518 534
519 } // namespace content 535 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698