Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/debug/debugger.h" |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 6 | |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 7 | #include "build/build_config.h" |
Richard Townsend | 0a350b7c | 2019-05-07 23:28:00 | [diff] [blame] | 8 | |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 9 | #if BUILDFLAG(IS_WIN) |
Richard Townsend | 0a350b7c | 2019-05-07 23:28:00 | [diff] [blame] | 10 | #include <windows.h> |
| 11 | #endif |
| 12 | |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | |
| 15 | namespace { |
| 16 | |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 17 | #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 18 | void CrashWithBreakDebugger() { |
| 19 | base::debug::SetSuppressDebugUI(false); |
| 20 | base::debug::BreakDebugger(); |
| 21 | |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 22 | #if BUILDFLAG(IS_WIN) |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 23 | // This should not be executed. |
| 24 | _exit(125); |
| 25 | #endif |
| 26 | } |
| 27 | #endif // defined(GTEST_HAS_DEATH_TEST) |
| 28 | |
| 29 | } // namespace |
| 30 | |
| 31 | // Death tests misbehave on Android. |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 32 | #if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 33 | |
| 34 | TEST(Debugger, CrashAtBreakpoint) { |
| 35 | EXPECT_DEATH(CrashWithBreakDebugger(), ""); |
| 36 | } |
| 37 | |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 38 | #if BUILDFLAG(IS_WIN) |
scottmg | f063a7e | 2015-02-25 00:17:30 | [diff] [blame] | 39 | TEST(Debugger, DoesntExecuteBeyondBreakpoint) { |
Richard Townsend | 0a350b7c | 2019-05-07 23:28:00 | [diff] [blame] | 40 | EXPECT_EXIT(CrashWithBreakDebugger(), |
| 41 | ::testing::ExitedWithCode(STATUS_BREAKPOINT), ""); |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 42 | } |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 43 | #endif // BUILDFLAG(IS_WIN) |
rvargas | 9e9ce3c5 | 2014-12-04 19:47:22 | [diff] [blame] | 44 | |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 45 | #else // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 46 | TEST(Debugger, NoTest) {} |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 47 | #endif // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID) |