Chromium Code Reviews| Index: base/logging_unittest.cc |
| diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc |
| index 9fe718c8799a4e74f170091ca148033373c79161..effa3b7f938e164d834e41a0b527507b61f41ae2 100644 |
| --- a/base/logging_unittest.cc |
| +++ b/base/logging_unittest.cc |
| @@ -9,6 +9,12 @@ |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#if defined(OS_POSIX) |
| +#include <signal.h> |
| +#include <unistd.h> |
| +#include "base/posix/eintr_wrapper.h" |
| +#endif // OS_POSIX |
| + |
| #if defined(OS_WIN) |
| #include <excpt.h> |
| #include <windows.h> |
| @@ -246,7 +252,81 @@ TEST_F(LoggingTest, CheckCausesDistinctBreakpoints) { |
| EXPECT_NE(addr1, addr3); |
| EXPECT_NE(addr2, addr3); |
| } |
| -#endif // OFFICIAL_BUILD && OS_WIN |
| +#elif defined(OS_POSIX) |
| + |
| +int g_child_crash_pipe; |
| + |
| +void CheckCrashTestSighandler(int, siginfo_t* info, void*) { |
| + const uintptr_t crash_addr = reinterpret_cast<uintptr_t>(info->si_addr); |
| + HANDLE_EINTR(write(g_child_crash_pipe, &crash_addr, sizeof(uintptr_t))); |
| + _exit(0); |
| +} |
| + |
| +// CHECK causes a direct crash (without jumping to another function) only in |
| +// official builds. Unfortunately, continuous test coverage on official builds |
| +// is lower. DO_CHECK here falls back on a home-brewed implementation in |
| +// non-official builds, to catch regressions earlier in the CQ. |
| +#if defined(OFFICIAL_BUILD) |
| +#define DO_CHECK CHECK |
| +#else |
| +#define DO_CHECK(cond) \ |
| + if (!(cond)) \ |
| + IMMEDIATE_CRASH() |
| +#endif |
| + |
| +void CrashChildMain(int death_location) { |
| + struct sigaction act = {}; |
| + act.sa_sigaction = CheckCrashTestSighandler; |
| + act.sa_flags = SA_SIGINFO; |
| + ASSERT_EQ(0, sigaction(SIGTRAP, &act, NULL)); |
| + ASSERT_EQ(0, sigaction(SIGILL, &act, NULL)); |
|
Torne
2017/02/17 11:06:31
Don't you need to handle SIGBUS here as well for a
Primiano Tucci (use gerrit)
2017/02/17 12:37:35
Ehm err you are definitely right. It was green bec
|
| + DO_CHECK(death_location != 1); |
| + DO_CHECK(death_location != 2); |
| + printf("\n"); |
| + DO_CHECK(death_location != 3); |
| + |
| + // Should never reach this point. |
| + const uintptr_t failed = 0; |
| + HANDLE_EINTR(write(g_child_crash_pipe, &failed, sizeof(uintptr_t))); |
| +}; |
| + |
| +void SpawnChildAndCrash(int death_location, uintptr_t* child_crash_addr) { |
| + int pipefd[2]; |
| + ASSERT_EQ(0, pipe(pipefd)); |
| + |
| + int pid = fork(); |
| + ASSERT_GE(pid, 0); |
| + |
| + if (pid == 0) { // child process. |
| + close(pipefd[0]); // Close reader (parent) end. |
| + g_child_crash_pipe = pipefd[1]; |
| + CrashChildMain(death_location); |
| + FAIL() << "The child process was supposed to crash. It didn't."; |
| + } |
| + |
| + close(pipefd[1]); // Close writer (child) end. |
| + DCHECK(child_crash_addr); |
| + int res = HANDLE_EINTR(read(pipefd[0], child_crash_addr, sizeof(uintptr_t))); |
| + ASSERT_EQ(static_cast<int>(sizeof(uintptr_t)), res); |
| +} |
| + |
| +TEST_F(LoggingTest, CheckCausesDistinctBreakpoints) { |
| + uintptr_t child_crash_addr_1 = 0; |
| + uintptr_t child_crash_addr_2 = 0; |
| + uintptr_t child_crash_addr_3 = 0; |
| + |
| + SpawnChildAndCrash(1, &child_crash_addr_1); |
| + SpawnChildAndCrash(2, &child_crash_addr_2); |
| + SpawnChildAndCrash(3, &child_crash_addr_3); |
| + |
| + ASSERT_NE(0u, child_crash_addr_1); |
| + ASSERT_NE(0u, child_crash_addr_2); |
| + ASSERT_NE(0u, child_crash_addr_3); |
| + ASSERT_NE(child_crash_addr_1, child_crash_addr_2); |
| + ASSERT_NE(child_crash_addr_1, child_crash_addr_3); |
| + ASSERT_NE(child_crash_addr_2, child_crash_addr_3); |
| +} |
| +#endif // OS_POSIX |
| TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { |
| #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |