aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/unittests')
-rw-r--r--lldb/unittests/API/CMakeLists.txt6
-rw-r--r--lldb/unittests/API/SBBreakpointClearConditionTest.cpp69
-rw-r--r--lldb/unittests/Breakpoint/CMakeLists.txt20
-rw-r--r--lldb/unittests/CMakeLists.txt6
-rw-r--r--lldb/unittests/DAP/CMakeLists.txt2
-rw-r--r--lldb/unittests/Host/MainLoopTest.cpp2
-rw-r--r--lldb/unittests/Target/LanguageTest.cpp23
7 files changed, 110 insertions, 18 deletions
diff --git a/lldb/unittests/API/CMakeLists.txt b/lldb/unittests/API/CMakeLists.txt
index 06ac492..b86054f 100644
--- a/lldb/unittests/API/CMakeLists.txt
+++ b/lldb/unittests/API/CMakeLists.txt
@@ -2,13 +2,17 @@ add_lldb_unittest(APITests
SBCommandInterpreterTest.cpp
SBLineEntryTest.cpp
SBMutexTest.cpp
+ SBBreakpointClearConditionTest.cpp
+
+ SBAPITEST
LINK_LIBS
liblldb
)
# Build with -Wdocumentation. This relies on the tests including all the API
-# headers through API/LLDB.h.
+# headers through API/LLDB.h. It also means that the API tests cannot include
+# private headers.
check_cxx_compiler_flag("-Wdocumentation"
CXX_SUPPORTS_DOCUMENTATION)
if (CXX_SUPPORTS_DOCUMENTATION)
diff --git a/lldb/unittests/API/SBBreakpointClearConditionTest.cpp b/lldb/unittests/API/SBBreakpointClearConditionTest.cpp
new file mode 100644
index 0000000..993f7f9
--- /dev/null
+++ b/lldb/unittests/API/SBBreakpointClearConditionTest.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+// Use the umbrella header for -Wdocumentation.
+#include "lldb/API/LLDB.h"
+
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/API/SBBreakpoint.h"
+#include "lldb/API/SBBreakpointLocation.h"
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBTarget.h"
+#include "gtest/gtest.h"
+#include <memory>
+#include <mutex>
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointClearConditionTest : public ::testing::Test {
+public:
+ void SetUp() override {
+ m_sb_debugger = SBDebugger::Create(/*source_init_files=*/false);
+ };
+
+ void TearDown() override { SBDebugger::Destroy(m_sb_debugger); }
+ SBDebugger m_sb_debugger;
+ SubsystemRAII<lldb::SBDebugger> subsystems;
+};
+
+template <typename T> void test_condition(T sb_object) {
+ const char *in_cond_str = "Here is a condition";
+ sb_object.SetCondition(in_cond_str);
+ // Make sure we set the condition correctly:
+ const char *out_cond_str = sb_object.GetCondition();
+ EXPECT_STREQ(in_cond_str, out_cond_str);
+ // Now unset it by passing in nullptr and make sure that works:
+ const char *empty_tokens[2] = {nullptr, ""};
+ for (auto token : empty_tokens) {
+ sb_object.SetCondition(token);
+ out_cond_str = sb_object.GetCondition();
+ // And make sure an unset condition returns nullptr:
+ EXPECT_EQ(nullptr, out_cond_str);
+ }
+}
+
+TEST_F(BreakpointClearConditionTest, BreakpointClearConditionTest) {
+ // Create target
+ SBTarget sb_target;
+ SBError error;
+ sb_target =
+ m_sb_debugger.CreateTarget("", "x86_64-apple-macosx-", "remote-macosx",
+ /*add_dependent=*/false, error);
+
+ EXPECT_EQ(sb_target.IsValid(), true);
+
+ // Create breakpoint
+ SBBreakpoint sb_breakpoint = sb_target.BreakpointCreateByAddress(0xDEADBEEF);
+ test_condition(sb_breakpoint);
+
+ // Address breakpoints always have one location, so we can also use this
+ // to test the location:
+ SBBreakpointLocation sb_loc = sb_breakpoint.GetLocationAtIndex(0);
+ EXPECT_EQ(sb_loc.IsValid(), true);
+ test_condition(sb_loc);
+}
diff --git a/lldb/unittests/Breakpoint/CMakeLists.txt b/lldb/unittests/Breakpoint/CMakeLists.txt
index 3c234a4..dec2265 100644
--- a/lldb/unittests/Breakpoint/CMakeLists.txt
+++ b/lldb/unittests/Breakpoint/CMakeLists.txt
@@ -1,10 +1,10 @@
-add_lldb_unittest(LLDBBreakpointTests
- BreakpointIDTest.cpp
- WatchpointAlgorithmsTests.cpp
-
- LINK_COMPONENTS
- Support
- LINK_LIBS
- lldbBreakpoint
- lldbCore
- )
+add_lldb_unittest(LLDBBreakpointTests
+ BreakpointIDTest.cpp
+ WatchpointAlgorithmsTests.cpp
+
+ LINK_COMPONENTS
+ Support
+ LINK_LIBS
+ lldbBreakpoint
+ lldbCore
+ )
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index 4c5267a..194dd42 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -12,7 +12,7 @@ endif()
function(add_lldb_unittest test_name)
cmake_parse_arguments(ARG
- ""
+ "SBAPITEST"
""
"LINK_LIBS;LINK_COMPONENTS"
${ARGN})
@@ -21,6 +21,10 @@ function(add_lldb_unittest test_name)
message(FATAL_ERROR "Unit test name must end with 'Tests' for lit to find it.")
endif()
+ if ("liblldb" IN_LIST ARG_LINK_LIBS AND NOT ARG_SBAPITEST)
+ message(FATAL_ERROR "The ${test_name} are not allowed to link liblldb.")
+ endif()
+
list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
add_unittest(LLDBUnitTests
diff --git a/lldb/unittests/DAP/CMakeLists.txt b/lldb/unittests/DAP/CMakeLists.txt
index 716159b..a08414c 100644
--- a/lldb/unittests/DAP/CMakeLists.txt
+++ b/lldb/unittests/DAP/CMakeLists.txt
@@ -12,6 +12,8 @@ add_lldb_unittest(DAPTests
TestBase.cpp
VariablesTest.cpp
+ SBAPITEST
+
LINK_COMPONENTS
Support
LINK_LIBS
diff --git a/lldb/unittests/Host/MainLoopTest.cpp b/lldb/unittests/Host/MainLoopTest.cpp
index 0bc291c..ae16d02 100644
--- a/lldb/unittests/Host/MainLoopTest.cpp
+++ b/lldb/unittests/Host/MainLoopTest.cpp
@@ -424,9 +424,9 @@ TEST_F(MainLoopTest, ManyPendingCallbacks) {
TEST_F(MainLoopTest, CallbackWithTimeout) {
MainLoop loop;
+ auto start = std::chrono::steady_clock::now();
loop.AddCallback([](MainLoopBase &loop) { loop.RequestTermination(); },
std::chrono::seconds(2));
- auto start = std::chrono::steady_clock::now();
ASSERT_THAT_ERROR(loop.Run().takeError(), llvm::Succeeded());
EXPECT_GE(std::chrono::steady_clock::now() - start, std::chrono::seconds(2));
}
diff --git a/lldb/unittests/Target/LanguageTest.cpp b/lldb/unittests/Target/LanguageTest.cpp
index a00fda78..720863b 100644
--- a/lldb/unittests/Target/LanguageTest.cpp
+++ b/lldb/unittests/Target/LanguageTest.cpp
@@ -24,9 +24,6 @@ TEST_F(LanguageTest, SourceLanguage_GetDescription) {
continue;
auto lang_type = static_cast<lldb::LanguageType>(i);
- if (lang_type == lldb::eLanguageTypeLastStandardLanguage)
- continue;
-
SourceLanguage lang(lang_type);
// eLanguageTypeHIP is not implemented as a DW_LNAME because of a conflict.
@@ -39,9 +36,12 @@ TEST_F(LanguageTest, SourceLanguage_GetDescription) {
EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus).GetDescription(),
"ISO C++");
EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus_17).GetDescription(),
- "ISO C++");
+ "C++17");
EXPECT_EQ(SourceLanguage(eLanguageTypeC_plus_plus_20).GetDescription(),
- "ISO C++");
+ "C++20");
+
+ EXPECT_EQ(SourceLanguage(eLanguageTypeC).GetDescription(), "C (K&R and ISO)");
+ EXPECT_EQ(SourceLanguage(eLanguageTypeC89).GetDescription(), "C89");
EXPECT_EQ(SourceLanguage(eLanguageTypeObjC).GetDescription(), "Objective C");
EXPECT_EQ(SourceLanguage(eLanguageTypeMipsAssembler).GetDescription(),
@@ -67,3 +67,16 @@ TEST_F(LanguageTest, SourceLanguage_AsLanguageType) {
EXPECT_EQ(SourceLanguage(eLanguageTypeUnknown).AsLanguageType(),
eLanguageTypeUnknown);
}
+
+TEST_F(LanguageTest, SourceLanguage_LastStandardLanguage) {
+ // eLanguageTypeLastStandardLanguage should be treated as a standard DWARF
+ // language.
+ SourceLanguage lang(eLanguageTypeLastStandardLanguage);
+ EXPECT_TRUE(lang);
+
+ // It should have a valid description (not "Unknown").
+ EXPECT_NE(lang.GetDescription(), "Unknown");
+
+ // It should convert to the correct language type.
+ EXPECT_EQ(lang.AsLanguageType(), eLanguageTypeLastStandardLanguage);
+}