Index: base/logging_unittest.cc |
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc |
index f41cce2f43b390fa9603a14f3f689fe87d0dcb33..8e55f142c7c08e52c569827c2f6588bc04777ddd 100644 |
--- a/base/logging_unittest.cc |
+++ b/base/logging_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/command_line.h" |
#include "base/compiler_specific.h" |
#include "base/logging.h" |
#include "base/macros.h" |
@@ -9,6 +10,11 @@ |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if defined(OS_WIN) |
+#include <windows.h> |
Primiano Tucci (use gerrit)
2017/02/03 03:15:05
as per Nico's recent PSA I think there should be a
scottmg
2017/02/06 19:50:47
This one didn't actually have to be backwards, I j
|
+#include <excpt.h> |
+#endif // OS_WIN |
+ |
namespace logging { |
namespace { |
@@ -190,6 +196,68 @@ TEST_F(LoggingTest, CheckStreamsAreLazy) { |
#endif |
+#if defined(OFFICIAL_BUILD) && defined(OS_WIN) |
+NOINLINE void CheckContainingFunc(int x, int y, int z) { |
+ if (z == 1) |
+ CHECK(!x); |
+ if (z == 2) |
+ CHECK(!y); |
Will Harris
2017/02/02 03:18:14
One final thought - does this test need to be chan
Primiano Tucci (use gerrit)
2017/02/03 03:15:05
+1, I'd go for something similar to
https://coder
scottmg
2017/02/06 19:50:47
Done. (I had previously been trying to outwit the
|
+ if (z == 3) |
+ CHECK(false); |
+} |
+ |
+int GetCheckExceptionData(EXCEPTION_POINTERS* p, DWORD* code, void** addr) { |
+ *code = p->ExceptionRecord->ExceptionCode; |
+ *addr = p->ExceptionRecord->ExceptionAddress; |
+ return EXCEPTION_EXECUTE_HANDLER; |
+} |
+ |
+TEST_F(LoggingTest, CheckCausesDistinctBreakpoints) { |
+ int x = base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ "something-that-does-not-exist") - |
+ 1; |
+ int y = base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ "something-else-that-does-not-exist") - |
+ 1; |
+ DWORD code1 = 0; |
+ DWORD code2 = 0; |
+ DWORD code3 = 0; |
+ void* addr1 = nullptr; |
+ void* addr2 = nullptr; |
+ void* addr3 = nullptr; |
+ |
+ // Record the exception code and addresses. |
+ __try { |
+ CheckContainingFunc(x, y, 1); |
+ } __except ( |
+ GetCheckExceptionData(GetExceptionInformation(), &code1, &addr1)) { |
+ } |
+ |
+ __try { |
+ CheckContainingFunc(x, y, 2); |
+ } __except ( |
+ GetCheckExceptionData(GetExceptionInformation(), &code2, &addr2)) { |
+ } |
+ |
+ __try { |
+ CheckContainingFunc(x, y, 3); |
+ } __except ( |
+ GetCheckExceptionData(GetExceptionInformation(), &code3, &addr3)) { |
+ } |
+ |
+ // Ensure that the exception codes are correct (in particular, breakpoints, |
+ // not access violations). |
+ EXPECT_EQ(STATUS_BREAKPOINT, code1); |
+ EXPECT_EQ(STATUS_BREAKPOINT, code2); |
+ EXPECT_EQ(STATUS_BREAKPOINT, code3); |
+ |
+ // Ensure that none of the CHECKs are colocated. |
+ EXPECT_NE(addr1, addr2); |
+ EXPECT_NE(addr1, addr3); |
+ EXPECT_NE(addr2, addr3); |
+} |
+#endif // OFFICIAL_BUILD && OS_WIN |
+ |
TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { |
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
int debug_only_variable = 1; |