Skip to content

Commit 6e9df05

Browse files
committed
[lldb-dap] add test case
1 parent c20a058 commit 6e9df05

File tree

5 files changed

+88
-8
lines changed

5 files changed

+88
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Test lldb-dap recieves invalidated-events when the area such as
3+
stack, variables, threads has changes but the client does not
4+
know about it.
5+
"""
6+
7+
import lldbdap_testcase
8+
from lldbsuite.test.lldbtest import line_number
9+
from dap_server import Event
10+
11+
12+
class TestDAP_invalidatedEvent(lldbdap_testcase.DAPTestCaseBase):
13+
def verify_top_frame_name(self, frame_name: str):
14+
all_frames = self.get_stackFrames()
15+
self.assertGreaterEqual(len(all_frames), 1, "Expected at least one frame.")
16+
top_frame_name = all_frames[0]["name"]
17+
self.assertRegex(top_frame_name, f"{frame_name}.*")
18+
19+
def test_invalidated_stack_area_event(self):
20+
"""
21+
Test an invalidated event for the stack area.
22+
The event is sent when the command `thread return <expr>` is sent by the user.
23+
"""
24+
other_source = "other.h"
25+
return_bp_line = line_number(other_source, "// thread return breakpoint")
26+
27+
program = self.getBuildArtifact("a.out")
28+
self.build_and_launch(program)
29+
self.set_source_breakpoints(other_source, [return_bp_line])
30+
self.continue_to_next_stop()
31+
32+
self.verify_top_frame_name("add")
33+
thread_id = self.dap_server.get_thread_id()
34+
self.assertIsNotNone(thread_id, "Exepected a thread id.")
35+
36+
# run thread return
37+
thread_command = "thread return 20"
38+
eval_resp = self.dap_server.request_evaluate(thread_command, context="repl")
39+
self.assertTrue(eval_resp["success"], f"Failed to evaluate `{thread_command}`.")
40+
41+
# wait for the invalidated stack event.
42+
stack_event = self.dap_server.wait_for_event(["invalidated"])
43+
self.assertIsNotNone(stack_event, "Expected an invalidated event.")
44+
event_body: Event = stack_event["body"]
45+
self.assertIn("stacks", event_body["areas"])
46+
self.assertIn("threadId", event_body.keys())
47+
self.assertEqual(
48+
thread_id,
49+
event_body["threadId"],
50+
f"Expected the event from thread {thread_id}.",
51+
)
52+
53+
# confirm we are back at the main frame.
54+
self.verify_top_frame_name("main")
55+
self.continue_to_exit()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "other.h"
2+
3+
int main() {
4+
int first = 5;
5+
int second = 10;
6+
const int result = add(first, second);
7+
8+
return 0;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef OTHER_H
2+
#define OTHER_H
3+
4+
int add(int a, int b) {
5+
int first = a;
6+
int second = b; // thread return breakpoint
7+
int result = first + second;
8+
return result;
9+
}
10+
#endif // OTHER_H

lldb/unittests/DAP/ProtocolTypesTest.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,14 +1079,17 @@ TEST(ProtocolTypesTest, InvalidatedEventBody) {
10791079
body.areas = {InvalidatedEventBody::eAreaStacks,
10801080
InvalidatedEventBody::eAreaThreads};
10811081
body.stackFrameId = 1;
1082-
StringRef json = R"({
1083-
"areas": [
1084-
"stacks",
1085-
"threads"
1086-
],
1087-
"stackFrameId": 1
1088-
})";
1089-
EXPECT_EQ(json, pp(body));
1082+
body.threadId = 20;
1083+
Expected<json::Value> expected = json::parse(R"({
1084+
"areas": [
1085+
"stacks",
1086+
"threads"
1087+
],
1088+
"stackFrameId": 1,
1089+
"threadId": 20
1090+
})");
1091+
ASSERT_THAT_EXPECTED(expected, llvm::Succeeded());
1092+
EXPECT_EQ(pp(*expected), pp(body));
10901093
}
10911094

10921095
TEST(ProtocolTypesTest, MemoryEventBody) {

0 commit comments

Comments
 (0)