Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: base/logging_unittest.cc

Issue 2676483002: Make CHECK int 3 on Windows, rather than crash (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/logging.h ('K') | « base/logging.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/command_line.h"
5 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
6 #include "base/logging.h" 7 #include "base/logging.h"
7 #include "base/macros.h" 8 #include "base/macros.h"
8 9
9 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
13 #if defined(OS_WIN)
14 #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
15 #include <excpt.h>
16 #endif // OS_WIN
17
12 namespace logging { 18 namespace logging {
13 19
14 namespace { 20 namespace {
15 21
16 using ::testing::Return; 22 using ::testing::Return;
17 23
18 // Needs to be global since log assert handlers can't maintain state. 24 // Needs to be global since log assert handlers can't maintain state.
19 int log_sink_call_count = 0; 25 int log_sink_call_count = 0;
20 26
21 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG) 27 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG)
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log(); 189 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log();
184 PCHECK(!mock_log_source.Log()) << mock_log_source.Log(); 190 PCHECK(!mock_log_source.Log()) << mock_log_source.Log();
185 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log()) 191 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log())
186 << uncalled_mock_log_source.Log(); 192 << uncalled_mock_log_source.Log();
187 CHECK_NE(mock_log_source.Log(), mock_log_source.Log()) 193 CHECK_NE(mock_log_source.Log(), mock_log_source.Log())
188 << mock_log_source.Log(); 194 << mock_log_source.Log();
189 } 195 }
190 196
191 #endif 197 #endif
192 198
199 #if defined(OFFICIAL_BUILD) && defined(OS_WIN)
200 NOINLINE void CheckContainingFunc(int x, int y, int z) {
201 if (z == 1)
202 CHECK(!x);
203 if (z == 2)
204 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
205 if (z == 3)
206 CHECK(false);
207 }
208
209 int GetCheckExceptionData(EXCEPTION_POINTERS* p, DWORD* code, void** addr) {
210 *code = p->ExceptionRecord->ExceptionCode;
211 *addr = p->ExceptionRecord->ExceptionAddress;
212 return EXCEPTION_EXECUTE_HANDLER;
213 }
214
215 TEST_F(LoggingTest, CheckCausesDistinctBreakpoints) {
216 int x = base::CommandLine::ForCurrentProcess()->HasSwitch(
217 "something-that-does-not-exist") -
218 1;
219 int y = base::CommandLine::ForCurrentProcess()->HasSwitch(
220 "something-else-that-does-not-exist") -
221 1;
222 DWORD code1 = 0;
223 DWORD code2 = 0;
224 DWORD code3 = 0;
225 void* addr1 = nullptr;
226 void* addr2 = nullptr;
227 void* addr3 = nullptr;
228
229 // Record the exception code and addresses.
230 __try {
231 CheckContainingFunc(x, y, 1);
232 } __except (
233 GetCheckExceptionData(GetExceptionInformation(), &code1, &addr1)) {
234 }
235
236 __try {
237 CheckContainingFunc(x, y, 2);
238 } __except (
239 GetCheckExceptionData(GetExceptionInformation(), &code2, &addr2)) {
240 }
241
242 __try {
243 CheckContainingFunc(x, y, 3);
244 } __except (
245 GetCheckExceptionData(GetExceptionInformation(), &code3, &addr3)) {
246 }
247
248 // Ensure that the exception codes are correct (in particular, breakpoints,
249 // not access violations).
250 EXPECT_EQ(STATUS_BREAKPOINT, code1);
251 EXPECT_EQ(STATUS_BREAKPOINT, code2);
252 EXPECT_EQ(STATUS_BREAKPOINT, code3);
253
254 // Ensure that none of the CHECKs are colocated.
255 EXPECT_NE(addr1, addr2);
256 EXPECT_NE(addr1, addr3);
257 EXPECT_NE(addr2, addr3);
258 }
259 #endif // OFFICIAL_BUILD && OS_WIN
260
193 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { 261 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) {
194 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 262 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
195 int debug_only_variable = 1; 263 int debug_only_variable = 1;
196 #endif 264 #endif
197 // These should avoid emitting references to |debug_only_variable| 265 // These should avoid emitting references to |debug_only_variable|
198 // in release mode. 266 // in release mode.
199 DLOG_IF(INFO, debug_only_variable) << "test"; 267 DLOG_IF(INFO, debug_only_variable) << "test";
200 DLOG_ASSERT(debug_only_variable) << "test"; 268 DLOG_ASSERT(debug_only_variable) << "test";
201 DPLOG_IF(INFO, debug_only_variable) << "test"; 269 DPLOG_IF(INFO, debug_only_variable) << "test";
202 DVLOG_IF(1, debug_only_variable) << "test"; 270 DVLOG_IF(1, debug_only_variable) << "test";
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 std::wstring wstr = L"Hello World"; 409 std::wstring wstr = L"Hello World";
342 std::ostringstream ostr; 410 std::ostringstream ostr;
343 ostr << wstr; 411 ostr << wstr;
344 EXPECT_EQ("Hello World", ostr.str()); 412 EXPECT_EQ("Hello World", ostr.str());
345 } 413 }
346 } // namespace nested_test 414 } // namespace nested_test
347 415
348 } // namespace 416 } // namespace
349 417
350 } // namespace logging 418 } // namespace logging
OLDNEW
« base/logging.h ('K') | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698