| Index: base/logging_unittest.cc
|
| diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
|
| index 8a20c54fb4c605734bf45c4b8bb582a76276e104..762f8f67a064fa6b3425f80daa1de4e7723ee126 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
|
| +
|
| namespace logging {
|
|
|
| namespace {
|
| @@ -312,6 +318,74 @@ namespace nested_test {
|
| }
|
| } // namespace nested_test
|
|
|
| +// This test checks that, on official builds, the crash address of CHECK() is
|
| +// distinct in presence of multiple CHECK()s in the same function. This is a
|
| +// regression test for http://crbug.com/664209 .
|
| +#if defined(OFFICIAL_BUILD) && defined(OS_POSIX)
|
| +
|
| +int g_child_crash_pipe;
|
| +
|
| +void OfficialCHECKNotAmbiguous_Sighandler(int, siginfo_t* info, void*) {
|
| + const uintptr_t crash_addr = reinterpret_cast<uintptr_t>(info->si_addr);
|
| + write(g_child_crash_pipe, &crash_addr, sizeof(uintptr_t));
|
| + _exit(0);
|
| +}
|
| +
|
| +void OfficialCHECKNotAmbiguous_ChildMain(int death_location) {
|
| + struct sigaction act = {};
|
| + act.sa_sigaction = OfficialCHECKNotAmbiguous_Sighandler;
|
| + act.sa_flags = SA_SIGINFO;
|
| + ASSERT_EQ(0, sigaction(SIGTRAP, &act, NULL));
|
| + ASSERT_EQ(0, sigaction(SIGILL, &act, NULL));
|
| + CHECK(death_location != 1);
|
| + CHECK(death_location != 2);
|
| + printf("\n");
|
| + CHECK(death_location != 3);
|
| +
|
| + // Should never reach this point.
|
| + const uintptr_t failed = 0;
|
| + write(g_child_crash_pipe, &failed, sizeof(uintptr_t));
|
| +};
|
| +
|
| +void OfficialCHECKNotAmbiguous_DoCrashChild(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];
|
| + OfficialCHECKNotAmbiguous_ChildMain(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, OfficialCHECKNotAmbiguous) {
|
| + uintptr_t child_crash_addr_1 = 0;
|
| + uintptr_t child_crash_addr_2 = 0;
|
| + uintptr_t child_crash_addr_3 = 0;
|
| +
|
| + OfficialCHECKNotAmbiguous_DoCrashChild(1, &child_crash_addr_1);
|
| + OfficialCHECKNotAmbiguous_DoCrashChild(2, &child_crash_addr_2);
|
| + OfficialCHECKNotAmbiguous_DoCrashChild(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 // defined(OFFICIAL_BUILD) && defined(OS_POSIX)
|
| +
|
| } // namespace
|
|
|
| } // namespace logging
|
|
|