Skip to content

Commit 9ae2fbb

Browse files
committed
Add new test cases, and refactor to support TITLE: DETAIL in all scenarios
1 parent b6b0866 commit 9ae2fbb

File tree

2 files changed

+152
-4
lines changed

2 files changed

+152
-4
lines changed

lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def create_options(cls):
3737
)
3838

3939
parser.add_option(
40-
"--total", dest="total", help="Total to count up.", type="int"
40+
"--total",
41+
dest="total",
42+
help="Total to count up, use -1 to identify as indeterminate",
43+
type="int",
4144
)
4245

4346
parser.add_option(
@@ -47,6 +50,13 @@ def create_options(cls):
4750
type="int",
4851
)
4952

53+
parser.add_option(
54+
"--no-details",
55+
dest="no_details",
56+
help="Do not display details",
57+
action="store_true",
58+
)
59+
5060
return parser
5161

5262
def get_short_help(self):
@@ -68,10 +78,23 @@ def __call__(self, debugger, command, exe_ctx, result):
6878
return
6979

7080
total = cmd_options.total
71-
progress = lldb.SBProgress("Progress tester", "Detail", total, debugger)
81+
if total == -1:
82+
progress = lldb.SBProgress(
83+
"Progress tester", "Indeterminate Detail", debugger
84+
)
85+
else:
86+
progress = lldb.SBProgress("Progress tester", "Detail", total, debugger)
87+
88+
# Check to see if total is set to -1 to indicate an indeterminate progress
89+
# then default to 10 steps.
90+
if total == -1:
91+
total = 10
7292

7393
for i in range(1, total):
74-
progress.Increment(1, f"Step {i}")
94+
if cmd_options.no_details:
95+
progress.Increment(1)
96+
else:
97+
progress.Increment(1, f"Step {i}")
7598
time.sleep(cmd_options.seconds)
7699

77100

lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from lldbsuite.test.decorators import *
66
from lldbsuite.test.lldbtest import *
7+
import json
78
import os
89
import time
910

@@ -18,7 +19,6 @@ def test_output(self):
1819
progress_emitter = os.path.join(os.getcwd(), "Progress_emitter.py")
1920
print(f"Progress emitter path: {progress_emitter}")
2021
source = "main.cpp"
21-
# Set breakpoint in the thread function so we can step the threads
2222
breakpoint_ids = self.set_source_breakpoints(
2323
source, [line_number(source, "// break here")]
2424
)
@@ -52,3 +52,128 @@ def test_output(self):
5252

5353
self.assertTrue(start_found)
5454
self.assertTrue(update_found)
55+
56+
@skipIfWindows
57+
def test_output_nodetails(self):
58+
program = self.getBuildArtifact("a.out")
59+
self.build_and_launch(program)
60+
progress_emitter = os.path.join(os.getcwd(), "Progress_emitter.py")
61+
print(f"Progress emitter path: {progress_emitter}")
62+
source = "main.cpp"
63+
breakpoint_ids = self.set_source_breakpoints(
64+
source, [line_number(source, "// break here")]
65+
)
66+
self.continue_to_breakpoints(breakpoint_ids)
67+
self.dap_server.request_evaluate(
68+
f"`command script import {progress_emitter}", context="repl"
69+
)
70+
self.dap_server.request_evaluate(
71+
"`test-progress --total 3 --seconds 1 --no-details", context="repl"
72+
)
73+
74+
self.dap_server.wait_for_event("progressEnd", 15)
75+
# Expect at least a start, an update, and end event
76+
# However because the underlying Progress instance is an RAII object and we can't guaruntee
77+
# it's deterministic destruction in the python API, we verify just start and update
78+
# otherwise this test could be flakey.
79+
self.assertTrue(len(self.dap_server.progress_events) > 0)
80+
start_found = False
81+
update_found = False
82+
for event in self.dap_server.progress_events:
83+
event_type = event["event"]
84+
if "progressStart" in event_type:
85+
title = event["body"]["title"]
86+
self.assertIn("Progress tester", title)
87+
start_found = True
88+
if "progressUpdate" in event_type:
89+
message = event["body"]["message"]
90+
# We send an update on first message to set the details, so ignore the first update
91+
if not update_found:
92+
self.assertTrue(message == "", message)
93+
update_found = True
94+
95+
self.assertTrue(start_found)
96+
self.assertTrue(update_found)
97+
98+
@skipIfWindows
99+
def test_output_indeterminate(self):
100+
program = self.getBuildArtifact("a.out")
101+
self.build_and_launch(program)
102+
progress_emitter = os.path.join(os.getcwd(), "Progress_emitter.py")
103+
print(f"Progress emitter path: {progress_emitter}")
104+
source = "main.cpp"
105+
breakpoint_ids = self.set_source_breakpoints(
106+
source, [line_number(source, "// break here")]
107+
)
108+
self.continue_to_breakpoints(breakpoint_ids)
109+
self.dap_server.request_evaluate(
110+
f"`command script import {progress_emitter}", context="repl"
111+
)
112+
self.dap_server.request_evaluate(
113+
"`test-progress --total -1 --seconds 1", context="repl"
114+
)
115+
116+
self.dap_server.wait_for_event("progressEnd", 15)
117+
# Expect at least a start, an update, and end event
118+
# However because the underlying Progress instance is an RAII object and we can't guaruntee
119+
# it's deterministic destruction in the python API, we verify just start and update
120+
# otherwise this test could be flakey.
121+
self.assertTrue(len(self.dap_server.progress_events) > 0)
122+
start_found = False
123+
update_found = False
124+
for event in self.dap_server.progress_events:
125+
event_type = event["event"]
126+
if "progressStart" in event_type:
127+
title = event["body"]["title"]
128+
self.assertIn("Progress tester", title)
129+
start_found = True
130+
if "progressUpdate" in event_type:
131+
message = event["body"]["message"]
132+
print(f"Progress update: {message}")
133+
self.assertNotIn("Progres tester", message)
134+
update_found = True
135+
136+
self.assertTrue(start_found)
137+
self.assertTrue(update_found)
138+
139+
@skipIfWindows
140+
def test_output_nodetails_indeterminate(self):
141+
program = self.getBuildArtifact("a.out")
142+
self.build_and_launch(program)
143+
progress_emitter = os.path.join(os.getcwd(), "Progress_emitter.py")
144+
print(f"Progress emitter path: {progress_emitter}")
145+
source = "main.cpp"
146+
breakpoint_ids = self.set_source_breakpoints(
147+
source, [line_number(source, "// break here")]
148+
)
149+
self.dap_server.request_evaluate(
150+
f"`command script import {progress_emitter}", context="repl"
151+
)
152+
153+
self.dap_server.request_evaluate(
154+
"`test-progress --total -1 --seconds 1 --no-details", context="repl"
155+
)
156+
157+
self.dap_server.wait_for_event("progressEnd", 15)
158+
# Expect at least a start, an update, and end event
159+
# However because the underlying Progress instance is an RAII object and we can't guaruntee
160+
# it's deterministic destruction in the python API, we verify just start and update
161+
# otherwise this test could be flakey.
162+
self.assertTrue(len(self.dap_server.progress_events) > 0)
163+
start_found = False
164+
update_found = False
165+
for event in self.dap_server.progress_events:
166+
event_type = event["event"]
167+
if "progressStart" in event_type:
168+
title = event["body"]["title"]
169+
self.assertIn("Progress tester", title)
170+
start_found = True
171+
if "progressUpdate" in event_type:
172+
message = event["body"]["message"]
173+
# We send an update on first message to set the details, so ignore the first update
174+
if not update_found:
175+
self.assertTrue(message == "", message)
176+
update_found = True
177+
178+
self.assertTrue(start_found)
179+
self.assertTrue(update_found)

0 commit comments

Comments
 (0)