MultiProcessTest: Update SpawnChild* to return a Process.
We should not be dealing with raw handles. BUG=417532 Review URL: https://codereview.chromium.org/843113003 Cr-Commit-Position: refs/heads/master@{#311127}
This commit is contained in:
base
debug
memory
metrics
process
test
chrome
browser
printing
cloud_print
common
components/browser_watcher
content/common
ipc
mojo/edk/test
sandbox/mac
@@ -146,9 +146,10 @@ MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) {
|
|||||||
// and e.g. mismatched new[]/delete would cause a hang because
|
// and e.g. mismatched new[]/delete would cause a hang because
|
||||||
// of re-entering malloc.
|
// of re-entering malloc.
|
||||||
TEST_F(StackTraceTest, AsyncSignalUnsafeSignalHandlerHang) {
|
TEST_F(StackTraceTest, AsyncSignalUnsafeSignalHandlerHang) {
|
||||||
ProcessHandle child = SpawnChild("MismatchedMallocChildProcess");
|
Process child = SpawnChild("MismatchedMallocChildProcess");
|
||||||
ASSERT_NE(kNullProcessHandle, child);
|
ASSERT_TRUE(child.IsValid());
|
||||||
ASSERT_TRUE(WaitForSingleProcess(child, TestTimeouts::action_timeout()));
|
ASSERT_TRUE(WaitForSingleProcess(child.Handle(),
|
||||||
|
TestTimeouts::action_timeout()));
|
||||||
}
|
}
|
||||||
#endif // !defined(OS_IOS)
|
#endif // !defined(OS_IOS)
|
||||||
|
|
||||||
|
@@ -699,15 +699,15 @@ const char* const SharedMemoryProcessTest::s_test_name_ = "MPMem";
|
|||||||
TEST_F(SharedMemoryProcessTest, Tasks) {
|
TEST_F(SharedMemoryProcessTest, Tasks) {
|
||||||
SharedMemoryProcessTest::CleanUp();
|
SharedMemoryProcessTest::CleanUp();
|
||||||
|
|
||||||
ProcessHandle handles[kNumTasks];
|
Process processes[kNumTasks];
|
||||||
for (int index = 0; index < kNumTasks; ++index) {
|
for (int index = 0; index < kNumTasks; ++index) {
|
||||||
handles[index] = SpawnChild("SharedMemoryTestMain");
|
processes[index] = SpawnChild("SharedMemoryTestMain");
|
||||||
ASSERT_TRUE(handles[index]);
|
ASSERT_TRUE(processes[index].IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
for (int index = 0; index < kNumTasks; ++index) {
|
for (int index = 0; index < kNumTasks; ++index) {
|
||||||
EXPECT_TRUE(WaitForExitCode(handles[index], &exit_code));
|
EXPECT_TRUE(processes[index].WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(0, exit_code);
|
EXPECT_EQ(0, exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -200,19 +200,19 @@ TEST_F(StatsTableTest, DISABLED_MultipleProcesses) {
|
|||||||
// Spin up a set of processes to go bang on the various counters.
|
// Spin up a set of processes to go bang on the various counters.
|
||||||
// After we join the processes, we'll make sure the counters
|
// After we join the processes, we'll make sure the counters
|
||||||
// contain the values we expected.
|
// contain the values we expected.
|
||||||
ProcessHandle procs[kMaxProcs];
|
Process procs[kMaxProcs];
|
||||||
|
|
||||||
// Spawn the processes.
|
// Spawn the processes.
|
||||||
for (int16 index = 0; index < kMaxProcs; index++) {
|
for (int16 index = 0; index < kMaxProcs; index++) {
|
||||||
procs[index] = SpawnChild("StatsTableMultipleProcessMain");
|
procs[index] = SpawnChild("StatsTableMultipleProcessMain");
|
||||||
EXPECT_NE(kNullProcessHandle, procs[index]);
|
EXPECT_TRUE(procs[index].IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the processes to finish.
|
// Wait for the processes to finish.
|
||||||
for (int index = 0; index < kMaxProcs; index++) {
|
for (int index = 0; index < kMaxProcs; index++) {
|
||||||
EXPECT_TRUE(WaitForSingleProcess(
|
EXPECT_TRUE(WaitForSingleProcess(procs[index].Handle(),
|
||||||
procs[index], base::TimeDelta::FromMinutes(1)));
|
base::TimeDelta::FromMinutes(1)));
|
||||||
CloseProcessHandle(procs[index]);
|
procs[index].Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
StatsCounter zero_counter(kCounterZero);
|
StatsCounter zero_counter(kCounterZero);
|
||||||
|
@@ -142,11 +142,10 @@ MULTIPROCESS_TEST_MAIN(SimpleChildProcess) {
|
|||||||
|
|
||||||
// TODO(viettrungluu): This should be in a "MultiProcessTestTest".
|
// TODO(viettrungluu): This should be in a "MultiProcessTestTest".
|
||||||
TEST_F(ProcessUtilTest, SpawnChild) {
|
TEST_F(ProcessUtilTest, SpawnChild) {
|
||||||
base::ProcessHandle handle = SpawnChild("SimpleChildProcess");
|
base::Process process = SpawnChild("SimpleChildProcess");
|
||||||
ASSERT_NE(base::kNullProcessHandle, handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
EXPECT_TRUE(base::WaitForSingleProcess(
|
EXPECT_TRUE(base::WaitForSingleProcess(process.Handle(),
|
||||||
handle, TestTimeouts::action_max_timeout()));
|
TestTimeouts::action_max_timeout()));
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MULTIPROCESS_TEST_MAIN(SlowChildProcess) {
|
MULTIPROCESS_TEST_MAIN(SlowChildProcess) {
|
||||||
@@ -158,12 +157,11 @@ TEST_F(ProcessUtilTest, KillSlowChild) {
|
|||||||
const std::string signal_file =
|
const std::string signal_file =
|
||||||
ProcessUtilTest::GetSignalFilePath(kSignalFileSlow);
|
ProcessUtilTest::GetSignalFilePath(kSignalFileSlow);
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
base::ProcessHandle handle = SpawnChild("SlowChildProcess");
|
base::Process process = SpawnChild("SlowChildProcess");
|
||||||
ASSERT_NE(base::kNullProcessHandle, handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
SignalChildren(signal_file.c_str());
|
SignalChildren(signal_file.c_str());
|
||||||
EXPECT_TRUE(base::WaitForSingleProcess(
|
EXPECT_TRUE(base::WaitForSingleProcess(process.Handle(),
|
||||||
handle, TestTimeouts::action_max_timeout()));
|
TestTimeouts::action_max_timeout()));
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,21 +170,20 @@ TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) {
|
|||||||
const std::string signal_file =
|
const std::string signal_file =
|
||||||
ProcessUtilTest::GetSignalFilePath(kSignalFileSlow);
|
ProcessUtilTest::GetSignalFilePath(kSignalFileSlow);
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
base::ProcessHandle handle = SpawnChild("SlowChildProcess");
|
base::Process process = SpawnChild("SlowChildProcess");
|
||||||
ASSERT_NE(base::kNullProcessHandle, handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
|
|
||||||
int exit_code = 42;
|
int exit_code = 42;
|
||||||
EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
|
EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
|
||||||
base::GetTerminationStatus(handle, &exit_code));
|
base::GetTerminationStatus(process.Handle(), &exit_code));
|
||||||
EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
|
EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
|
||||||
|
|
||||||
SignalChildren(signal_file.c_str());
|
SignalChildren(signal_file.c_str());
|
||||||
exit_code = 42;
|
exit_code = 42;
|
||||||
base::TerminationStatus status =
|
base::TerminationStatus status =
|
||||||
WaitForChildTermination(handle, &exit_code);
|
WaitForChildTermination(process.Handle(), &exit_code);
|
||||||
EXPECT_EQ(base::TERMINATION_STATUS_NORMAL_TERMINATION, status);
|
EXPECT_EQ(base::TERMINATION_STATUS_NORMAL_TERMINATION, status);
|
||||||
EXPECT_EQ(0, exit_code);
|
EXPECT_EQ(0, exit_code);
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,12 +192,11 @@ TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) {
|
|||||||
TEST_F(ProcessUtilTest, GetProcId) {
|
TEST_F(ProcessUtilTest, GetProcId) {
|
||||||
base::ProcessId id1 = base::GetProcId(GetCurrentProcess());
|
base::ProcessId id1 = base::GetProcId(GetCurrentProcess());
|
||||||
EXPECT_NE(0ul, id1);
|
EXPECT_NE(0ul, id1);
|
||||||
base::ProcessHandle handle = SpawnChild("SimpleChildProcess");
|
base::Process process = SpawnChild("SimpleChildProcess");
|
||||||
ASSERT_NE(base::kNullProcessHandle, handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
base::ProcessId id2 = base::GetProcId(handle);
|
base::ProcessId id2 = process.pid();
|
||||||
EXPECT_NE(0ul, id2);
|
EXPECT_NE(0ul, id2);
|
||||||
EXPECT_NE(id1, id2);
|
EXPECT_NE(id1, id2);
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -239,18 +235,18 @@ TEST_F(ProcessUtilTest, MAYBE_GetTerminationStatusCrash) {
|
|||||||
const std::string signal_file =
|
const std::string signal_file =
|
||||||
ProcessUtilTest::GetSignalFilePath(kSignalFileCrash);
|
ProcessUtilTest::GetSignalFilePath(kSignalFileCrash);
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
base::ProcessHandle handle = SpawnChild("CrashingChildProcess");
|
base::Process process = SpawnChild("CrashingChildProcess");
|
||||||
ASSERT_NE(base::kNullProcessHandle, handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
|
|
||||||
int exit_code = 42;
|
int exit_code = 42;
|
||||||
EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
|
EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
|
||||||
base::GetTerminationStatus(handle, &exit_code));
|
base::GetTerminationStatus(process.Handle(), &exit_code));
|
||||||
EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
|
EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
|
||||||
|
|
||||||
SignalChildren(signal_file.c_str());
|
SignalChildren(signal_file.c_str());
|
||||||
exit_code = 42;
|
exit_code = 42;
|
||||||
base::TerminationStatus status =
|
base::TerminationStatus status =
|
||||||
WaitForChildTermination(handle, &exit_code);
|
WaitForChildTermination(process.Handle(), &exit_code);
|
||||||
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_CRASHED, status);
|
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_CRASHED, status);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
@@ -261,7 +257,6 @@ TEST_F(ProcessUtilTest, MAYBE_GetTerminationStatusCrash) {
|
|||||||
int signal = WTERMSIG(exit_code);
|
int signal = WTERMSIG(exit_code);
|
||||||
EXPECT_EQ(SIGSEGV, signal);
|
EXPECT_EQ(SIGSEGV, signal);
|
||||||
#endif
|
#endif
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
|
|
||||||
// Reset signal handlers back to "normal".
|
// Reset signal handlers back to "normal".
|
||||||
base::debug::EnableInProcessStackDumping();
|
base::debug::EnableInProcessStackDumping();
|
||||||
@@ -286,18 +281,18 @@ TEST_F(ProcessUtilTest, GetTerminationStatusKill) {
|
|||||||
const std::string signal_file =
|
const std::string signal_file =
|
||||||
ProcessUtilTest::GetSignalFilePath(kSignalFileKill);
|
ProcessUtilTest::GetSignalFilePath(kSignalFileKill);
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
base::ProcessHandle handle = SpawnChild("KilledChildProcess");
|
base::Process process = SpawnChild("KilledChildProcess");
|
||||||
ASSERT_NE(base::kNullProcessHandle, handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
|
|
||||||
int exit_code = 42;
|
int exit_code = 42;
|
||||||
EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
|
EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING,
|
||||||
base::GetTerminationStatus(handle, &exit_code));
|
base::GetTerminationStatus(process.Handle(), &exit_code));
|
||||||
EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
|
EXPECT_EQ(kExpectedStillRunningExitCode, exit_code);
|
||||||
|
|
||||||
SignalChildren(signal_file.c_str());
|
SignalChildren(signal_file.c_str());
|
||||||
exit_code = 42;
|
exit_code = 42;
|
||||||
base::TerminationStatus status =
|
base::TerminationStatus status =
|
||||||
WaitForChildTermination(handle, &exit_code);
|
WaitForChildTermination(process.Handle(), &exit_code);
|
||||||
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status);
|
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status);
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
EXPECT_EQ(kExpectedKilledExitCode, exit_code);
|
EXPECT_EQ(kExpectedKilledExitCode, exit_code);
|
||||||
@@ -307,7 +302,6 @@ TEST_F(ProcessUtilTest, GetTerminationStatusKill) {
|
|||||||
int signal = WTERMSIG(exit_code);
|
int signal = WTERMSIG(exit_code);
|
||||||
EXPECT_EQ(SIGKILL, signal);
|
EXPECT_EQ(SIGKILL, signal);
|
||||||
#endif
|
#endif
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
remove(signal_file.c_str());
|
remove(signal_file.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,9 +529,9 @@ int ProcessUtilTest::CountOpenFDsInChild() {
|
|||||||
fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe));
|
fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe));
|
||||||
base::LaunchOptions options;
|
base::LaunchOptions options;
|
||||||
options.fds_to_remap = &fd_mapping_vec;
|
options.fds_to_remap = &fd_mapping_vec;
|
||||||
base::ProcessHandle handle =
|
base::Process process =
|
||||||
SpawnChildWithOptions("ProcessUtilsLeakFDChildProcess", options);
|
SpawnChildWithOptions("ProcessUtilsLeakFDChildProcess", options);
|
||||||
CHECK(handle);
|
CHECK(process.IsValid());
|
||||||
int ret = IGNORE_EINTR(close(fds[1]));
|
int ret = IGNORE_EINTR(close(fds[1]));
|
||||||
DPCHECK(ret == 0);
|
DPCHECK(ret == 0);
|
||||||
|
|
||||||
@@ -549,11 +543,12 @@ int ProcessUtilTest::CountOpenFDsInChild() {
|
|||||||
|
|
||||||
#if defined(THREAD_SANITIZER)
|
#if defined(THREAD_SANITIZER)
|
||||||
// Compiler-based ThreadSanitizer makes this test slow.
|
// Compiler-based ThreadSanitizer makes this test slow.
|
||||||
CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(3)));
|
CHECK(base::WaitForSingleProcess(process.Handle(),
|
||||||
|
base::TimeDelta::FromSeconds(3)));
|
||||||
#else
|
#else
|
||||||
CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(1)));
|
CHECK(base::WaitForSingleProcess(process.Handle(),
|
||||||
|
base::TimeDelta::FromSeconds(1)));
|
||||||
#endif
|
#endif
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
ret = IGNORE_EINTR(close(fds[0]));
|
ret = IGNORE_EINTR(close(fds[0]));
|
||||||
DPCHECK(ret == 0);
|
DPCHECK(ret == 0);
|
||||||
|
|
||||||
@@ -888,7 +883,7 @@ bool IsProcessDead(base::ProcessHandle child) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProcessUtilTest, DelayedTermination) {
|
TEST_F(ProcessUtilTest, DelayedTermination) {
|
||||||
base::Process child_process(SpawnChild("process_util_test_never_die"));
|
base::Process child_process = SpawnChild("process_util_test_never_die");
|
||||||
ASSERT_TRUE(child_process.IsValid());
|
ASSERT_TRUE(child_process.IsValid());
|
||||||
base::EnsureProcessTerminated(child_process.Duplicate());
|
base::EnsureProcessTerminated(child_process.Duplicate());
|
||||||
base::WaitForSingleProcess(child_process.Handle(),
|
base::WaitForSingleProcess(child_process.Handle(),
|
||||||
@@ -906,7 +901,7 @@ MULTIPROCESS_TEST_MAIN(process_util_test_never_die) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProcessUtilTest, ImmediateTermination) {
|
TEST_F(ProcessUtilTest, ImmediateTermination) {
|
||||||
base::Process child_process(SpawnChild("process_util_test_die_immediately"));
|
base::Process child_process = SpawnChild("process_util_test_die_immediately");
|
||||||
ASSERT_TRUE(child_process.IsValid());
|
ASSERT_TRUE(child_process.IsValid());
|
||||||
// Give it time to die.
|
// Give it time to die.
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
#if !defined(OS_ANDROID)
|
#if !defined(OS_ANDROID)
|
||||||
ProcessHandle SpawnMultiProcessTestChild(
|
Process SpawnMultiProcessTestChild(
|
||||||
const std::string& procname,
|
const std::string& procname,
|
||||||
const CommandLine& base_command_line,
|
const CommandLine& base_command_line,
|
||||||
const LaunchOptions& options) {
|
const LaunchOptions& options) {
|
||||||
@@ -21,9 +21,7 @@ ProcessHandle SpawnMultiProcessTestChild(
|
|||||||
if (!command_line.HasSwitch(switches::kTestChildProcess))
|
if (!command_line.HasSwitch(switches::kTestChildProcess))
|
||||||
command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
|
command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
|
||||||
|
|
||||||
ProcessHandle handle = kNullProcessHandle;
|
return LaunchProcess(command_line, options);
|
||||||
LaunchProcess(command_line, options, &handle);
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
#endif // !defined(OS_ANDROID)
|
#endif // !defined(OS_ANDROID)
|
||||||
|
|
||||||
@@ -36,7 +34,7 @@ CommandLine GetMultiProcessTestChildBaseCommandLine() {
|
|||||||
MultiProcessTest::MultiProcessTest() {
|
MultiProcessTest::MultiProcessTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname) {
|
Process MultiProcessTest::SpawnChild(const std::string& procname) {
|
||||||
LaunchOptions options;
|
LaunchOptions options;
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
options.start_hidden = true;
|
options.start_hidden = true;
|
||||||
@@ -44,7 +42,7 @@ ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname) {
|
|||||||
return SpawnChildWithOptions(procname, options);
|
return SpawnChildWithOptions(procname, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessHandle MultiProcessTest::SpawnChildWithOptions(
|
Process MultiProcessTest::SpawnChildWithOptions(
|
||||||
const std::string& procname,
|
const std::string& procname,
|
||||||
const LaunchOptions& options) {
|
const LaunchOptions& options) {
|
||||||
return SpawnMultiProcessTestChild(procname, MakeCmdLine(procname), options);
|
return SpawnMultiProcessTestChild(procname, MakeCmdLine(procname), options);
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/process/launch.h"
|
#include "base/process/launch.h"
|
||||||
#include "base/process/process_handle.h"
|
#include "base/process/process.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "testing/platform_test.h"
|
#include "testing/platform_test.h"
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class CommandLine;
|
|||||||
// |command_line| should be as provided by
|
// |command_line| should be as provided by
|
||||||
// |GetMultiProcessTestChildBaseCommandLine()| (below), possibly with arguments
|
// |GetMultiProcessTestChildBaseCommandLine()| (below), possibly with arguments
|
||||||
// added. Note: On Windows, you probably want to set |options.start_hidden|.
|
// added. Note: On Windows, you probably want to set |options.start_hidden|.
|
||||||
ProcessHandle SpawnMultiProcessTestChild(
|
Process SpawnMultiProcessTestChild(
|
||||||
const std::string& procname,
|
const std::string& procname,
|
||||||
const CommandLine& command_line,
|
const CommandLine& command_line,
|
||||||
const LaunchOptions& options);
|
const LaunchOptions& options);
|
||||||
@@ -105,14 +105,14 @@ class MultiProcessTest : public PlatformTest {
|
|||||||
// // do client work here
|
// // do client work here
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Returns the handle to the child, or NULL on failure
|
// Returns the child process.
|
||||||
ProcessHandle SpawnChild(const std::string& procname);
|
Process SpawnChild(const std::string& procname);
|
||||||
|
|
||||||
// Run a child process using the given launch options.
|
// Run a child process using the given launch options.
|
||||||
//
|
//
|
||||||
// Note: On Windows, you probably want to set |options.start_hidden|.
|
// Note: On Windows, you probably want to set |options.start_hidden|.
|
||||||
ProcessHandle SpawnChildWithOptions(const std::string& procname,
|
Process SpawnChildWithOptions(const std::string& procname,
|
||||||
const LaunchOptions& options);
|
const LaunchOptions& options);
|
||||||
|
|
||||||
// Set up the command line used to spawn the child process.
|
// Set up the command line used to spawn the child process.
|
||||||
// Override this to add things to the command line (calling this first in the
|
// Override this to add things to the command line (calling this first in the
|
||||||
|
@@ -19,9 +19,9 @@ namespace base {
|
|||||||
// and we don't have an executable to exec*. This implementation does the bare
|
// and we don't have an executable to exec*. This implementation does the bare
|
||||||
// minimum to execute the method specified by procname (in the child process).
|
// minimum to execute the method specified by procname (in the child process).
|
||||||
// - All options except |fds_to_remap| are ignored.
|
// - All options except |fds_to_remap| are ignored.
|
||||||
ProcessHandle SpawnMultiProcessTestChild(const std::string& procname,
|
Process SpawnMultiProcessTestChild(const std::string& procname,
|
||||||
const CommandLine& base_command_line,
|
const CommandLine& base_command_line,
|
||||||
const LaunchOptions& options) {
|
const LaunchOptions& options) {
|
||||||
// TODO(viettrungluu): The FD-remapping done below is wrong in the presence of
|
// TODO(viettrungluu): The FD-remapping done below is wrong in the presence of
|
||||||
// cycles (e.g., fd1 -> fd2, fd2 -> fd1). crbug.com/326576
|
// cycles (e.g., fd1 -> fd2, fd2 -> fd1). crbug.com/326576
|
||||||
FileHandleMappingVector empty;
|
FileHandleMappingVector empty;
|
||||||
@@ -32,11 +32,11 @@ ProcessHandle SpawnMultiProcessTestChild(const std::string& procname,
|
|||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
PLOG(ERROR) << "fork";
|
PLOG(ERROR) << "fork";
|
||||||
return kNullProcessHandle;
|
return Process();
|
||||||
}
|
}
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
// Parent process.
|
// Parent process.
|
||||||
return pid;
|
return Process(pid);
|
||||||
}
|
}
|
||||||
// Child process.
|
// Child process.
|
||||||
base::hash_set<int> fds_to_keep_open;
|
base::hash_set<int> fds_to_keep_open;
|
||||||
@@ -69,7 +69,7 @@ ProcessHandle SpawnMultiProcessTestChild(const std::string& procname,
|
|||||||
command_line->AppendSwitchASCII(switches::kTestChildProcess, procname);
|
command_line->AppendSwitchASCII(switches::kTestChildProcess, procname);
|
||||||
|
|
||||||
_exit(multi_process_function_list::InvokeChildProcessTest(procname));
|
_exit(multi_process_function_list::InvokeChildProcessTest(procname));
|
||||||
return 0;
|
return Process();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/message_loop/message_loop.h"
|
#include "base/message_loop/message_loop.h"
|
||||||
#include "base/process/kill.h"
|
#include "base/process/kill.h"
|
||||||
|
#include "base/process/process.h"
|
||||||
#include "base/rand_util.h"
|
#include "base/rand_util.h"
|
||||||
#include "base/synchronization/waitable_event.h"
|
#include "base/synchronization/waitable_event.h"
|
||||||
#include "base/test/multiprocess_test.h"
|
#include "base/test/multiprocess_test.h"
|
||||||
@@ -308,10 +309,10 @@ class CloudPrintProxyPolicyStartupTest : public base::MultiProcessTest,
|
|||||||
scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() {
|
scoped_refptr<base::MessageLoopProxy> IOMessageLoopProxy() {
|
||||||
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
|
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
|
||||||
}
|
}
|
||||||
base::ProcessHandle Launch(const std::string& name);
|
base::Process Launch(const std::string& name);
|
||||||
void WaitForConnect();
|
void WaitForConnect();
|
||||||
bool Send(IPC::Message* message);
|
bool Send(IPC::Message* message);
|
||||||
void ShutdownAndWaitForExitWithTimeout(base::ProcessHandle handle);
|
void ShutdownAndWaitForExitWithTimeout(base::Process process);
|
||||||
|
|
||||||
// IPC::Listener implementation
|
// IPC::Listener implementation
|
||||||
bool OnMessageReceived(const IPC::Message& message) override { return false; }
|
bool OnMessageReceived(const IPC::Message& message) override { return false; }
|
||||||
@@ -430,7 +431,7 @@ void CloudPrintProxyPolicyStartupTest::TearDown() {
|
|||||||
TestingBrowserProcess::DeleteInstance();
|
TestingBrowserProcess::DeleteInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch(
|
base::Process CloudPrintProxyPolicyStartupTest::Launch(
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
EXPECT_FALSE(CheckServiceProcessReady());
|
EXPECT_FALSE(CheckServiceProcessReady());
|
||||||
|
|
||||||
@@ -450,12 +451,12 @@ base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch(
|
|||||||
kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
|
kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
|
||||||
base::LaunchOptions options;
|
base::LaunchOptions options;
|
||||||
options.fds_to_remap = &ipc_file_list;
|
options.fds_to_remap = &ipc_file_list;
|
||||||
base::ProcessHandle handle = SpawnChildWithOptions(name, options);
|
base::Process process = SpawnChildWithOptions(name, options);
|
||||||
#else
|
#else
|
||||||
base::ProcessHandle handle = SpawnChild(name);
|
base::Process process = SpawnChild(name);
|
||||||
#endif
|
#endif
|
||||||
EXPECT_TRUE(handle);
|
EXPECT_TRUE(process.IsValid());
|
||||||
return handle;
|
return process.Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudPrintProxyPolicyStartupTest::WaitForConnect() {
|
void CloudPrintProxyPolicyStartupTest::WaitForConnect() {
|
||||||
@@ -474,16 +475,14 @@ bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout(
|
void CloudPrintProxyPolicyStartupTest::ShutdownAndWaitForExitWithTimeout(
|
||||||
base::ProcessHandle handle) {
|
base::Process process) {
|
||||||
ASSERT_TRUE(Send(new ServiceMsg_Shutdown()));
|
ASSERT_TRUE(Send(new ServiceMsg_Shutdown()));
|
||||||
|
|
||||||
int exit_code = -100;
|
int exit_code = -100;
|
||||||
bool exited =
|
bool exited = process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
|
||||||
base::WaitForExitCodeWithTimeout(handle, &exit_code,
|
&exit_code);
|
||||||
TestTimeouts::action_timeout());
|
|
||||||
EXPECT_TRUE(exited);
|
EXPECT_TRUE(exited);
|
||||||
EXPECT_EQ(exit_code, 0);
|
EXPECT_EQ(exit_code, 0);
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) {
|
void CloudPrintProxyPolicyStartupTest::OnChannelConnected(int32 peer_pid) {
|
||||||
@@ -511,10 +510,10 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartAndShutdown) {
|
|||||||
// constructed.
|
// constructed.
|
||||||
chrome::TestingIOThreadState testing_io_thread_state;
|
chrome::TestingIOThreadState testing_io_thread_state;
|
||||||
|
|
||||||
base::ProcessHandle handle =
|
base::Process process =
|
||||||
Launch("CloudPrintMockService_StartEnabledWaitForQuit");
|
Launch("CloudPrintMockService_StartEnabledWaitForQuit");
|
||||||
WaitForConnect();
|
WaitForConnect();
|
||||||
ShutdownAndWaitForExitWithTimeout(handle);
|
ShutdownAndWaitForExitWithTimeout(process.Pass());
|
||||||
content::RunAllPendingInMessageLoop();
|
content::RunAllPendingInMessageLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +526,7 @@ KeyedService* CloudPrintProxyServiceFactoryForPolicyTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) {
|
TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) {
|
||||||
base::ProcessHandle handle =
|
base::Process process =
|
||||||
Launch("CloudPrintMockService_StartEnabledWaitForQuit");
|
Launch("CloudPrintMockService_StartEnabledWaitForQuit");
|
||||||
|
|
||||||
// Setup the Browser Process with a full IOThread::Globals.
|
// Setup the Browser Process with a full IOThread::Globals.
|
||||||
@@ -571,13 +570,13 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithoutPolicy) {
|
|||||||
EXPECT_EQ(MockServiceIPCServer::EnabledUserId(),
|
EXPECT_EQ(MockServiceIPCServer::EnabledUserId(),
|
||||||
prefs->GetString(prefs::kCloudPrintEmail));
|
prefs->GetString(prefs::kCloudPrintEmail));
|
||||||
|
|
||||||
ShutdownAndWaitForExitWithTimeout(handle);
|
ShutdownAndWaitForExitWithTimeout(process.Pass());
|
||||||
content::RunAllPendingInMessageLoop();
|
content::RunAllPendingInMessageLoop();
|
||||||
profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy");
|
profile_manager.DeleteTestingProfile("StartBrowserWithoutPolicy");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
|
TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
|
||||||
base::ProcessHandle handle =
|
base::Process process =
|
||||||
Launch("CloudPrintMockService_StartEnabledExpectDisabled");
|
Launch("CloudPrintMockService_StartEnabledExpectDisabled");
|
||||||
|
|
||||||
TestingBrowserProcess* browser_process =
|
TestingBrowserProcess* browser_process =
|
||||||
@@ -622,7 +621,7 @@ TEST_F(CloudPrintProxyPolicyStartupTest, StartBrowserWithPolicy) {
|
|||||||
|
|
||||||
EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail));
|
EXPECT_EQ("", prefs->GetString(prefs::kCloudPrintEmail));
|
||||||
|
|
||||||
ShutdownAndWaitForExitWithTimeout(handle);
|
ShutdownAndWaitForExitWithTimeout(process.Pass());
|
||||||
content::RunAllPendingInMessageLoop();
|
content::RunAllPendingInMessageLoop();
|
||||||
profile_manager.DeleteTestingProfile("StartBrowserWithPolicy");
|
profile_manager.DeleteTestingProfile("StartBrowserWithPolicy");
|
||||||
}
|
}
|
||||||
|
@@ -51,20 +51,20 @@ std::string MultiProcessLockTest::GenerateLockName() {
|
|||||||
|
|
||||||
void MultiProcessLockTest::ExpectLockIsLocked(const std::string &name) {
|
void MultiProcessLockTest::ExpectLockIsLocked(const std::string &name) {
|
||||||
ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
|
ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
|
||||||
base::ProcessHandle handle = SpawnChild("MultiProcessLockTryFailMain");
|
base::Process process = SpawnChild("MultiProcessLockTryFailMain");
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code));
|
EXPECT_TRUE(process.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(exit_code, 0);
|
EXPECT_EQ(exit_code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiProcessLockTest::ExpectLockIsUnlocked(
|
void MultiProcessLockTest::ExpectLockIsUnlocked(
|
||||||
const std::string &name) {
|
const std::string &name) {
|
||||||
ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
|
ScopedEnvironmentVariable var(kLockEnviromentVarName, name);
|
||||||
base::ProcessHandle handle = SpawnChild("MultiProcessLockTrySucceedMain");
|
base::Process process = SpawnChild("MultiProcessLockTrySucceedMain");
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code));
|
EXPECT_TRUE(process.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(exit_code, 0);
|
EXPECT_EQ(exit_code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -94,10 +94,10 @@ void ServiceProcessStateTest::SetUp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServiceProcessStateTest::LaunchAndWait(const std::string& name) {
|
void ServiceProcessStateTest::LaunchAndWait(const std::string& name) {
|
||||||
base::ProcessHandle handle = SpawnChild(name);
|
base::Process process = SpawnChild(name);
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
ASSERT_TRUE(base::WaitForExitCode(handle, &exit_code));
|
ASSERT_TRUE(process.WaitForExit(&exit_code));
|
||||||
ASSERT_EQ(exit_code, 0);
|
ASSERT_EQ(exit_code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ TEST_F(ServiceProcessStateTest, DISABLED_SharedMem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) {
|
TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) {
|
||||||
base::ProcessHandle handle = SpawnChild("ServiceProcessStateTestShutdown");
|
base::Process process = SpawnChild("ServiceProcessStateTestShutdown");
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) {
|
for (int i = 0; !CheckServiceProcessReady() && i < 10; ++i) {
|
||||||
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
|
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
|
||||||
}
|
}
|
||||||
@@ -198,9 +198,8 @@ TEST_F(ServiceProcessStateTest, MAYBE_ForceShutdown) {
|
|||||||
ASSERT_TRUE(GetServiceProcessData(&version, &pid));
|
ASSERT_TRUE(GetServiceProcessData(&version, &pid));
|
||||||
ASSERT_TRUE(ForceServiceProcessShutdown(version, pid));
|
ASSERT_TRUE(ForceServiceProcessShutdown(version, pid));
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
ASSERT_TRUE(base::WaitForExitCodeWithTimeout(handle,
|
ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
|
||||||
&exit_code, TestTimeouts::action_max_timeout()));
|
&exit_code));
|
||||||
base::CloseProcessHandle(handle);
|
|
||||||
ASSERT_EQ(exit_code, 0);
|
ASSERT_EQ(exit_code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,8 +50,7 @@ class ScopedSleeperProcess {
|
|||||||
base::CommandLine cmd_line(base::GetMultiProcessTestChildBaseCommandLine());
|
base::CommandLine cmd_line(base::GetMultiProcessTestChildBaseCommandLine());
|
||||||
base::LaunchOptions options;
|
base::LaunchOptions options;
|
||||||
options.start_hidden = true;
|
options.start_hidden = true;
|
||||||
process_ = base::Process(
|
process_ = base::SpawnMultiProcessTestChild("Sleeper", cmd_line, options);
|
||||||
base::SpawnMultiProcessTestChild("Sleeper", cmd_line, options));
|
|
||||||
ASSERT_TRUE(process_.IsValid());
|
ASSERT_TRUE(process_.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,14 +34,14 @@ class MacDirAccessSandboxTest : public base::MultiProcessTest {
|
|||||||
public:
|
public:
|
||||||
bool CheckSandbox(const std::string& directory_to_try) {
|
bool CheckSandbox(const std::string& directory_to_try) {
|
||||||
setenv(kSandboxAccessPathKey, directory_to_try.c_str(), 1);
|
setenv(kSandboxAccessPathKey, directory_to_try.c_str(), 1);
|
||||||
base::ProcessHandle child_process = SpawnChild("mac_sandbox_path_access");
|
base::Process child_process = SpawnChild("mac_sandbox_path_access");
|
||||||
if (child_process == base::kNullProcessHandle) {
|
if (!child_process.IsValid()) {
|
||||||
LOG(WARNING) << "SpawnChild failed";
|
LOG(WARNING) << "SpawnChild failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int code = -1;
|
int code = -1;
|
||||||
if (!base::WaitForExitCode(child_process, &code)) {
|
if (!child_process.WaitForExit(&code)) {
|
||||||
LOG(WARNING) << "base::WaitForExitCode failed";
|
LOG(WARNING) << "Process::WaitForExit failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return code == 0;
|
return code == 0;
|
||||||
|
@@ -77,14 +77,14 @@ bool MacSandboxTest::RunTestInSandbox(SandboxType sandbox_type,
|
|||||||
if (test_data)
|
if (test_data)
|
||||||
setenv(kTestDataKey, test_data, 1);
|
setenv(kTestDataKey, test_data, 1);
|
||||||
|
|
||||||
base::ProcessHandle child_process = SpawnChild("mac_sandbox_test_runner");
|
base::Process child_process = SpawnChild("mac_sandbox_test_runner");
|
||||||
if (child_process == base::kNullProcessHandle) {
|
if (!child_process.IsValid()) {
|
||||||
LOG(WARNING) << "SpawnChild failed";
|
LOG(WARNING) << "SpawnChild failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int code = -1;
|
int code = -1;
|
||||||
if (!base::WaitForExitCode(child_process, &code)) {
|
if (!child_process.WaitForExit(&code)) {
|
||||||
LOG(WARNING) << "base::WaitForExitCode failed";
|
LOG(WARNING) << "Process::WaitForExit failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return code == 0;
|
return code == 0;
|
||||||
|
@@ -293,8 +293,8 @@ TEST_F(IPCChannelPosixTest, AdvancedConnected) {
|
|||||||
ASSERT_TRUE(channel->AcceptsConnections());
|
ASSERT_TRUE(channel->AcceptsConnections());
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
|
|
||||||
base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc");
|
base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
SpinRunLoop(TestTimeouts::action_max_timeout());
|
SpinRunLoop(TestTimeouts::action_max_timeout());
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
||||||
ASSERT_TRUE(channel->HasAcceptedConnection());
|
ASSERT_TRUE(channel->HasAcceptedConnection());
|
||||||
@@ -304,7 +304,7 @@ TEST_F(IPCChannelPosixTest, AdvancedConnected) {
|
|||||||
channel->Send(message);
|
channel->Send(message);
|
||||||
SpinRunLoop(TestTimeouts::action_timeout());
|
SpinRunLoop(TestTimeouts::action_timeout());
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code));
|
EXPECT_TRUE(process.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(0, exit_code);
|
EXPECT_EQ(0, exit_code);
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
@@ -323,16 +323,16 @@ TEST_F(IPCChannelPosixTest, ResetState) {
|
|||||||
ASSERT_TRUE(channel->AcceptsConnections());
|
ASSERT_TRUE(channel->AcceptsConnections());
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
|
|
||||||
base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc");
|
base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
SpinRunLoop(TestTimeouts::action_max_timeout());
|
SpinRunLoop(TestTimeouts::action_max_timeout());
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
||||||
ASSERT_TRUE(channel->HasAcceptedConnection());
|
ASSERT_TRUE(channel->HasAcceptedConnection());
|
||||||
channel->ResetToAcceptingConnectionState();
|
channel->ResetToAcceptingConnectionState();
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
|
|
||||||
base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixTestConnectionProc");
|
base::Process process2 = SpawnChild("IPCChannelPosixTestConnectionProc");
|
||||||
ASSERT_TRUE(handle2);
|
ASSERT_TRUE(process2.IsValid());
|
||||||
SpinRunLoop(TestTimeouts::action_max_timeout());
|
SpinRunLoop(TestTimeouts::action_max_timeout());
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
||||||
ASSERT_TRUE(channel->HasAcceptedConnection());
|
ASSERT_TRUE(channel->HasAcceptedConnection());
|
||||||
@@ -341,9 +341,9 @@ TEST_F(IPCChannelPosixTest, ResetState) {
|
|||||||
IPC::Message::PRIORITY_NORMAL);
|
IPC::Message::PRIORITY_NORMAL);
|
||||||
channel->Send(message);
|
channel->Send(message);
|
||||||
SpinRunLoop(TestTimeouts::action_timeout());
|
SpinRunLoop(TestTimeouts::action_timeout());
|
||||||
EXPECT_TRUE(base::KillProcess(handle, 0, false));
|
EXPECT_TRUE(base::KillProcess(process.Handle(), 0, false));
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code));
|
EXPECT_TRUE(process2.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(0, exit_code);
|
EXPECT_EQ(0, exit_code);
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
@@ -383,16 +383,16 @@ TEST_F(IPCChannelPosixTest, MultiConnection) {
|
|||||||
ASSERT_TRUE(channel->AcceptsConnections());
|
ASSERT_TRUE(channel->AcceptsConnections());
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
|
|
||||||
base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc");
|
base::Process process = SpawnChild("IPCChannelPosixTestConnectionProc");
|
||||||
ASSERT_TRUE(handle);
|
ASSERT_TRUE(process.IsValid());
|
||||||
SpinRunLoop(TestTimeouts::action_max_timeout());
|
SpinRunLoop(TestTimeouts::action_max_timeout());
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status());
|
||||||
ASSERT_TRUE(channel->HasAcceptedConnection());
|
ASSERT_TRUE(channel->HasAcceptedConnection());
|
||||||
base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixFailConnectionProc");
|
base::Process process2 = SpawnChild("IPCChannelPosixFailConnectionProc");
|
||||||
ASSERT_TRUE(handle2);
|
ASSERT_TRUE(process2.IsValid());
|
||||||
SpinRunLoop(TestTimeouts::action_max_timeout());
|
SpinRunLoop(TestTimeouts::action_max_timeout());
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code));
|
EXPECT_TRUE(process2.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(exit_code, 0);
|
EXPECT_EQ(exit_code, 0);
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status());
|
||||||
ASSERT_TRUE(channel->HasAcceptedConnection());
|
ASSERT_TRUE(channel->HasAcceptedConnection());
|
||||||
@@ -401,7 +401,7 @@ TEST_F(IPCChannelPosixTest, MultiConnection) {
|
|||||||
IPC::Message::PRIORITY_NORMAL);
|
IPC::Message::PRIORITY_NORMAL);
|
||||||
channel->Send(message);
|
channel->Send(message);
|
||||||
SpinRunLoop(TestTimeouts::action_timeout());
|
SpinRunLoop(TestTimeouts::action_timeout());
|
||||||
EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code));
|
EXPECT_TRUE(process.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(exit_code, 0);
|
EXPECT_EQ(exit_code, 0);
|
||||||
ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
|
ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
|
||||||
ASSERT_FALSE(channel->HasAcceptedConnection());
|
ASSERT_FALSE(channel->HasAcceptedConnection());
|
||||||
|
@@ -22,8 +22,7 @@ std::string IPCTestBase::GetChannelName(const std::string& test_client_name) {
|
|||||||
return test_client_name + "__Channel";
|
return test_client_name + "__Channel";
|
||||||
}
|
}
|
||||||
|
|
||||||
IPCTestBase::IPCTestBase()
|
IPCTestBase::IPCTestBase() {
|
||||||
: client_process_(base::kNullProcessHandle) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IPCTestBase::~IPCTestBase() {
|
IPCTestBase::~IPCTestBase() {
|
||||||
@@ -104,8 +103,8 @@ std::string IPCTestBase::GetTestMainName() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IPCTestBase::DidStartClient() {
|
bool IPCTestBase::DidStartClient() {
|
||||||
DCHECK_NE(base::kNullProcessHandle, client_process_);
|
DCHECK(client_process_.IsValid());
|
||||||
return client_process_ != base::kNullProcessHandle;
|
return client_process_.IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(OS_POSIX)
|
#if defined(OS_POSIX)
|
||||||
@@ -117,7 +116,7 @@ bool IPCTestBase::StartClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IPCTestBase::StartClientWithFD(int ipcfd) {
|
bool IPCTestBase::StartClientWithFD(int ipcfd) {
|
||||||
DCHECK_EQ(client_process_, base::kNullProcessHandle);
|
DCHECK(!client_process_.IsValid());
|
||||||
|
|
||||||
base::FileHandleMappingVector fds_to_map;
|
base::FileHandleMappingVector fds_to_map;
|
||||||
if (ipcfd > -1)
|
if (ipcfd > -1)
|
||||||
@@ -133,7 +132,7 @@ bool IPCTestBase::StartClientWithFD(int ipcfd) {
|
|||||||
#elif defined(OS_WIN)
|
#elif defined(OS_WIN)
|
||||||
|
|
||||||
bool IPCTestBase::StartClient() {
|
bool IPCTestBase::StartClient() {
|
||||||
DCHECK_EQ(client_process_, base::kNullProcessHandle);
|
DCHECK(!client_process_.IsValid());
|
||||||
client_process_ = SpawnChild(GetTestMainName());
|
client_process_ = SpawnChild(GetTestMainName());
|
||||||
return DidStartClient();
|
return DidStartClient();
|
||||||
}
|
}
|
||||||
@@ -141,12 +140,11 @@ bool IPCTestBase::StartClient() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool IPCTestBase::WaitForClientShutdown() {
|
bool IPCTestBase::WaitForClientShutdown() {
|
||||||
DCHECK(client_process_ != base::kNullProcessHandle);
|
DCHECK(client_process_.IsValid());
|
||||||
|
|
||||||
bool rv = base::WaitForSingleProcess(client_process_,
|
bool rv = base::WaitForSingleProcess(client_process_.Handle(),
|
||||||
base::TimeDelta::FromSeconds(5));
|
base::TimeDelta::FromSeconds(5));
|
||||||
base::CloseProcessHandle(client_process_);
|
client_process_.Close();
|
||||||
client_process_ = base::kNullProcessHandle;
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ class IPCTestBase : public base::MultiProcessTest {
|
|||||||
IPC::Channel* channel() { return channel_.get(); }
|
IPC::Channel* channel() { return channel_.get(); }
|
||||||
IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); }
|
IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); }
|
||||||
|
|
||||||
const base::ProcessHandle& client_process() const { return client_process_; }
|
const base::Process& client_process() const { return client_process_; }
|
||||||
scoped_refptr<base::TaskRunner> task_runner();
|
scoped_refptr<base::TaskRunner> task_runner();
|
||||||
|
|
||||||
virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
|
virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
|
||||||
@@ -117,7 +117,7 @@ class IPCTestBase : public base::MultiProcessTest {
|
|||||||
scoped_ptr<IPC::Channel> channel_;
|
scoped_ptr<IPC::Channel> channel_;
|
||||||
scoped_ptr<IPC::ChannelProxy> channel_proxy_;
|
scoped_ptr<IPC::ChannelProxy> channel_proxy_;
|
||||||
|
|
||||||
base::ProcessHandle client_process_;
|
base::Process client_process_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(IPCTestBase);
|
DISALLOW_COPY_AND_ASSIGN(IPCTestBase);
|
||||||
};
|
};
|
||||||
|
@@ -89,7 +89,7 @@ class IPCChannelMojoTest : public IPCTestBase {
|
|||||||
bool DidStartClient() override {
|
bool DidStartClient() override {
|
||||||
bool ok = IPCTestBase::DidStartClient();
|
bool ok = IPCTestBase::DidStartClient();
|
||||||
DCHECK(ok);
|
DCHECK(ok);
|
||||||
host_->OnClientLaunched(client_process());
|
host_->OnClientLaunched(client_process().Handle());
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ class IPCChannelMojoErrorTest : public IPCTestBase {
|
|||||||
bool DidStartClient() override {
|
bool DidStartClient() override {
|
||||||
bool ok = IPCTestBase::DidStartClient();
|
bool ok = IPCTestBase::DidStartClient();
|
||||||
DCHECK(ok);
|
DCHECK(ok);
|
||||||
host_->OnClientLaunched(client_process());
|
host_->OnClientLaunched(client_process().Handle());
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,10 +269,11 @@ class IPCChannelMojoDeadHandleTest : public IPCTestBase {
|
|||||||
|
|
||||||
virtual bool DidStartClient() override {
|
virtual bool DidStartClient() override {
|
||||||
IPCTestBase::DidStartClient();
|
IPCTestBase::DidStartClient();
|
||||||
base::ProcessHandle client = client_process();
|
const base::ProcessHandle client = client_process().Handle();
|
||||||
// Forces GetFileHandleForProcess() fail. It happens occasionally
|
// Forces GetFileHandleForProcess() fail. It happens occasionally
|
||||||
// in production, so we should exercise it somehow.
|
// in production, so we should exercise it somehow.
|
||||||
::CloseHandle(client);
|
// TODO(morrita): figure out how to safely test this.
|
||||||
|
// ::CloseHandle(client);
|
||||||
host_->OnClientLaunched(client);
|
host_->OnClientLaunched(client);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ TEST_F(IPCMojoBootstrapTest, Connect) {
|
|||||||
#else
|
#else
|
||||||
ASSERT_TRUE(StartClient());
|
ASSERT_TRUE(StartClient());
|
||||||
#endif
|
#endif
|
||||||
bootstrap->OnClientLaunched(client_process());
|
bootstrap->OnClientLaunched(client_process().Handle());
|
||||||
|
|
||||||
base::MessageLoop::current()->Run();
|
base::MessageLoop::current()->Run();
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ public:
|
|||||||
bool DidStartClient() override {
|
bool DidStartClient() override {
|
||||||
bool ok = IPCTestBase::DidStartClient();
|
bool ok = IPCTestBase::DidStartClient();
|
||||||
DCHECK(ok);
|
DCHECK(ok);
|
||||||
host_->OnClientLaunched(client_process());
|
host_->OnClientLaunched(client_process().Handle());
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -184,7 +184,7 @@ TEST_F(SyncSocketTest, SanityTest) {
|
|||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// On windows we need to duplicate the handle into the server process.
|
// On windows we need to duplicate the handle into the server process.
|
||||||
BOOL retval = DuplicateHandle(GetCurrentProcess(), pair[1].handle(),
|
BOOL retval = DuplicateHandle(GetCurrentProcess(), pair[1].handle(),
|
||||||
client_process(), &target_handle,
|
client_process().Handle(), &target_handle,
|
||||||
0, FALSE, DUPLICATE_SAME_ACCESS);
|
0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||||
EXPECT_TRUE(retval);
|
EXPECT_TRUE(retval);
|
||||||
// Set up a message to pass the handle to the server.
|
// Set up a message to pass the handle to the server.
|
||||||
|
@@ -14,14 +14,13 @@
|
|||||||
namespace mojo {
|
namespace mojo {
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
MultiprocessTestHelper::MultiprocessTestHelper()
|
MultiprocessTestHelper::MultiprocessTestHelper() {
|
||||||
: test_child_handle_(base::kNullProcessHandle) {
|
|
||||||
platform_channel_pair_.reset(new embedder::PlatformChannelPair());
|
platform_channel_pair_.reset(new embedder::PlatformChannelPair());
|
||||||
server_platform_handle = platform_channel_pair_->PassServerHandle();
|
server_platform_handle = platform_channel_pair_->PassServerHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiprocessTestHelper::~MultiprocessTestHelper() {
|
MultiprocessTestHelper::~MultiprocessTestHelper() {
|
||||||
CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
|
CHECK(!test_child_.IsValid());
|
||||||
server_platform_handle.reset();
|
server_platform_handle.reset();
|
||||||
platform_channel_pair_.reset();
|
platform_channel_pair_.reset();
|
||||||
}
|
}
|
||||||
@@ -29,7 +28,7 @@ MultiprocessTestHelper::~MultiprocessTestHelper() {
|
|||||||
void MultiprocessTestHelper::StartChild(const std::string& test_child_name) {
|
void MultiprocessTestHelper::StartChild(const std::string& test_child_name) {
|
||||||
CHECK(platform_channel_pair_);
|
CHECK(platform_channel_pair_);
|
||||||
CHECK(!test_child_name.empty());
|
CHECK(!test_child_name.empty());
|
||||||
CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
|
CHECK(!test_child_.IsValid());
|
||||||
|
|
||||||
std::string test_child_main = test_child_name + "TestChildMain";
|
std::string test_child_main = test_child_name + "TestChildMain";
|
||||||
|
|
||||||
@@ -49,21 +48,20 @@ void MultiprocessTestHelper::StartChild(const std::string& test_child_name) {
|
|||||||
#error "Not supported yet."
|
#error "Not supported yet."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
test_child_handle_ =
|
test_child_ =
|
||||||
base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
|
base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
|
||||||
platform_channel_pair_->ChildProcessLaunched();
|
platform_channel_pair_->ChildProcessLaunched();
|
||||||
|
|
||||||
CHECK_NE(test_child_handle_, base::kNullProcessHandle);
|
CHECK(test_child_.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultiprocessTestHelper::WaitForChildShutdown() {
|
int MultiprocessTestHelper::WaitForChildShutdown() {
|
||||||
CHECK_NE(test_child_handle_, base::kNullProcessHandle);
|
CHECK(test_child_.IsValid());
|
||||||
|
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
CHECK(base::WaitForExitCodeWithTimeout(test_child_handle_, &rv,
|
CHECK(test_child_.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
|
||||||
TestTimeouts::action_timeout()));
|
&rv));
|
||||||
base::CloseProcessHandle(test_child_handle_);
|
test_child_.Close();
|
||||||
test_child_handle_ = base::kNullProcessHandle;
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "base/process/process_handle.h"
|
#include "base/process/process.h"
|
||||||
#include "base/test/multiprocess_test.h"
|
#include "base/test/multiprocess_test.h"
|
||||||
#include "base/test/test_timeouts.h"
|
#include "base/test/test_timeouts.h"
|
||||||
#include "mojo/edk/embedder/scoped_platform_handle.h"
|
#include "mojo/edk/embedder/scoped_platform_handle.h"
|
||||||
@@ -58,7 +58,7 @@ class MultiprocessTestHelper {
|
|||||||
scoped_ptr<embedder::PlatformChannelPair> platform_channel_pair_;
|
scoped_ptr<embedder::PlatformChannelPair> platform_channel_pair_;
|
||||||
|
|
||||||
// Valid after |StartChild()| and before |WaitForChildShutdown()|.
|
// Valid after |StartChild()| and before |WaitForChildShutdown()|.
|
||||||
base::ProcessHandle test_child_handle_;
|
base::Process test_child_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper);
|
DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper);
|
||||||
};
|
};
|
||||||
|
@@ -100,14 +100,14 @@ class BootstrapSandboxTest : public base::MultiProcessTest {
|
|||||||
sandbox_->PrepareToForkWithPolicy(policy_id);
|
sandbox_->PrepareToForkWithPolicy(policy_id);
|
||||||
base::LaunchOptions options;
|
base::LaunchOptions options;
|
||||||
options.replacement_bootstrap_name = sandbox_->server_bootstrap_name();
|
options.replacement_bootstrap_name = sandbox_->server_bootstrap_name();
|
||||||
base::ProcessHandle pid = SpawnChildWithOptions(child_name, options);
|
base::Process process = SpawnChildWithOptions(child_name, options);
|
||||||
ASSERT_GT(pid, 0);
|
ASSERT_TRUE(process.IsValid());
|
||||||
sandbox_->FinishedFork(pid);
|
sandbox_->FinishedFork(process.Handle());
|
||||||
int code = 0;
|
int code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(pid, &code));
|
EXPECT_TRUE(process.WaitForExit(&code));
|
||||||
EXPECT_EQ(0, code);
|
EXPECT_EQ(0, code);
|
||||||
if (out_pid)
|
if (out_pid)
|
||||||
*out_pid = pid;
|
*out_pid = process.pid();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -121,15 +121,15 @@ TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) {
|
|||||||
base::scoped_nsobject<DistributedNotificationObserver> observer(
|
base::scoped_nsobject<DistributedNotificationObserver> observer(
|
||||||
[[DistributedNotificationObserver alloc] init]);
|
[[DistributedNotificationObserver alloc] init]);
|
||||||
|
|
||||||
base::ProcessHandle pid = SpawnChild(kNotificationTestMain);
|
base::Process process = SpawnChild(kNotificationTestMain);
|
||||||
ASSERT_GT(pid, 0);
|
ASSERT_TRUE(process.IsValid());
|
||||||
int code = 0;
|
int code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(pid, &code));
|
EXPECT_TRUE(process.WaitForExit(&code));
|
||||||
EXPECT_EQ(0, code);
|
EXPECT_EQ(0, code);
|
||||||
|
|
||||||
[observer waitForNotification];
|
[observer waitForNotification];
|
||||||
EXPECT_EQ(1, [observer receivedCount]);
|
EXPECT_EQ(1, [observer receivedCount]);
|
||||||
EXPECT_EQ(pid, [[observer object] intValue]);
|
EXPECT_EQ(process.pid(), [[observer object] intValue]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the test with the sandbox enabled without notifications on the policy
|
// Run the test with the sandbox enabled without notifications on the policy
|
||||||
@@ -439,10 +439,9 @@ TEST_F(BootstrapSandboxTest, ChildOutliveSandbox) {
|
|||||||
sandbox_->PrepareToForkWithPolicy(kTestPolicyId);
|
sandbox_->PrepareToForkWithPolicy(kTestPolicyId);
|
||||||
base::LaunchOptions options;
|
base::LaunchOptions options;
|
||||||
options.replacement_bootstrap_name = sandbox_->server_bootstrap_name();
|
options.replacement_bootstrap_name = sandbox_->server_bootstrap_name();
|
||||||
base::ProcessHandle pid =
|
base::Process process = SpawnChildWithOptions("ChildOutliveSandbox", options);
|
||||||
SpawnChildWithOptions("ChildOutliveSandbox", options);
|
ASSERT_TRUE(process.IsValid());
|
||||||
ASSERT_GT(pid, 0);
|
sandbox_->FinishedFork(process.Handle());
|
||||||
sandbox_->FinishedFork(pid);
|
|
||||||
|
|
||||||
// Synchronize with the child.
|
// Synchronize with the child.
|
||||||
mach_msg_empty_rcv_t rcv_msg;
|
mach_msg_empty_rcv_t rcv_msg;
|
||||||
@@ -468,7 +467,7 @@ TEST_F(BootstrapSandboxTest, ChildOutliveSandbox) {
|
|||||||
EXPECT_EQ(KERN_SUCCESS, kr) << mach_error_string(kr);
|
EXPECT_EQ(KERN_SUCCESS, kr) << mach_error_string(kr);
|
||||||
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
EXPECT_TRUE(base::WaitForExitCode(pid, &code));
|
EXPECT_TRUE(process.WaitForExit(&code));
|
||||||
EXPECT_EQ(0, code);
|
EXPECT_EQ(0, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -149,21 +149,19 @@ XPC_TEST_F(GetSenderPID) // {
|
|||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
ASSERT_EQ(KERN_SUCCESS, kr);
|
ASSERT_EQ(KERN_SUCCESS, kr);
|
||||||
|
|
||||||
base::ProcessHandle child_handle = base::SpawnMultiProcessTestChild(
|
base::Process child = base::SpawnMultiProcessTestChild(
|
||||||
"GetSenderPID",
|
"GetSenderPID",
|
||||||
base::GetMultiProcessTestChildBaseCommandLine(),
|
base::GetMultiProcessTestChildBaseCommandLine(),
|
||||||
base::LaunchOptions());
|
base::LaunchOptions());
|
||||||
ASSERT_NE(base::kNullProcessHandle, child_handle);
|
ASSERT_TRUE(child.IsValid());
|
||||||
|
|
||||||
int exit_code = -1;
|
int exit_code = -1;
|
||||||
ASSERT_TRUE(base::WaitForExitCode(child_handle, &exit_code));
|
ASSERT_TRUE(child.WaitForExit(&exit_code));
|
||||||
EXPECT_EQ(0, exit_code);
|
EXPECT_EQ(0, exit_code);
|
||||||
|
|
||||||
EXPECT_EQ(base::GetProcId(child_handle), sender_pid);
|
EXPECT_EQ(child.pid(), sender_pid);
|
||||||
EXPECT_EQ(base::GetProcId(child_handle), child_pid);
|
EXPECT_EQ(child.pid(), child_pid);
|
||||||
EXPECT_EQ(sender_pid, child_pid);
|
EXPECT_EQ(sender_pid, child_pid);
|
||||||
|
|
||||||
base::CloseProcessHandle(child_handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MULTIPROCESS_TEST_MAIN(GetSenderPID) {
|
MULTIPROCESS_TEST_MAIN(GetSenderPID) {
|
||||||
|
Reference in New Issue
Block a user