| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/launcher/unit_test_launcher.h" | 5 #include "base/test/launcher/unit_test_launcher.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 return false; | 106 return false; |
| 107 *path = path->AppendASCII("test_results.xml"); | 107 *path = path->AppendASCII("test_results.xml"); |
| 108 return true; | 108 return true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 CommandLine GetCommandLineForChildGTestProcess( | 111 CommandLine GetCommandLineForChildGTestProcess( |
| 112 const std::vector<std::string>& test_names, | 112 const std::vector<std::string>& test_names, |
| 113 const base::FilePath& output_file) override { | 113 const base::FilePath& output_file) override { |
| 114 CommandLine new_cmd_line(*CommandLine::ForCurrentProcess()); | 114 CommandLine new_cmd_line(*CommandLine::ForCurrentProcess()); |
| 115 | 115 |
| 116 CHECK(temp_dir_.IsValid() || temp_dir_.CreateUniqueTempDir()); |
| 117 FilePath temp_file; |
| 118 CHECK(CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); |
| 119 std::string long_flags( |
| 120 std::string("--") + kGTestFilterFlag + "=" + |
| 121 JoinString(test_names, ":")); |
| 122 CHECK_EQ(static_cast<int>(long_flags.size()), |
| 123 WriteFile(temp_file, |
| 124 long_flags.data(), |
| 125 static_cast<int>(long_flags.size()))); |
| 126 |
| 116 new_cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file); | 127 new_cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file); |
| 117 new_cmd_line.AppendSwitchASCII(kGTestFilterFlag, | 128 new_cmd_line.AppendSwitchPath(kGTestFlagfileFlag, temp_file); |
| 118 JoinString(test_names, ":")); | |
| 119 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); | 129 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); |
| 120 | 130 |
| 121 return new_cmd_line; | 131 return new_cmd_line; |
| 122 } | 132 } |
| 123 | 133 |
| 124 std::string GetWrapperForChildGTestProcess() override { | 134 std::string GetWrapperForChildGTestProcess() override { |
| 125 return std::string(); | 135 return std::string(); |
| 126 } | 136 } |
| 127 | 137 |
| 128 void RelaunchTests(TestLauncher* test_launcher, | 138 void RelaunchTests(TestLauncher* test_launcher, |
| 129 const std::vector<std::string>& test_names, | 139 const std::vector<std::string>& test_names, |
| 130 int launch_flags) override { | 140 int launch_flags) override { |
| 131 // Relaunch requested tests in parallel, but only use single | 141 // Relaunch requested tests in parallel, but only use single |
| 132 // test per batch for more precise results (crashes, etc). | 142 // test per batch for more precise results (crashes, etc). |
| 133 for (const std::string& test_name : test_names) { | 143 for (const std::string& test_name : test_names) { |
| 134 std::vector<std::string> batch; | 144 std::vector<std::string> batch; |
| 135 batch.push_back(test_name); | 145 batch.push_back(test_name); |
| 136 RunUnitTestsBatch(test_launcher, this, batch, launch_flags); | 146 RunUnitTestsBatch(test_launcher, this, batch, launch_flags); |
| 137 } | 147 } |
| 138 } | 148 } |
| 139 | 149 |
| 150 ScopedTempDir temp_dir_; |
| 151 |
| 140 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); | 152 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); |
| 141 }; | 153 }; |
| 142 | 154 |
| 143 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { | 155 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { |
| 144 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) | 156 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) |
| 145 return true; | 157 return true; |
| 146 | 158 |
| 147 std::string switch_value = | 159 std::string switch_value = |
| 148 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 160 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
| 149 if (!StringToInt(switch_value, result) || *result < 1) { | 161 if (!StringToInt(switch_value, result) || *result < 1) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 TestLauncher* test_launcher, | 592 TestLauncher* test_launcher, |
| 581 const std::vector<std::string>& test_names) { | 593 const std::vector<std::string>& test_names) { |
| 582 ThreadTaskRunnerHandle::Get()->PostTask( | 594 ThreadTaskRunnerHandle::Get()->PostTask( |
| 583 FROM_HERE, | 595 FROM_HERE, |
| 584 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, | 596 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, |
| 585 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); | 597 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); |
| 586 return test_names.size(); | 598 return test_names.size(); |
| 587 } | 599 } |
| 588 | 600 |
| 589 } // namespace base | 601 } // namespace base |
| OLD | NEW |