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