https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/96001
>From 0dc804076d624883e966b58c94cae8dc5065f1e3 Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova <chelsea_cassan...@apple.com> Date: Thu, 13 Jun 2024 16:02:07 -0700 Subject: [PATCH] add unit test for breakpoint::setcallback --- lldb/unittests/Breakpoint/CMakeLists.txt | 3 + lldb/unittests/CMakeLists.txt | 1 + lldb/unittests/Callback/CMakeLists.txt | 12 +++ .../Callback/TestBreakpointSetCallback.cpp | 89 +++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 lldb/unittests/Callback/CMakeLists.txt create mode 100644 lldb/unittests/Callback/TestBreakpointSetCallback.cpp diff --git a/lldb/unittests/Breakpoint/CMakeLists.txt b/lldb/unittests/Breakpoint/CMakeLists.txt index 757c2da1a4d9d..629f86dfe65a7 100644 --- a/lldb/unittests/Breakpoint/CMakeLists.txt +++ b/lldb/unittests/Breakpoint/CMakeLists.txt @@ -5,6 +5,9 @@ add_lldb_unittest(LLDBBreakpointTests LINK_LIBS lldbBreakpoint lldbCore + LLVMTestingSupport + lldbUtilityHelpers + lldbPluginPlatformMacOSX LINK_COMPONENTS Support ) diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt index a2585a94b6155..cc9d45ebf981d 100644 --- a/lldb/unittests/CMakeLists.txt +++ b/lldb/unittests/CMakeLists.txt @@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") add_subdirectory(API) endif() add_subdirectory(Breakpoint) +add_subdirectory(Callback) add_subdirectory(Core) add_subdirectory(DataFormatter) add_subdirectory(Disassembler) diff --git a/lldb/unittests/Callback/CMakeLists.txt b/lldb/unittests/Callback/CMakeLists.txt new file mode 100644 index 0000000000000..bb8797c513256 --- /dev/null +++ b/lldb/unittests/Callback/CMakeLists.txt @@ -0,0 +1,12 @@ +add_lldb_unittest(LLDBCallbackTests + TestBreakpointSetCallback.cpp + + LINK_LIBS + lldbBreakpoint + lldbCore + LLVMTestingSupport + lldbUtilityHelpers + lldbPluginPlatformMacOSX + LINK_COMPONENTS + Support + ) diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp new file mode 100644 index 0000000000000..7eea9c42bfad3 --- /dev/null +++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp @@ -0,0 +1,89 @@ +//===-- TestBreakpointSetCallback.cpp +//--------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Plugins/Platform/MacOSX/PlatformMacOSX.h" +#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h" +#include "TestingSupport/SubsystemRAII.h" +#include "TestingSupport/TestUtilities.h" +#include "lldb/Breakpoint/StoppointCallbackContext.h" +#include "lldb/Core/Debugger.h" +#include "lldb/Core/Progress.h" +#include "lldb/Host/FileSystem.h" +#include "lldb/Host/HostInfo.h" +#include "lldb/Target/ExecutionContext.h" +#include "lldb/lldb-private-enumerations.h" +#include "lldb/lldb-types.h" +#include "gtest/gtest.h" +#include <iostream> +#include <memory> +#include <mutex> + +using namespace lldb_private; +using namespace lldb; + +class BreakpointSetCallbackTest : public ::testing::Test { +public: + static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id, + lldb::user_id_t expected_breakpoint_id, + lldb::user_id_t expected_breakpoint_loc_id) { + EXPECT_TRUE(baton); + EXPECT_TRUE(context); + EXPECT_EQ(break_id, expected_breakpoint_id); + EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id); + } + +protected: + // The debugger's initialization function can't be called with no arguments + // so calling it using SubsystemRAII will cause the test build to fail as + // SubsystemRAII will call Initialize with no arguments. As such we set it up + // here the usual way. + void SetUp() override { + std::call_once(TestUtilities::g_debugger_initialize_flag, + []() { Debugger::Initialize(nullptr); }); + + // Set up the debugger, make sure that was done properly. + ArchSpec arch("x86_64-apple-macosx-"); + Platform::SetHostPlatform( + PlatformRemoteMacOSX::CreateInstance(true, &arch)); + + m_debugger_sp = Debugger::CreateInstance(); + m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch, + lldb_private::eLoadDependentsNo, + m_platform_sp, m_target_sp); + m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false); + }; + + static bool callback(void *baton, StoppointCallbackContext *context, + lldb::user_id_t break_id, lldb::user_id_t break_loc_id) { + BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id, + break_loc_id, 0, 0); + return true; + } + + DebuggerSP m_debugger_sp; + PlatformSP m_platform_sp; + TargetSP m_target_sp; + BreakpointSP m_breakpoint_sp; + Event *m_event; + const ExecutionContext m_exe_ctx; + lldb::user_id_t expected_breakpoint_id; + lldb::user_id_t expected_breakpoint_loc_id; + SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX, ProgressManager> + subsystems; +}; + +TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) { + void *baton = (void *)"hello"; + StoppointCallbackContext context(m_event, m_exe_ctx, true); + m_breakpoint_sp->SetCallback(BreakpointSetCallbackTest::callback, baton, + false); + m_breakpoint_sp->InvokeCallback(&context, 0); +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits