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/test_launcher.h" | 5 #include "base/test/launcher/test_launcher.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/scoped_file.h" |
17 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
18 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
22 #include "base/process/kill.h" | 23 #include "base/process/kill.h" |
23 #include "base/process/launch.h" | 24 #include "base/process/launch.h" |
24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 26 #include "base/strings/string_split.h" |
26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 CHECK(handle.IsValid()); | 238 CHECK(handle.IsValid()); |
238 options.inherit_handles = true; | 239 options.inherit_handles = true; |
239 options.stdin_handle = INVALID_HANDLE_VALUE; | 240 options.stdin_handle = INVALID_HANDLE_VALUE; |
240 options.stdout_handle = handle.Get(); | 241 options.stdout_handle = handle.Get(); |
241 options.stderr_handle = handle.Get(); | 242 options.stderr_handle = handle.Get(); |
242 } | 243 } |
243 #elif defined(OS_POSIX) | 244 #elif defined(OS_POSIX) |
244 options.new_process_group = true; | 245 options.new_process_group = true; |
245 | 246 |
246 base::FileHandleMappingVector fds_mapping; | 247 base::FileHandleMappingVector fds_mapping; |
247 file_util::ScopedFD output_file_fd_closer; | 248 base::ScopedFD output_file_fd; |
248 | 249 |
249 if (redirect_stdio) { | 250 if (redirect_stdio) { |
250 int output_file_fd = open(output_file.value().c_str(), O_RDWR); | 251 output_file_fd.reset(open(output_file.value().c_str(), O_RDWR)); |
251 CHECK_GE(output_file_fd, 0); | 252 CHECK(output_file_fd); |
252 | 253 |
253 output_file_fd_closer.reset(&output_file_fd); | 254 fds_mapping.push_back(std::make_pair(output_file_fd.get(), STDOUT_FILENO)); |
254 | 255 fds_mapping.push_back(std::make_pair(output_file_fd.get(), STDERR_FILENO)); |
255 fds_mapping.push_back(std::make_pair(output_file_fd, STDOUT_FILENO)); | |
256 fds_mapping.push_back(std::make_pair(output_file_fd, STDERR_FILENO)); | |
257 options.fds_to_remap = &fds_mapping; | 256 options.fds_to_remap = &fds_mapping; |
258 } | 257 } |
259 #endif | 258 #endif |
260 | 259 |
261 bool was_timeout = false; | 260 bool was_timeout = false; |
262 int exit_code = LaunchChildTestProcessWithOptions( | 261 int exit_code = LaunchChildTestProcessWithOptions( |
263 command_line, options, timeout, &was_timeout); | 262 command_line, options, timeout, &was_timeout); |
264 | 263 |
265 if (redirect_stdio) { | 264 if (redirect_stdio) { |
266 #if defined(OS_WIN) | 265 #if defined(OS_WIN) |
267 FlushFileBuffers(handle.Get()); | 266 FlushFileBuffers(handle.Get()); |
268 handle.Close(); | 267 handle.Close(); |
269 #elif defined(OS_POSIX) | 268 #elif defined(OS_POSIX) |
270 output_file_fd_closer.reset(); | 269 output_file_fd.reset(); |
271 #endif | 270 #endif |
272 } | 271 } |
273 | 272 |
274 std::string output_file_contents; | 273 std::string output_file_contents; |
275 CHECK(base::ReadFileToString(output_file, &output_file_contents)); | 274 CHECK(base::ReadFileToString(output_file, &output_file_contents)); |
276 | 275 |
277 if (!base::DeleteFile(output_file, false)) { | 276 if (!base::DeleteFile(output_file, false)) { |
278 // This needs to be non-fatal at least for Windows. | 277 // This needs to be non-fatal at least for Windows. |
279 LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); | 278 LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); |
280 } | 279 } |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 | 1069 |
1071 g_live_processes.Get().erase(process_handle); | 1070 g_live_processes.Get().erase(process_handle); |
1072 } | 1071 } |
1073 | 1072 |
1074 base::CloseProcessHandle(process_handle); | 1073 base::CloseProcessHandle(process_handle); |
1075 | 1074 |
1076 return exit_code; | 1075 return exit_code; |
1077 } | 1076 } |
1078 | 1077 |
1079 } // namespace base | 1078 } // namespace base |
OLD | NEW |