| OLD | NEW |
| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/environment.h" | 13 #include "base/environment.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/test/launcher/parallel_test_launcher.h" | |
| 25 #include "base/test/launcher/test_launcher.h" | 24 #include "base/test/launcher/test_launcher.h" |
| 26 #include "base/test/test_suite.h" | 25 #include "base/test/test_suite.h" |
| 27 #include "base/test/test_switches.h" | 26 #include "base/test/test_switches.h" |
| 28 #include "base/test/test_timeouts.h" | 27 #include "base/test/test_timeouts.h" |
| 29 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| 30 #include "content/public/app/content_main.h" | 29 #include "content/public/app/content_main.h" |
| 31 #include "content/public/app/content_main_delegate.h" | 30 #include "content/public/app/content_main_delegate.h" |
| 32 #include "content/public/app/startup_helper_win.h" | 31 #include "content/public/app/startup_helper_win.h" |
| 33 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/sandbox_init.h" | 33 #include "content/public/common/sandbox_init.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 " --help\n" | 79 " --help\n" |
| 81 " Shows this message.\n" | 80 " Shows this message.\n" |
| 82 " --gtest_help\n" | 81 " --gtest_help\n" |
| 83 " Shows the gtest help message.\n"); | 82 " Shows the gtest help message.\n"); |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Implementation of base::TestLauncherDelegate. This is also a test launcher, | 85 // Implementation of base::TestLauncherDelegate. This is also a test launcher, |
| 87 // wrapping a lower-level test launcher with content-specific code. | 86 // wrapping a lower-level test launcher with content-specific code. |
| 88 class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { | 87 class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { |
| 89 public: | 88 public: |
| 90 WrapperTestLauncherDelegate(content::TestLauncherDelegate* launcher_delegate, | 89 explicit WrapperTestLauncherDelegate( |
| 91 size_t jobs) | 90 content::TestLauncherDelegate* launcher_delegate) |
| 92 : launcher_delegate_(launcher_delegate), | 91 : launcher_delegate_(launcher_delegate) { |
| 93 parallel_launcher_(jobs) { | |
| 94 CHECK(temp_dir_.CreateUniqueTempDir()); | 92 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 95 } | 93 } |
| 96 | 94 |
| 97 // base::TestLauncherDelegate: | 95 // base::TestLauncherDelegate: |
| 98 virtual void OnTestIterationStarting() OVERRIDE; | 96 virtual void OnTestIterationStarting() OVERRIDE; |
| 99 virtual std::string GetTestNameForFiltering( | 97 virtual std::string GetTestNameForFiltering( |
| 100 const testing::TestCase* test_case, | 98 const testing::TestCase* test_case, |
| 101 const testing::TestInfo* test_info) OVERRIDE; | 99 const testing::TestInfo* test_info) OVERRIDE; |
| 102 virtual bool ShouldRunTest(const testing::TestCase* test_case, | 100 virtual bool ShouldRunTest(const testing::TestCase* test_case, |
| 103 const testing::TestInfo* test_info) OVERRIDE; | 101 const testing::TestInfo* test_info) OVERRIDE; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 121 void GTestCallback( | 119 void GTestCallback( |
| 122 base::TestLauncher* test_launcher, | 120 base::TestLauncher* test_launcher, |
| 123 const std::string& test_name, | 121 const std::string& test_name, |
| 124 int exit_code, | 122 int exit_code, |
| 125 const base::TimeDelta& elapsed_time, | 123 const base::TimeDelta& elapsed_time, |
| 126 bool was_timeout, | 124 bool was_timeout, |
| 127 const std::string& output); | 125 const std::string& output); |
| 128 | 126 |
| 129 content::TestLauncherDelegate* launcher_delegate_; | 127 content::TestLauncherDelegate* launcher_delegate_; |
| 130 | 128 |
| 131 base::ParallelTestLauncher parallel_launcher_; | |
| 132 | |
| 133 // Store dependent test name (map is indexed by full test name). | 129 // Store dependent test name (map is indexed by full test name). |
| 134 typedef std::map<std::string, std::string> DependentTestMap; | 130 typedef std::map<std::string, std::string> DependentTestMap; |
| 135 DependentTestMap dependent_test_map_; | 131 DependentTestMap dependent_test_map_; |
| 136 DependentTestMap reverse_dependent_test_map_; | 132 DependentTestMap reverse_dependent_test_map_; |
| 137 | 133 |
| 138 // Store unique data directory prefix for test names (without PRE_ prefixes). | 134 // Store unique data directory prefix for test names (without PRE_ prefixes). |
| 139 // PRE_ tests and tests that depend on them must share the same | 135 // PRE_ tests and tests that depend on them must share the same |
| 140 // data directory. Using test name as directory name leads to too long | 136 // data directory. Using test name as directory name leads to too long |
| 141 // names (exceeding UNIX_PATH_MAX, which creates a problem with | 137 // names (exceeding UNIX_PATH_MAX, which creates a problem with |
| 142 // process_singleton_linux). Create a randomly-named temporary directory | 138 // process_singleton_linux). Create a randomly-named temporary directory |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 320 } |
| 325 | 321 |
| 326 // Always enable disabled tests. This method is not called with disabled | 322 // Always enable disabled tests. This method is not called with disabled |
| 327 // tests unless this flag was specified to the browser test executable. | 323 // tests unless this flag was specified to the browser test executable. |
| 328 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); | 324 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); |
| 329 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); | 325 new_cmd_line.AppendSwitchASCII("gtest_filter", test_name); |
| 330 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); | 326 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); |
| 331 | 327 |
| 332 char* browser_wrapper = getenv("BROWSER_WRAPPER"); | 328 char* browser_wrapper = getenv("BROWSER_WRAPPER"); |
| 333 | 329 |
| 334 parallel_launcher_.LaunchChildGTestProcess( | 330 test_launcher->LaunchChildGTestProcess( |
| 335 new_cmd_line, | 331 new_cmd_line, |
| 336 browser_wrapper ? browser_wrapper : std::string(), | 332 browser_wrapper ? browser_wrapper : std::string(), |
| 337 TestTimeouts::action_max_timeout(), | 333 TestTimeouts::action_max_timeout(), |
| 338 base::Bind(&WrapperTestLauncherDelegate::GTestCallback, | 334 base::Bind(&WrapperTestLauncherDelegate::GTestCallback, |
| 339 base::Unretained(this), | 335 base::Unretained(this), |
| 340 test_launcher, | 336 test_launcher, |
| 341 test_name)); | 337 test_name)); |
| 342 } | 338 } |
| 343 | 339 |
| 344 void WrapperTestLauncherDelegate::RunDependentTest( | 340 void WrapperTestLauncherDelegate::RunDependentTest( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 if (ContainsKey(user_data_dir_map_, test_name_no_pre)) { | 390 if (ContainsKey(user_data_dir_map_, test_name_no_pre)) { |
| 395 if (!base::DeleteFile(user_data_dir_map_[test_name_no_pre], true)) { | 391 if (!base::DeleteFile(user_data_dir_map_[test_name_no_pre], true)) { |
| 396 LOG(WARNING) << "Failed to delete " | 392 LOG(WARNING) << "Failed to delete " |
| 397 << user_data_dir_map_[test_name_no_pre].value(); | 393 << user_data_dir_map_[test_name_no_pre].value(); |
| 398 } | 394 } |
| 399 user_data_dir_map_.erase(test_name_no_pre); | 395 user_data_dir_map_.erase(test_name_no_pre); |
| 400 } | 396 } |
| 401 } | 397 } |
| 402 | 398 |
| 403 test_launcher->OnTestFinished(result); | 399 test_launcher->OnTestFinished(result); |
| 404 parallel_launcher_.ResetOutputWatchdog(); | |
| 405 } | 400 } |
| 406 | 401 |
| 407 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { | 402 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { |
| 408 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) | 403 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) |
| 409 return true; | 404 return true; |
| 410 | 405 |
| 411 std::string switch_value = | 406 std::string switch_value = |
| 412 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 407 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
| 413 if (!base::StringToInt(switch_value, result) || *result < 1) { | 408 if (!base::StringToInt(switch_value, result) || *result < 1) { |
| 414 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; | 409 LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 "Starting tests (using %d parallel jobs)...\n" | 503 "Starting tests (using %d parallel jobs)...\n" |
| 509 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" | 504 "IMPORTANT DEBUGGING NOTE: each test is run inside its own process.\n" |
| 510 "For debugging a test inside a debugger, use the\n" | 505 "For debugging a test inside a debugger, use the\n" |
| 511 "--gtest_filter=<your_test_name> flag along with either\n" | 506 "--gtest_filter=<your_test_name> flag along with either\n" |
| 512 "--single_process (to run the test in one launcher/browser process) or\n" | 507 "--single_process (to run the test in one launcher/browser process) or\n" |
| 513 "--single-process (to do the above, and also run Chrome in single-" | 508 "--single-process (to do the above, and also run Chrome in single-" |
| 514 "process mode).\n", jobs); | 509 "process mode).\n", jobs); |
| 515 | 510 |
| 516 base::MessageLoopForIO message_loop; | 511 base::MessageLoopForIO message_loop; |
| 517 | 512 |
| 518 WrapperTestLauncherDelegate delegate(launcher_delegate, jobs); | 513 WrapperTestLauncherDelegate delegate(launcher_delegate); |
| 519 base::TestLauncher launcher(&delegate); | 514 base::TestLauncher launcher(&delegate, jobs); |
| 520 bool success = launcher.Run(argc, argv); | 515 bool success = launcher.Run(argc, argv); |
| 521 return (success ? 0 : 1); | 516 return (success ? 0 : 1); |
| 522 } | 517 } |
| 523 | 518 |
| 524 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 519 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
| 525 return g_launcher_delegate; | 520 return g_launcher_delegate; |
| 526 } | 521 } |
| 527 | 522 |
| 528 } // namespace content | 523 } // namespace content |
| OLD | NEW |