Index: base/process/process_util_unittest.cc |
diff --git a/base/process/process_util_unittest.cc b/base/process/process_util_unittest.cc |
index 11d8874a52ab9576cd9ec5b1f2d08c9808655ac5..1f7f1b2c776edcfe2942c7564a74a209942804ec 100644 |
--- a/base/process/process_util_unittest.cc |
+++ b/base/process/process_util_unittest.cc |
@@ -75,6 +75,10 @@ const char kPosixShell[] = "bash"; |
const char kSignalFileSlow[] = "SlowChildProcess.die"; |
const char kSignalFileKill[] = "KilledChildProcess.die"; |
+#if defined(OS_POSIX) |
+const char kSignalFileTerm[] = "TerminatedChildProcess.die"; |
+#endif |
+ |
#if defined(OS_WIN) |
const int kExpectedStillRunningExitCode = 0x102; |
const int kExpectedKilledExitCode = 1; |
@@ -286,7 +290,16 @@ MULTIPROCESS_TEST_MAIN(KilledChildProcess) { |
return 1; |
} |
-TEST_F(ProcessUtilTest, GetTerminationStatusKill) { |
+#if defined(OS_POSIX) |
+MULTIPROCESS_TEST_MAIN(TerminatedChildProcess) { |
+ WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileTerm).c_str()); |
+ // Send a SIGTERM to this process. |
+ ::kill(getpid(), SIGTERM); |
+ return 1; |
+} |
+#endif |
+ |
+TEST_F(ProcessUtilTest, GetTerminationStatusSigKill) { |
const std::string signal_file = |
ProcessUtilTest::GetSignalFilePath(kSignalFileKill); |
remove(signal_file.c_str()); |
@@ -302,7 +315,12 @@ TEST_F(ProcessUtilTest, GetTerminationStatusKill) { |
exit_code = 42; |
base::TerminationStatus status = |
WaitForChildTermination(process.Handle(), &exit_code); |
+#if defined(OS_CHROMEOS) |
+ EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM, status); |
+#else |
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status); |
+#endif |
+ |
#if defined(OS_WIN) |
EXPECT_EQ(kExpectedKilledExitCode, exit_code); |
#elif defined(OS_POSIX) |
@@ -314,6 +332,33 @@ TEST_F(ProcessUtilTest, GetTerminationStatusKill) { |
remove(signal_file.c_str()); |
} |
+#if defined(OS_POSIX) |
+TEST_F(ProcessUtilTest, GetTerminationStatusSigTerm) { |
+ const std::string signal_file = |
+ ProcessUtilTest::GetSignalFilePath(kSignalFileTerm); |
+ remove(signal_file.c_str()); |
+ base::Process process = SpawnChild("TerminatedChildProcess"); |
+ ASSERT_TRUE(process.IsValid()); |
+ |
+ int exit_code = 42; |
+ EXPECT_EQ(base::TERMINATION_STATUS_STILL_RUNNING, |
+ base::GetTerminationStatus(process.Handle(), &exit_code)); |
+ EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); |
+ |
+ SignalChildren(signal_file.c_str()); |
+ exit_code = 42; |
+ base::TerminationStatus status = |
+ WaitForChildTermination(process.Handle(), &exit_code); |
+ EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status); |
+ |
+ int signaled = WIFSIGNALED(exit_code); |
+ EXPECT_NE(0, signaled); |
+ int signal = WTERMSIG(exit_code); |
+ EXPECT_EQ(SIGTERM, signal); |
+ remove(signal_file.c_str()); |
+} |
+#endif |
+ |
#if defined(OS_WIN) |
// TODO(estade): if possible, port this test. |
TEST_F(ProcessUtilTest, GetAppOutput) { |