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

Side by Side Diff: base/logging_unittest.cc

Issue 2676483002: Make CHECK int 3 on Windows, rather than crash (Closed)
Patch Set: no need to special case #if for clang 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
« no previous file with comments | « 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/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 8
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 #if defined(OS_WIN)
13 #include <excpt.h>
14 #include <windows.h>
15 #endif // OS_WIN
16
12 namespace logging { 17 namespace logging {
13 18
14 namespace { 19 namespace {
15 20
16 using ::testing::Return; 21 using ::testing::Return;
17 22
18 // Needs to be global since log assert handlers can't maintain state. 23 // Needs to be global since log assert handlers can't maintain state.
19 int log_sink_call_count = 0; 24 int log_sink_call_count = 0;
20 25
21 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG) 26 #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(); 188 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log();
184 PCHECK(!mock_log_source.Log()) << mock_log_source.Log(); 189 PCHECK(!mock_log_source.Log()) << mock_log_source.Log();
185 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log()) 190 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log())
186 << uncalled_mock_log_source.Log(); 191 << uncalled_mock_log_source.Log();
187 CHECK_NE(mock_log_source.Log(), mock_log_source.Log()) 192 CHECK_NE(mock_log_source.Log(), mock_log_source.Log())
188 << mock_log_source.Log(); 193 << mock_log_source.Log();
189 } 194 }
190 195
191 #endif 196 #endif
192 197
198 #if defined(OFFICIAL_BUILD) && defined(OS_WIN)
199 NOINLINE void CheckContainingFunc(int death_location) {
200 CHECK(death_location != 1);
201 CHECK(death_location != 2);
202 CHECK(death_location != 3);
203 }
204
205 int GetCheckExceptionData(EXCEPTION_POINTERS* p, DWORD* code, void** addr) {
206 *code = p->ExceptionRecord->ExceptionCode;
207 *addr = p->ExceptionRecord->ExceptionAddress;
208 return EXCEPTION_EXECUTE_HANDLER;
209 }
210
211 TEST_F(LoggingTest, CheckCausesDistinctBreakpoints) {
212 DWORD code1 = 0;
213 DWORD code2 = 0;
214 DWORD code3 = 0;
215 void* addr1 = nullptr;
216 void* addr2 = nullptr;
217 void* addr3 = nullptr;
218
219 // Record the exception code and addresses.
220 __try {
221 CheckContainingFunc(1);
222 } __except (
223 GetCheckExceptionData(GetExceptionInformation(), &code1, &addr1)) {
224 }
225
226 __try {
227 CheckContainingFunc(2);
228 } __except (
229 GetCheckExceptionData(GetExceptionInformation(), &code2, &addr2)) {
230 }
231
232 __try {
233 CheckContainingFunc(3);
234 } __except (
235 GetCheckExceptionData(GetExceptionInformation(), &code3, &addr3)) {
236 }
237
238 // Ensure that the exception codes are correct (in particular, breakpoints,
239 // not access violations).
240 EXPECT_EQ(STATUS_BREAKPOINT, code1);
241 EXPECT_EQ(STATUS_BREAKPOINT, code2);
242 EXPECT_EQ(STATUS_BREAKPOINT, code3);
243
244 // Ensure that none of the CHECKs are colocated.
245 EXPECT_NE(addr1, addr2);
246 EXPECT_NE(addr1, addr3);
247 EXPECT_NE(addr2, addr3);
248 }
249 #endif // OFFICIAL_BUILD && OS_WIN
250
193 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { 251 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) {
194 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 252 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
195 int debug_only_variable = 1; 253 int debug_only_variable = 1;
196 #endif 254 #endif
197 // These should avoid emitting references to |debug_only_variable| 255 // These should avoid emitting references to |debug_only_variable|
198 // in release mode. 256 // in release mode.
199 DLOG_IF(INFO, debug_only_variable) << "test"; 257 DLOG_IF(INFO, debug_only_variable) << "test";
200 DLOG_ASSERT(debug_only_variable) << "test"; 258 DLOG_ASSERT(debug_only_variable) << "test";
201 DPLOG_IF(INFO, debug_only_variable) << "test"; 259 DPLOG_IF(INFO, debug_only_variable) << "test";
202 DVLOG_IF(1, debug_only_variable) << "test"; 260 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"; 399 std::wstring wstr = L"Hello World";
342 std::ostringstream ostr; 400 std::ostringstream ostr;
343 ostr << wstr; 401 ostr << wstr;
344 EXPECT_EQ("Hello World", ostr.str()); 402 EXPECT_EQ("Hello World", ostr.str());
345 } 403 }
346 } // namespace nested_test 404 } // namespace nested_test
347 405
348 } // namespace 406 } // namespace
349 407
350 } // namespace logging 408 } // namespace logging
OLDNEW
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698