| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/posix/global_descriptors.h" |  | 
| 6 #include "base/test/multiprocess_test.h" | 5 #include "base/test/multiprocess_test.h" | 
| 7 | 6 | 
| 8 #include <unistd.h> | 7 #include <unistd.h> | 
| 9 | 8 | 
|  | 9 #include "base/base_switches.h" | 
|  | 10 #include "base/command_line.h" | 
| 10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" | 
| 11 #include "base/logging.h" | 12 #include "base/logging.h" | 
|  | 13 #include "base/posix/global_descriptors.h" | 
| 12 #include "testing/multiprocess_func_list.h" | 14 #include "testing/multiprocess_func_list.h" | 
| 13 | 15 | 
| 14 namespace base { | 16 namespace base { | 
| 15 | 17 | 
| 16 // A very basic implementation for Android. On Android tests can run in an APK | 18 // A very basic implementation for Android. On Android tests can run in an APK | 
| 17 // and we don't have an executable to exec*. This implementation does the bare | 19 // and we don't have an executable to exec*. This implementation does the bare | 
| 18 // minimum to execute the method specified by procname (in the child process). | 20 // minimum to execute the method specified by procname (in the child process). | 
| 19 //  - |base_command_line| is ignored. |  | 
| 20 //  - All options except |fds_to_remap| are ignored. | 21 //  - All options except |fds_to_remap| are ignored. | 
| 21 ProcessHandle SpawnMultiProcessTestChild(const std::string& procname, | 22 ProcessHandle SpawnMultiProcessTestChild(const std::string& procname, | 
| 22                                          const CommandLine& base_command_line, | 23                                          const CommandLine& base_command_line, | 
| 23                                          const LaunchOptions& options) { | 24                                          const LaunchOptions& options) { | 
| 24   // TODO(viettrungluu): The FD-remapping done below is wrong in the presence of | 25   // TODO(viettrungluu): The FD-remapping done below is wrong in the presence of | 
| 25   // cycles (e.g., fd1 -> fd2, fd2 -> fd1). crbug.com/326576 | 26   // cycles (e.g., fd1 -> fd2, fd2 -> fd1). crbug.com/326576 | 
| 26   FileHandleMappingVector empty; | 27   FileHandleMappingVector empty; | 
| 27   const FileHandleMappingVector* fds_to_remap = | 28   const FileHandleMappingVector* fds_to_remap = | 
| 28       options.fds_to_remap ? options.fds_to_remap : ∅ | 29       options.fds_to_remap ? options.fds_to_remap : ∅ | 
| 29 | 30 | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 53   } | 54   } | 
| 54   for (FileHandleMappingVector::const_iterator it = fds_to_remap->begin(); | 55   for (FileHandleMappingVector::const_iterator it = fds_to_remap->begin(); | 
| 55        it != fds_to_remap->end(); ++it) { | 56        it != fds_to_remap->end(); ++it) { | 
| 56     int old_fd = it->first; | 57     int old_fd = it->first; | 
| 57     int new_fd = it->second; | 58     int new_fd = it->second; | 
| 58     if (dup2(old_fd, new_fd) < 0) { | 59     if (dup2(old_fd, new_fd) < 0) { | 
| 59       PLOG(FATAL) << "dup2"; | 60       PLOG(FATAL) << "dup2"; | 
| 60     } | 61     } | 
| 61     close(old_fd); | 62     close(old_fd); | 
| 62   } | 63   } | 
|  | 64   CommandLine::Reset(); | 
|  | 65   CommandLine::Init(0, nullptr); | 
|  | 66   CommandLine* command_line = CommandLine::ForCurrentProcess(); | 
|  | 67   command_line->InitFromArgv(base_command_line.argv()); | 
|  | 68   if (!command_line->HasSwitch(switches::kTestChildProcess)) | 
|  | 69     command_line->AppendSwitchASCII(switches::kTestChildProcess, procname); | 
|  | 70 | 
| 63   _exit(multi_process_function_list::InvokeChildProcessTest(procname)); | 71   _exit(multi_process_function_list::InvokeChildProcessTest(procname)); | 
| 64   return 0; | 72   return 0; | 
| 65 } | 73 } | 
| 66 | 74 | 
| 67 }  // namespace base | 75 }  // namespace base | 
| OLD | NEW | 
|---|