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/test/multiprocess_test.h" | 5 #include "base/test/multiprocess_test.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/posix/eintr_wrapper.h" | |
12 #include "testing/multiprocess_func_list.h" | 11 #include "testing/multiprocess_func_list.h" |
13 | 12 |
14 namespace base { | 13 namespace base { |
15 | 14 |
16 // A very basic implementation for android. On Android tests can run in an APK | 15 // 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 | 16 // 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). | 17 // minimum to execute the method specified by procname (in the child process). |
19 // - |debug_on_start| is ignored. | 18 // - |debug_on_start| is ignored. |
20 ProcessHandle MultiProcessTest::SpawnChildImpl( | 19 ProcessHandle MultiProcessTest::SpawnChildImpl( |
21 const std::string& procname, | 20 const std::string& procname, |
(...skipping 13 matching lines...) Expand all Loading... |
35 std::hash_set<int> fds_to_keep_open; | 34 std::hash_set<int> fds_to_keep_open; |
36 for (FileHandleMappingVector::const_iterator it = fds_to_remap.begin(); | 35 for (FileHandleMappingVector::const_iterator it = fds_to_remap.begin(); |
37 it != fds_to_remap.end(); ++it) { | 36 it != fds_to_remap.end(); ++it) { |
38 fds_to_keep_open.insert(it->first); | 37 fds_to_keep_open.insert(it->first); |
39 } | 38 } |
40 // Keep stdin, stdout and stderr open since this is not meant to spawn a | 39 // Keep stdin, stdout and stderr open since this is not meant to spawn a |
41 // daemon. | 40 // daemon. |
42 const int kFdForAndroidLogging = 3; // FD used by __android_log_write(). | 41 const int kFdForAndroidLogging = 3; // FD used by __android_log_write(). |
43 for (int fd = kFdForAndroidLogging + 1; fd < getdtablesize(); ++fd) { | 42 for (int fd = kFdForAndroidLogging + 1; fd < getdtablesize(); ++fd) { |
44 if (fds_to_keep_open.find(fd) == fds_to_keep_open.end()) { | 43 if (fds_to_keep_open.find(fd) == fds_to_keep_open.end()) { |
45 HANDLE_EINTR(close(fd)); | 44 close(fd); |
46 } | 45 } |
47 } | 46 } |
48 for (FileHandleMappingVector::const_iterator it = fds_to_remap.begin(); | 47 for (FileHandleMappingVector::const_iterator it = fds_to_remap.begin(); |
49 it != fds_to_remap.end(); ++it) { | 48 it != fds_to_remap.end(); ++it) { |
50 int old_fd = it->first; | 49 int old_fd = it->first; |
51 int new_fd = it->second; | 50 int new_fd = it->second; |
52 if (dup2(old_fd, new_fd) < 0) { | 51 if (dup2(old_fd, new_fd) < 0) { |
53 PLOG(FATAL) << "dup2"; | 52 PLOG(FATAL) << "dup2"; |
54 } | 53 } |
55 HANDLE_EINTR(close(old_fd)); | 54 close(old_fd); |
56 } | 55 } |
57 _exit(multi_process_function_list::InvokeChildProcessTest(procname)); | 56 _exit(multi_process_function_list::InvokeChildProcessTest(procname)); |
58 return 0; | 57 return 0; |
59 } | 58 } |
60 | 59 |
61 } // namespace base | 60 } // namespace base |
OLD | NEW |