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

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

Issue 1806353003: Adds option to run browser tests in mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 9 months 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
16 #include "base/environment.h" 17 #include "base/environment.h"
17 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
18 #include "base/files/scoped_temp_dir.h" 19 #include "base/files/scoped_temp_dir.h"
19 #include "base/logging.h" 20 #include "base/logging.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "base/memory/linked_ptr.h" 22 #include "base/memory/linked_ptr.h"
22 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
23 #include "base/message_loop/message_loop.h" 24 #include "base/message_loop/message_loop.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 " Controls when full test output is printed.\n" 108 " Controls when full test output is printed.\n"
108 " auto means to print it when the test failed.\n" 109 " auto means to print it when the test failed.\n"
109 "\n" 110 "\n"
110 " --test-launcher-total-shards=N\n" 111 " --test-launcher-total-shards=N\n"
111 " Sets the total number of shards to N.\n" 112 " Sets the total number of shards to N.\n"
112 "\n" 113 "\n"
113 " --test-launcher-shard-index=N\n" 114 " --test-launcher-shard-index=N\n"
114 " Sets the shard index to run to N (from 0 to TOTAL - 1).\n"); 115 " Sets the shard index to run to N (from 0 to TOTAL - 1).\n");
115 } 116 }
116 117
118 void CallChildProcessLaunched(TestState* test_state,
119 base::ProcessHandle handle,
120 base::ProcessId pid) {
121 if (test_state)
122 test_state->ChildProcessLaunched(handle, pid);
123 }
124
117 // Implementation of base::TestLauncherDelegate. This is also a test launcher, 125 // Implementation of base::TestLauncherDelegate. This is also a test launcher,
118 // wrapping a lower-level test launcher with content-specific code. 126 // wrapping a lower-level test launcher with content-specific code.
119 class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { 127 class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
120 public: 128 public:
121 explicit WrapperTestLauncherDelegate( 129 explicit WrapperTestLauncherDelegate(
122 content::TestLauncherDelegate* launcher_delegate) 130 content::TestLauncherDelegate* launcher_delegate)
123 : launcher_delegate_(launcher_delegate) { 131 : launcher_delegate_(launcher_delegate) {
124 CHECK(temp_dir_.CreateUniqueTempDir()); 132 CHECK(temp_dir_.CreateUniqueTempDir());
125 } 133 }
126 134
(...skipping 10 matching lines...) Expand all
137 void DoRunTests(base::TestLauncher* test_launcher, 145 void DoRunTests(base::TestLauncher* test_launcher,
138 const std::vector<std::string>& test_names); 146 const std::vector<std::string>& test_names);
139 147
140 // Launches test named |test_name| using parallel launcher, 148 // Launches test named |test_name| using parallel launcher,
141 // given result of PRE_ test |pre_test_result|. 149 // given result of PRE_ test |pre_test_result|.
142 void RunDependentTest(base::TestLauncher* test_launcher, 150 void RunDependentTest(base::TestLauncher* test_launcher,
143 const std::string test_name, 151 const std::string test_name,
144 const base::TestResult& pre_test_result); 152 const base::TestResult& pre_test_result);
145 153
146 // Callback to receive result of a test. 154 // Callback to receive result of a test.
147 void GTestCallback( 155 void GTestCallback(base::TestLauncher* test_launcher,
148 base::TestLauncher* test_launcher, 156 const std::vector<std::string>& test_names,
149 const std::vector<std::string>& test_names, 157 const std::string& test_name,
150 const std::string& test_name, 158 scoped_ptr<TestState> test_state,
151 int exit_code, 159 int exit_code,
152 const base::TimeDelta& elapsed_time, 160 const base::TimeDelta& elapsed_time,
153 bool was_timeout, 161 bool was_timeout,
154 const std::string& output); 162 const std::string& output);
155 163
156 content::TestLauncherDelegate* launcher_delegate_; 164 content::TestLauncherDelegate* launcher_delegate_;
157 165
158 // Store dependent test name (map is indexed by full test name). 166 // Store dependent test name (map is indexed by full test name).
159 typedef std::map<std::string, std::string> DependentTestMap; 167 typedef std::map<std::string, std::string> DependentTestMap;
160 DependentTestMap dependent_test_map_; 168 DependentTestMap dependent_test_map_;
161 DependentTestMap reverse_dependent_test_map_; 169 DependentTestMap reverse_dependent_test_map_;
162 170
163 // Store unique data directory prefix for test names (without PRE_ prefixes). 171 // Store unique data directory prefix for test names (without PRE_ prefixes).
164 // PRE_ tests and tests that depend on them must share the same 172 // PRE_ tests and tests that depend on them must share the same
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 if (test_names.empty()) 342 if (test_names.empty())
335 return; 343 return;
336 344
337 std::string test_name(test_names.front()); 345 std::string test_name(test_names.front());
338 std::vector<std::string> test_names_copy( 346 std::vector<std::string> test_names_copy(
339 test_names.begin() + 1, test_names.end()); 347 test_names.begin() + 1, test_names.end());
340 348
341 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name)); 349 std::string test_name_no_pre(RemoveAnyPrePrefixes(test_name));
342 350
343 base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess()); 351 base::CommandLine cmd_line(*base::CommandLine::ForCurrentProcess());
352 base::TestLauncher::LaunchOptions test_launch_options;
353 test_launch_options.flags = base::TestLauncher::USE_JOB_OBJECTS |
354 base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB;
355 scoped_ptr<TestState> test_state_ptr =
356 launcher_delegate_->PreRunTest(&cmd_line, &test_launch_options);
344 CHECK(launcher_delegate_->AdjustChildProcessCommandLine( 357 CHECK(launcher_delegate_->AdjustChildProcessCommandLine(
345 &cmd_line, user_data_dir_map_[test_name_no_pre])); 358 &cmd_line, user_data_dir_map_[test_name_no_pre]));
346 359
347 base::CommandLine new_cmd_line(cmd_line.GetProgram()); 360 base::CommandLine new_cmd_line(cmd_line.GetProgram());
348 base::CommandLine::SwitchMap switches = cmd_line.GetSwitches(); 361 base::CommandLine::SwitchMap switches = cmd_line.GetSwitches();
349 362
350 // Strip out gtest_output flag because otherwise we would overwrite results 363 // Strip out gtest_output flag because otherwise we would overwrite results
351 // of the other tests. 364 // of the other tests.
352 switches.erase(base::kGTestOutputFlag); 365 switches.erase(base::kGTestOutputFlag);
353 366
354 for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin(); 367 for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin();
355 iter != switches.end(); ++iter) { 368 iter != switches.end(); ++iter) {
356 new_cmd_line.AppendSwitchNative(iter->first, iter->second); 369 new_cmd_line.AppendSwitchNative(iter->first, iter->second);
357 } 370 }
358 371
359 // Always enable disabled tests. This method is not called with disabled 372 // Always enable disabled tests. This method is not called with disabled
360 // tests unless this flag was specified to the browser test executable. 373 // tests unless this flag was specified to the browser test executable.
361 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); 374 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests");
362 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); 375 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name);
363 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); 376 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag);
364 377
365 char* browser_wrapper = getenv("BROWSER_WRAPPER"); 378 char* browser_wrapper = getenv("BROWSER_WRAPPER");
366 379
367 base::TestLauncher::LaunchOptions test_launch_options; 380 TestState* test_state = test_state_ptr.get();
368 test_launch_options.flags = base::TestLauncher::USE_JOB_OBJECTS |
369 base::TestLauncher::ALLOW_BREAKAWAY_FROM_JOB;
370 test_launcher->LaunchChildGTestProcess( 381 test_launcher->LaunchChildGTestProcess(
371 new_cmd_line, browser_wrapper ? browser_wrapper : std::string(), 382 new_cmd_line, browser_wrapper ? browser_wrapper : std::string(),
372 TestTimeouts::action_max_timeout(), test_launch_options, 383 TestTimeouts::action_max_timeout(), test_launch_options,
373 base::Bind(&WrapperTestLauncherDelegate::GTestCallback, 384 base::Bind(&WrapperTestLauncherDelegate::GTestCallback,
374 base::Unretained(this), test_launcher, test_names_copy, 385 base::Unretained(this), test_launcher, test_names_copy,
375 test_name), 386 test_name, base::Passed(&test_state_ptr)),
376 base::TestLauncher::GTestProcessLaunchedCallback()); 387 base::Bind(&CallChildProcessLaunched, base::Unretained(test_state)));
377 } 388 }
378 389
379 void WrapperTestLauncherDelegate::RunDependentTest( 390 void WrapperTestLauncherDelegate::RunDependentTest(
380 base::TestLauncher* test_launcher, 391 base::TestLauncher* test_launcher,
381 const std::string test_name, 392 const std::string test_name,
382 const base::TestResult& pre_test_result) { 393 const base::TestResult& pre_test_result) {
383 if (pre_test_result.status == base::TestResult::TEST_SUCCESS) { 394 if (pre_test_result.status == base::TestResult::TEST_SUCCESS) {
384 // Only run the dependent test if PRE_ test succeeded. 395 // Only run the dependent test if PRE_ test succeeded.
385 std::vector<std::string> test_list; 396 std::vector<std::string> test_list;
386 test_list.push_back(test_name); 397 test_list.push_back(test_name);
(...skipping 10 matching lines...) Expand all
397 dependent_test_map_[test_name], 408 dependent_test_map_[test_name],
398 test_result); 409 test_result);
399 } 410 }
400 } 411 }
401 } 412 }
402 413
403 void WrapperTestLauncherDelegate::GTestCallback( 414 void WrapperTestLauncherDelegate::GTestCallback(
404 base::TestLauncher* test_launcher, 415 base::TestLauncher* test_launcher,
405 const std::vector<std::string>& test_names, 416 const std::vector<std::string>& test_names,
406 const std::string& test_name, 417 const std::string& test_name,
418 scoped_ptr<TestState> test_state,
407 int exit_code, 419 int exit_code,
408 const base::TimeDelta& elapsed_time, 420 const base::TimeDelta& elapsed_time,
409 bool was_timeout, 421 bool was_timeout,
410 const std::string& output) { 422 const std::string& output) {
411 base::TestResult result; 423 base::TestResult result;
412 result.full_name = test_name; 424 result.full_name = test_name;
413 425
414 // TODO(phajdan.jr): Recognize crashes. 426 // TODO(phajdan.jr): Recognize crashes.
415 if (exit_code == 0) 427 if (exit_code == 0)
416 result.status = base::TestResult::TEST_SUCCESS; 428 result.status = base::TestResult::TEST_SUCCESS;
(...skipping 30 matching lines...) Expand all
447 459
448 const char kHelpFlag[] = "help"; 460 const char kHelpFlag[] = "help";
449 461
450 const char kLaunchAsBrowser[] = "as-browser"; 462 const char kLaunchAsBrowser[] = "as-browser";
451 463
452 // See kManualTestPrefix above. 464 // See kManualTestPrefix above.
453 const char kRunManualTestsFlag[] = "run-manual"; 465 const char kRunManualTestsFlag[] = "run-manual";
454 466
455 const char kSingleProcessTestsFlag[] = "single_process"; 467 const char kSingleProcessTestsFlag[] = "single_process";
456 468
469 scoped_ptr<TestState> TestLauncherDelegate::PreRunTest(
470 base::CommandLine* command_line,
471 base::TestLauncher::LaunchOptions* test_launch_options) {
472 return nullptr;
473 }
457 474
458 TestLauncherDelegate::~TestLauncherDelegate() { 475 TestLauncherDelegate::~TestLauncherDelegate() {
459 } 476 }
460 477
461 int LaunchTests(TestLauncherDelegate* launcher_delegate, 478 int LaunchTests(TestLauncherDelegate* launcher_delegate,
462 int default_jobs, 479 int default_jobs,
463 int argc, 480 int argc,
464 char** argv) { 481 char** argv) {
465 DCHECK(!g_launcher_delegate); 482 DCHECK(!g_launcher_delegate);
466 g_launcher_delegate = launcher_delegate; 483 g_launcher_delegate = launcher_delegate;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 546
530 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { 547 TestLauncherDelegate* GetCurrentTestLauncherDelegate() {
531 return g_launcher_delegate; 548 return g_launcher_delegate;
532 } 549 }
533 550
534 ContentMainParams* GetContentMainParams() { 551 ContentMainParams* GetContentMainParams() {
535 return g_params; 552 return g_params;
536 } 553 }
537 554
538 } // namespace content 555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698