aboutsummaryrefslogtreecommitdiff
path: root/src/client/linux/handler/exception_handler_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/linux/handler/exception_handler_unittest.cc')
-rw-r--r--src/client/linux/handler/exception_handler_unittest.cc37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/client/linux/handler/exception_handler_unittest.cc b/src/client/linux/handler/exception_handler_unittest.cc
index 27808aa1..691ea133 100644
--- a/src/client/linux/handler/exception_handler_unittest.cc
+++ b/src/client/linux/handler/exception_handler_unittest.cc
@@ -1,5 +1,4 @@
-// Copyright (c) 2010 Google Inc.
-// All rights reserved.
+// Copyright 2010 Google LLC
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -11,7 +10,7 @@
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
-// * Neither the name of Google Inc. nor the names of its
+// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
@@ -201,7 +200,7 @@ static bool DoneCallback(const MinidumpDescriptor& descriptor,
// optimize them out. In the case of ExceptionHandlerTest::ExternalDumper,
// GCC-4.9 optimized out the entire set up of ExceptionHandler, causing
// test failure.
-volatile int *p_null; // external linkage, so GCC can't tell that it
+volatile int* p_null; // external linkage, so GCC can't tell that it
// remains NULL. Volatile just for a good measure.
static void DoNullPointerDereference() {
*p_null = 1;
@@ -306,8 +305,22 @@ TEST(ExceptionHandlerTest, ParallelChildCrashesDontHang) {
}
}
- // Wait a while until the child should have crashed.
- usleep(1000000);
+ // Poll the child to see if it crashed.
+ int status, wp_pid;
+ for (int i = 0; i < 100; i++) {
+ wp_pid = HANDLE_EINTR(waitpid(child, &status, WNOHANG));
+ ASSERT_NE(-1, wp_pid);
+ if (wp_pid > 0) {
+ ASSERT_TRUE(WIFSIGNALED(status));
+ // If the child process terminated by itself,
+ // it will have returned SIGSEGV.
+ ASSERT_EQ(SIGSEGV, WTERMSIG(status));
+ return;
+ } else {
+ usleep(100000);
+ }
+ }
+
// Kill the child if it is still running.
kill(child, SIGKILL);
@@ -649,7 +662,7 @@ TEST(ExceptionHandlerTest, InstructionPointerMemory) {
memset(prefix_bytes, 0, sizeof(prefix_bytes));
memset(suffix_bytes, 0, sizeof(suffix_bytes));
EXPECT_TRUE(memcmp(bytes, prefix_bytes, sizeof(prefix_bytes)) == 0);
- EXPECT_TRUE(memcmp(bytes + kOffset, kIllegalInstruction,
+ EXPECT_TRUE(memcmp(bytes + kOffset, kIllegalInstruction,
sizeof(kIllegalInstruction)) == 0);
EXPECT_TRUE(memcmp(bytes + kOffset + sizeof(kIllegalInstruction),
suffix_bytes, sizeof(suffix_bytes)) == 0);
@@ -738,7 +751,7 @@ TEST(ExceptionHandlerTest, InstructionPointerMemoryMinBound) {
uint8_t suffix_bytes[kMemorySize / 2 - sizeof(kIllegalInstruction)];
memset(suffix_bytes, 0, sizeof(suffix_bytes));
- EXPECT_TRUE(memcmp(bytes + kOffset, kIllegalInstruction,
+ EXPECT_TRUE(memcmp(bytes + kOffset, kIllegalInstruction,
sizeof(kIllegalInstruction)) == 0);
EXPECT_TRUE(memcmp(bytes + kOffset + sizeof(kIllegalInstruction),
suffix_bytes, sizeof(suffix_bytes)) == 0);
@@ -994,7 +1007,7 @@ CrashHandler(const void* crash_context, size_t crash_context_size,
msg.msg_control = cmsg;
msg.msg_controllen = sizeof(cmsg);
- struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
+ struct cmsghdr* hdr = CMSG_FIRSTHDR(&msg);
hdr->cmsg_level = SOL_SOCKET;
hdr->cmsg_type = SCM_RIGHTS;
hdr->cmsg_len = CMSG_LEN(sizeof(int));
@@ -1003,7 +1016,7 @@ CrashHandler(const void* crash_context, size_t crash_context_size,
hdr->cmsg_level = SOL_SOCKET;
hdr->cmsg_type = SCM_CREDENTIALS;
hdr->cmsg_len = CMSG_LEN(sizeof(struct ucred));
- struct ucred *cred = reinterpret_cast<struct ucred*>(CMSG_DATA(hdr));
+ struct ucred* cred = reinterpret_cast<struct ucred*>(CMSG_DATA(hdr));
cred->uid = getuid();
cred->gid = getgid();
cred->pid = getpid();
@@ -1056,7 +1069,7 @@ TEST(ExceptionHandlerTest, ExternalDumper) {
pid_t crashing_pid = -1;
int signal_fd = -1;
- for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr;
+ for (struct cmsghdr* hdr = CMSG_FIRSTHDR(&msg); hdr;
hdr = CMSG_NXTHDR(&msg, hdr)) {
if (hdr->cmsg_level != SOL_SOCKET)
continue;
@@ -1066,7 +1079,7 @@ TEST(ExceptionHandlerTest, ExternalDumper) {
ASSERT_EQ(sizeof(int), len);
signal_fd = *(reinterpret_cast<int*>(CMSG_DATA(hdr)));
} else if (hdr->cmsg_type == SCM_CREDENTIALS) {
- const struct ucred *cred =
+ const struct ucred* cred =
reinterpret_cast<struct ucred*>(CMSG_DATA(hdr));
crashing_pid = cred->pid;
}