blob: 70208ea668d8f002d627fd0eaa731b69fa7fb2e3 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2014 The Chromium Authors
rvargas9e9ce3c52014-12-04 19:47:222// 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 Kasting134ef9af2024-12-28 02:30:096
rvargas9e9ce3c52014-12-04 19:47:227#include "build/build_config.h"
Richard Townsend0a350b7c2019-05-07 23:28:008
Xiaohan Wang131aa4d2022-01-15 19:39:419#if BUILDFLAG(IS_WIN)
Richard Townsend0a350b7c2019-05-07 23:28:0010#include <windows.h>
11#endif
12
rvargas9e9ce3c52014-12-04 19:47:2213#include "testing/gtest/include/gtest/gtest.h"
14
15namespace {
16
Xiaohan Wang131aa4d2022-01-15 19:39:4117#if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
rvargas9e9ce3c52014-12-04 19:47:2218void CrashWithBreakDebugger() {
19 base::debug::SetSuppressDebugUI(false);
20 base::debug::BreakDebugger();
21
Xiaohan Wang131aa4d2022-01-15 19:39:4122#if BUILDFLAG(IS_WIN)
rvargas9e9ce3c52014-12-04 19:47:2223 // 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 Wang131aa4d2022-01-15 19:39:4132#if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
rvargas9e9ce3c52014-12-04 19:47:2233
34TEST(Debugger, CrashAtBreakpoint) {
35 EXPECT_DEATH(CrashWithBreakDebugger(), "");
36}
37
Xiaohan Wang131aa4d2022-01-15 19:39:4138#if BUILDFLAG(IS_WIN)
scottmgf063a7e2015-02-25 00:17:3039TEST(Debugger, DoesntExecuteBeyondBreakpoint) {
Richard Townsend0a350b7c2019-05-07 23:28:0040 EXPECT_EXIT(CrashWithBreakDebugger(),
41 ::testing::ExitedWithCode(STATUS_BREAKPOINT), "");
rvargas9e9ce3c52014-12-04 19:47:2242}
Xiaohan Wang131aa4d2022-01-15 19:39:4143#endif // BUILDFLAG(IS_WIN)
rvargas9e9ce3c52014-12-04 19:47:2244
Xiaohan Wang131aa4d2022-01-15 19:39:4145#else // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
Peter Kasting134ef9af2024-12-28 02:30:0946TEST(Debugger, NoTest) {}
Xiaohan Wang131aa4d2022-01-15 19:39:4147#endif // defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)