Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Unified Diff: base/test/multiprocess_test_android.cc

Issue 1952513003: Fix Android multi-process tests on M. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/multiprocess_test_android.cc
diff --git a/base/test/multiprocess_test_android.cc b/base/test/multiprocess_test_android.cc
index 52dc01feea1853f46e4dd2b7ef04ab8a9756a396..cb3c0c3f1f28d223e7eb6fcd3451b709c0ed487b 100644
--- a/base/test/multiprocess_test_android.cc
+++ b/base/test/multiprocess_test_android.cc
@@ -103,7 +103,7 @@ class LaunchHelper {
int* exit_code);
bool IsReady() const { return child_fd_ != -1; }
- bool IsChild() const { return parent_fd_ != -1; }
+ bool IsChild() const { return is_child_; }
private:
// Wrappers around sendmsg/recvmsg that supports message fragmentation.
@@ -119,6 +119,8 @@ class LaunchHelper {
std::vector<ScopedFD> fds);
void WaitForChildInHelper(const WaitProcessRequest* request);
+ bool is_child_ = false;
+
// Parent vars.
int child_fd_ = -1;
@@ -204,6 +206,7 @@ void LaunchHelper::DoParent(int fd) {
void LaunchHelper::DoHelper(int fd) {
parent_fd_ = fd;
+ is_child_ = true;
std::unique_ptr<char[]> buf(new char[kMaxMessageSize]);
while (true) {
// Wait for a message from the parent.
@@ -247,6 +250,7 @@ void LaunchHelper::StartProcessInHelper(const StartProcessRequest* request,
} else {
// Child.
PCHECK(close(parent_fd_) == 0);
+ parent_fd_ = -1;
CommandLine::Reset();
Pickle serialised_extra(reinterpret_cast<const char*>(request + 1),
@@ -264,10 +268,12 @@ void LaunchHelper::StartProcessInHelper(const StartProcessRequest* request,
int new_fd;
CHECK(iter.ReadInt(&new_fd));
int old_fd = fds[i].release();
- if (dup2(old_fd, new_fd) < 0) {
- PLOG(FATAL) << "dup2";
+ if (new_fd != old_fd) {
+ if (dup2(old_fd, new_fd) < 0) {
+ PLOG(FATAL) << "dup2";
+ }
+ PCHECK(close(old_fd) == 0);
}
- PCHECK(close(old_fd) == 0);
}
std::unique_ptr<char*[]> argv(new char*[args.size()]);
@@ -370,6 +376,10 @@ void InitAndroidMultiProcessTestHelper(int (*main)(int, char**)) {
g_launch_helper.Get().Init(main);
}
+bool AndroidIsChildProcess() {
+ return g_launch_helper.Get().IsChild();
+}
+
bool AndroidWaitForChildExitWithTimeout(
const Process& process, TimeDelta timeout, int* exit_code) {
CHECK(g_launch_helper.Get().IsReady());

Powered by Google App Engine
This is Rietveld 408576698