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

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/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 #include "base/rand_util.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>
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 __declspec(noinline) void CheckContainingFunc(uint64_t x, uint64_t y, int z) {
Will Harris 2017/02/02 01:21:06 not sure here (base owner might know) but I think
scottmg 2017/02/02 01:41:23 Done.
201 if (z == 1)
202 CHECK(!x);
203 if (z == 2)
204 CHECK(!y);
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 uint64_t x = base::RandUint64();
Will Harris 2017/02/02 01:21:06 this can return 0, so the test can fail with a ver
scottmg 2017/02/02 01:41:24 Meh. Done.
217 uint64_t y = base::RandUint64();
218 DWORD code1 = 0;
219 DWORD code2 = 0;
220 DWORD code3 = 0;
221 void* addr1 = nullptr;
222 void* addr2 = nullptr;
223 void* addr3 = nullptr;
224
225 // Record the exception code and addresses.
226 __try {
227 CheckContainingFunc(x, y, 1);
228 } __except (
229 GetCheckExceptionData(GetExceptionInformation(), &code1, &addr1)) {
230 }
231
232 __try {
233 CheckContainingFunc(x, y, 2);
234 } __except (
235 GetCheckExceptionData(GetExceptionInformation(), &code2, &addr2)) {
236 }
237
238 __try {
239 CheckContainingFunc(x, y, 3);
240 } __except (
241 GetCheckExceptionData(GetExceptionInformation(), &code3, &addr3)) {
242 }
243
244 // Ensure that the exception codes are correct (in particular, breakpoints,
245 // not access violations).
246 EXPECT_EQ(STATUS_BREAKPOINT, code1);
247 EXPECT_EQ(STATUS_BREAKPOINT, code2);
248 EXPECT_EQ(STATUS_BREAKPOINT, code3);
249
250 // Ensure that none of the CHECKs are colocated.
251 EXPECT_NE(addr1, addr2);
252 EXPECT_NE(addr1, addr3);
253 EXPECT_NE(addr2, addr3);
254 }
255 #endif // OFFICIAL_BUILD && OS_WIN
256
193 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { 257 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) {
194 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 258 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
195 int debug_only_variable = 1; 259 int debug_only_variable = 1;
196 #endif 260 #endif
197 // These should avoid emitting references to |debug_only_variable| 261 // These should avoid emitting references to |debug_only_variable|
198 // in release mode. 262 // in release mode.
199 DLOG_IF(INFO, debug_only_variable) << "test"; 263 DLOG_IF(INFO, debug_only_variable) << "test";
200 DLOG_ASSERT(debug_only_variable) << "test"; 264 DLOG_ASSERT(debug_only_variable) << "test";
201 DPLOG_IF(INFO, debug_only_variable) << "test"; 265 DPLOG_IF(INFO, debug_only_variable) << "test";
202 DVLOG_IF(1, debug_only_variable) << "test"; 266 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"; 405 std::wstring wstr = L"Hello World";
342 std::ostringstream ostr; 406 std::ostringstream ostr;
343 ostr << wstr; 407 ostr << wstr;
344 EXPECT_EQ("Hello World", ostr.str()); 408 EXPECT_EQ("Hello World", ostr.str());
345 } 409 }
346 } // namespace nested_test 410 } // namespace nested_test
347 411
348 } // namespace 412 } // namespace
349 413
350 } // namespace logging 414 } // 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