| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 | 10 |
| 11 #include "chrome/test/test_launcher/test_runner.h" | 11 #include "chrome/test/test_launcher/test_runner.h" |
| 12 #include "chrome/test/unit/chrome_test_suite.h" | 12 #include "chrome/test/unit/chrome_test_suite.h" |
| 13 | 13 |
| 14 // This version of the test launcher forks a new process for each test it runs. | 14 // This version of the test launcher forks a new process for each test it runs. |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests"; | 18 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
| 19 const wchar_t* const kChildProcessFlag = L"child"; | 19 const char kChildProcessFlag[] = "child"; |
| 20 | 20 |
| 21 class OutOfProcTestRunner : public tests::TestRunner { | 21 class OutOfProcTestRunner : public tests::TestRunner { |
| 22 public: | 22 public: |
| 23 OutOfProcTestRunner() { | 23 OutOfProcTestRunner() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 virtual ~OutOfProcTestRunner() { | 26 virtual ~OutOfProcTestRunner() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool Init() { | 29 bool Init() { |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Returns true if the test succeeded, false if it failed. | 33 // Returns true if the test succeeded, false if it failed. |
| 34 bool RunTest(const std::string& test_name) { | 34 bool RunTest(const std::string& test_name) { |
| 35 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 35 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 36 CommandLine new_cmd_line(cmd_line->argv()); | 36 CommandLine new_cmd_line(cmd_line->argv()); |
| 37 // Always enable disabled tests. This method is not called with disabled | 37 // Always enable disabled tests. This method is not called with disabled |
| 38 // tests unless this flag was specified to the browser test executable. | 38 // tests unless this flag was specified to the browser test executable. |
| 39 new_cmd_line.AppendSwitch(L"gtest_also_run_disabled_tests"); | 39 new_cmd_line.AppendSwitch("gtest_also_run_disabled_tests"); |
| 40 new_cmd_line.AppendSwitchWithValue(L"gtest_filter", ASCIIToWide(test_name)); | 40 new_cmd_line.AppendSwitchWithValue("gtest_filter", test_name); |
| 41 new_cmd_line.AppendSwitch(kChildProcessFlag); | 41 new_cmd_line.AppendSwitch(kChildProcessFlag); |
| 42 | 42 |
| 43 base::ProcessHandle process_handle; | 43 base::ProcessHandle process_handle; |
| 44 bool r = base::LaunchApp(new_cmd_line, false, false, &process_handle); | 44 bool r = base::LaunchApp(new_cmd_line, false, false, &process_handle); |
| 45 if (!r) | 45 if (!r) |
| 46 return false; | 46 return false; |
| 47 | 47 |
| 48 int exit_code = 0; | 48 int exit_code = 0; |
| 49 r = base::WaitForExitCode(process_handle, &exit_code); | 49 r = base::WaitForExitCode(process_handle, &exit_code); |
| 50 if (!r) | 50 if (!r) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 77 | 77 |
| 78 if (command_line->HasSwitch(kChildProcessFlag)) | 78 if (command_line->HasSwitch(kChildProcessFlag)) |
| 79 return ChromeTestSuite(argc, argv).Run(); | 79 return ChromeTestSuite(argc, argv).Run(); |
| 80 | 80 |
| 81 if (command_line->HasSwitch(kGTestListTestsFlag)) | 81 if (command_line->HasSwitch(kGTestListTestsFlag)) |
| 82 return ChromeTestSuite(argc, argv).Run(); | 82 return ChromeTestSuite(argc, argv).Run(); |
| 83 | 83 |
| 84 OutOfProcTestRunnerFactory test_runner_factory; | 84 OutOfProcTestRunnerFactory test_runner_factory; |
| 85 return tests::RunTests(test_runner_factory) ? 0 : 1; | 85 return tests::RunTests(test_runner_factory) ? 0 : 1; |
| 86 } | 86 } |
| OLD | NEW |