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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 base::ProcessId id1 = base::GetProcId(GetCurrentProcess()); | 250 base::ProcessId id1 = base::GetProcId(GetCurrentProcess()); |
251 EXPECT_NE(0ul, id1); | 251 EXPECT_NE(0ul, id1); |
252 base::Process process = SpawnChild("SimpleChildProcess"); | 252 base::Process process = SpawnChild("SimpleChildProcess"); |
253 ASSERT_TRUE(process.IsValid()); | 253 ASSERT_TRUE(process.IsValid()); |
254 base::ProcessId id2 = process.Pid(); | 254 base::ProcessId id2 = process.Pid(); |
255 EXPECT_NE(0ul, id2); | 255 EXPECT_NE(0ul, id2); |
256 EXPECT_NE(id1, id2); | 256 EXPECT_NE(id1, id2); |
257 } | 257 } |
258 #endif // defined(OS_WIN) | 258 #endif // defined(OS_WIN) |
259 | 259 |
260 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 260 #if !defined(OS_MACOSX) |
261 // This test is disabled on Mac, since it's flaky due to ReportCrash | 261 // This test is disabled on Mac, since it's flaky due to ReportCrash |
262 // taking a variable amount of time to parse and load the debug and | 262 // taking a variable amount of time to parse and load the debug and |
263 // symbol data for this unit test's executable before firing the | 263 // symbol data for this unit test's executable before firing the |
264 // signal handler. | 264 // signal handler. |
265 // | 265 // |
266 // TODO(gspencer): turn this test process into a very small program | 266 // TODO(gspencer): turn this test process into a very small program |
267 // with no symbols (instead of using the multiprocess testing | 267 // with no symbols (instead of using the multiprocess testing |
268 // framework) to reduce the ReportCrash overhead. | 268 // framework) to reduce the ReportCrash overhead. |
269 // | |
270 // It is disabled on Android as MultiprocessTests are started as services that | |
271 // the framework restarts on crashes. | |
272 const char kSignalFileCrash[] = "CrashingChildProcess.die"; | 269 const char kSignalFileCrash[] = "CrashingChildProcess.die"; |
273 | 270 |
274 MULTIPROCESS_TEST_MAIN(CrashingChildProcess) { | 271 MULTIPROCESS_TEST_MAIN(CrashingChildProcess) { |
275 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileCrash).c_str()); | 272 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileCrash).c_str()); |
276 #if defined(OS_POSIX) | 273 #if defined(OS_ANDROID) |
| 274 // Android L+ expose signal and sigaction symbols that override the system |
| 275 // ones. There is a bug in these functions where a request to set the handler |
| 276 // to SIG_DFL is ignored. In that case, an infinite loop is entered as the |
| 277 // signal is repeatedly sent to the crash dump signal handler. |
| 278 // To work around this, directly call the system's sigaction. |
| 279 struct kernel_sigaction sa; |
| 280 memset(&sa, 0, sizeof(sa)); |
| 281 sys_sigemptyset(&sa.sa_mask); |
| 282 sa.sa_handler_ = SIG_DFL; |
| 283 sa.sa_flags = SA_RESTART; |
| 284 sys_rt_sigaction(SIGSEGV, &sa, NULL, sizeof(kernel_sigset_t)); |
| 285 #elif defined(OS_POSIX) |
277 // Have to disable to signal handler for segv so we can get a crash | 286 // Have to disable to signal handler for segv so we can get a crash |
278 // instead of an abnormal termination through the crash dump handler. | 287 // instead of an abnormal termination through the crash dump handler. |
279 ::signal(SIGSEGV, SIG_DFL); | 288 ::signal(SIGSEGV, SIG_DFL); |
280 #endif | 289 #endif |
281 // Make this process have a segmentation fault. | 290 // Make this process have a segmentation fault. |
282 volatile int* oops = NULL; | 291 volatile int* oops = NULL; |
283 *oops = 0xDEAD; | 292 *oops = 0xDEAD; |
284 return 1; | 293 return 1; |
285 } | 294 } |
286 | 295 |
(...skipping 28 matching lines...) Expand all Loading... |
315 int signaled = WIFSIGNALED(exit_code); | 324 int signaled = WIFSIGNALED(exit_code); |
316 EXPECT_NE(0, signaled); | 325 EXPECT_NE(0, signaled); |
317 int signal = WTERMSIG(exit_code); | 326 int signal = WTERMSIG(exit_code); |
318 EXPECT_EQ(SIGSEGV, signal); | 327 EXPECT_EQ(SIGSEGV, signal); |
319 #endif | 328 #endif |
320 | 329 |
321 // Reset signal handlers back to "normal". | 330 // Reset signal handlers back to "normal". |
322 base::debug::EnableInProcessStackDumping(); | 331 base::debug::EnableInProcessStackDumping(); |
323 remove(signal_file.c_str()); | 332 remove(signal_file.c_str()); |
324 } | 333 } |
325 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) | 334 #endif // !defined(OS_MACOSX) |
326 | 335 |
327 MULTIPROCESS_TEST_MAIN(KilledChildProcess) { | 336 MULTIPROCESS_TEST_MAIN(KilledChildProcess) { |
328 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileKill).c_str()); | 337 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileKill).c_str()); |
329 #if defined(OS_WIN) | 338 #if defined(OS_WIN) |
330 // Kill ourselves. | 339 // Kill ourselves. |
331 HANDLE handle = ::OpenProcess(PROCESS_ALL_ACCESS, 0, ::GetCurrentProcessId()); | 340 HANDLE handle = ::OpenProcess(PROCESS_ALL_ACCESS, 0, ::GetCurrentProcessId()); |
332 ::TerminateProcess(handle, kExpectedKilledExitCode); | 341 ::TerminateProcess(handle, kExpectedKilledExitCode); |
333 #elif defined(OS_POSIX) | 342 #elif defined(OS_POSIX) |
334 // Send a SIGKILL to this process, just like the OOM killer would. | 343 // Send a SIGKILL to this process, just like the OOM killer would. |
335 ::kill(getpid(), SIGKILL); | 344 ::kill(getpid(), SIGKILL); |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 options.current_directory = base::FilePath("/dev/null"); | 1020 options.current_directory = base::FilePath("/dev/null"); |
1012 | 1021 |
1013 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); | 1022 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); |
1014 ASSERT_TRUE(process.IsValid()); | 1023 ASSERT_TRUE(process.IsValid()); |
1015 | 1024 |
1016 int exit_code = kSuccess; | 1025 int exit_code = kSuccess; |
1017 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 1026 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
1018 EXPECT_NE(kSuccess, exit_code); | 1027 EXPECT_NE(kSuccess, exit_code); |
1019 } | 1028 } |
1020 #endif // defined(OS_LINUX) | 1029 #endif // defined(OS_LINUX) |
OLD | NEW |