Chromium Code Reviews| 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 if (!temp_dir_.IsValid()) { | |
|
sky
2015/10/29 17:32:34
nit: no {}. That said, I would likely move this in
Paweł Hajdan Jr.
2015/10/29 18:43:20
Done.
| |
| 117 CHECK(temp_dir_.CreateUniqueTempDir()); | |
| 118 } | |
| 119 FilePath temp_file; | |
| 120 CHECK(CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); | |
| 121 std::string long_flags( | |
| 122 std::string("--") + kGTestFilterFlag + "=" + | |
| 123 JoinString(test_names, ":")); | |
| 124 CHECK_EQ(static_cast<int>(long_flags.size()), | |
| 125 WriteFile(temp_file, | |
| 126 long_flags.data(), | |
| 127 static_cast<int>(long_flags.size()))); | |
| 128 | |
| 116 new_cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file); | 129 new_cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file); |
| 117 new_cmd_line.AppendSwitchASCII(kGTestFilterFlag, | 130 new_cmd_line.AppendSwitchPath(kGTestFlagfileFlag, temp_file); |
| 118 JoinString(test_names, ":")); | |
| 119 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); | 131 new_cmd_line.AppendSwitch(kSingleProcessTestsFlag); |
| 120 | 132 |
| 121 return new_cmd_line; | 133 return new_cmd_line; |
| 122 } | 134 } |
| 123 | 135 |
| 124 std::string GetWrapperForChildGTestProcess() override { | 136 std::string GetWrapperForChildGTestProcess() override { |
| 125 return std::string(); | 137 return std::string(); |
| 126 } | 138 } |
| 127 | 139 |
| 128 void RelaunchTests(TestLauncher* test_launcher, | 140 void RelaunchTests(TestLauncher* test_launcher, |
| 129 const std::vector<std::string>& test_names, | 141 const std::vector<std::string>& test_names, |
| 130 int launch_flags) override { | 142 int launch_flags) override { |
| 131 // Relaunch requested tests in parallel, but only use single | 143 // Relaunch requested tests in parallel, but only use single |
| 132 // test per batch for more precise results (crashes, etc). | 144 // test per batch for more precise results (crashes, etc). |
| 133 for (const std::string& test_name : test_names) { | 145 for (const std::string& test_name : test_names) { |
| 134 std::vector<std::string> batch; | 146 std::vector<std::string> batch; |
| 135 batch.push_back(test_name); | 147 batch.push_back(test_name); |
| 136 RunUnitTestsBatch(test_launcher, this, batch, launch_flags); | 148 RunUnitTestsBatch(test_launcher, this, batch, launch_flags); |
| 137 } | 149 } |
| 138 } | 150 } |
| 139 | 151 |
| 152 ScopedTempDir temp_dir_; | |
| 153 | |
| 140 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); | 154 DISALLOW_COPY_AND_ASSIGN(DefaultUnitTestPlatformDelegate); |
| 141 }; | 155 }; |
| 142 | 156 |
| 143 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { | 157 bool GetSwitchValueAsInt(const std::string& switch_name, int* result) { |
| 144 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) | 158 if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) |
| 145 return true; | 159 return true; |
| 146 | 160 |
| 147 std::string switch_value = | 161 std::string switch_value = |
| 148 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); | 162 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name); |
| 149 if (!StringToInt(switch_value, result) || *result < 1) { | 163 if (!StringToInt(switch_value, result) || *result < 1) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 TestLauncher* test_launcher, | 594 TestLauncher* test_launcher, |
| 581 const std::vector<std::string>& test_names) { | 595 const std::vector<std::string>& test_names) { |
| 582 ThreadTaskRunnerHandle::Get()->PostTask( | 596 ThreadTaskRunnerHandle::Get()->PostTask( |
| 583 FROM_HERE, | 597 FROM_HERE, |
| 584 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, | 598 Bind(&RunUnitTestsSerially, test_launcher, platform_delegate_, test_names, |
| 585 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); | 599 use_job_objects_ ? TestLauncher::USE_JOB_OBJECTS : 0)); |
| 586 return test_names.size(); | 600 return test_names.size(); |
| 587 } | 601 } |
| 588 | 602 |
| 589 } // namespace base | 603 } // namespace base |
| OLD | NEW |