Skip to content

Commit 6d4b3aa

Browse files
committed
Refactor tests to be concise and add progresse end, add additional check to sbprogress description check
1 parent 79394c3 commit 6d4b3aa

File tree

2 files changed

+54
-91
lines changed

2 files changed

+54
-91
lines changed

lldb/source/API/SBProgress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void SBProgress::Increment(uint64_t amount, const char *description) {
4141
LLDB_INSTRUMENT_VA(amount, description);
4242

4343
std::optional<std::string> description_opt;
44-
if (description)
44+
if (description && description[0])
4545
description_opt = description;
4646
m_opaque_up->Increment(amount, description_opt);
4747
}

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

Lines changed: 53 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@
1212

1313

1414
class TestDAP_progress(lldbdap_testcase.DAPTestCaseBase):
15+
def verify_progress_events(
16+
self,
17+
expected_title,
18+
expected_message=None,
19+
expected_not_in_message=None,
20+
only_verify_first_update=False,
21+
):
22+
self.dap_server.wait_for_event("progressEnd", 15)
23+
self.assertTrue(len(self.dap_server.progress_events) > 0)
24+
start_found = False
25+
update_found = False
26+
end_found = False
27+
for event in self.dap_server.progress_events:
28+
event_type = event["event"]
29+
if "progressStart" in event_type:
30+
title = event["body"]["title"]
31+
self.assertIn(expected_title, title)
32+
start_found = True
33+
if "progressUpdate" in event_type:
34+
message = event["body"]["message"]
35+
print(f"Progress update: {message}")
36+
if only_verify_first_update and update_found:
37+
continue
38+
if expected_message is not None:
39+
self.assertIn(expected_message, message)
40+
if expected_not_in_message is not None:
41+
self.assertNotIn(expected_not_in_message, message)
42+
update_found = True
43+
if "progressEnd" in event_type:
44+
end_found = True
45+
46+
self.assertTrue(start_found)
47+
self.assertTrue(update_found)
48+
self.assertTrue(end_found)
49+
1550
@skipIfWindows
1651
def test_output(self):
1752
program = self.getBuildArtifact("a.out")
@@ -30,28 +65,10 @@ def test_output(self):
3065
"`test-progress --total 3 --seconds 1", context="repl"
3166
)
3267

33-
self.dap_server.wait_for_event("progressEnd", 15)
34-
# Expect at least a start, an update, and end event
35-
# However because the underlying Progress instance is an RAII object and we can't guaruntee
36-
# it's deterministic destruction in the python API, we verify just start and update
37-
# otherwise this test could be flakey.
38-
self.assertTrue(len(self.dap_server.progress_events) > 0)
39-
start_found = False
40-
update_found = False
41-
for event in self.dap_server.progress_events:
42-
event_type = event["event"]
43-
if "progressStart" in event_type:
44-
title = event["body"]["title"]
45-
self.assertIn("Progress tester", title)
46-
start_found = True
47-
if "progressUpdate" in event_type:
48-
message = event["body"]["message"]
49-
print(f"Progress update: {message}")
50-
self.assertNotIn("Progres tester", message)
51-
update_found = True
52-
53-
self.assertTrue(start_found)
54-
self.assertTrue(update_found)
68+
self.verify_progress_events(
69+
expected_title="Progress tester",
70+
expected_not_in_message="Progress tester",
71+
)
5572

5673
@skipIfWindows
5774
def test_output_nodetails(self):
@@ -71,27 +88,10 @@ def test_output_nodetails(self):
7188
"`test-progress --total 3 --seconds 1 --no-details", context="repl"
7289
)
7390

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-
self.assertEqual("Initial Detail", message)
91-
update_found = True
92-
93-
self.assertTrue(start_found)
94-
self.assertTrue(update_found)
91+
self.verify_progress_events(
92+
expected_title="Progress tester",
93+
expected_message="Initial Detail",
94+
)
9595

9696
@skipIfWindows
9797
def test_output_indeterminate(self):
@@ -109,30 +109,11 @@ def test_output_indeterminate(self):
109109
)
110110
self.dap_server.request_evaluate("`test-progress --seconds 1", context="repl")
111111

112-
self.dap_server.wait_for_event("progressEnd", 15)
113-
# Expect at least a start, an update, and end event
114-
# However because the underlying Progress instance is an RAII object and we can't guaruntee
115-
# it's deterministic destruction in the python API, we verify just start and update
116-
# otherwise this test could be flakey.
117-
self.assertTrue(len(self.dap_server.progress_events) > 0)
118-
start_found = False
119-
update_found = False
120-
for event in self.dap_server.progress_events:
121-
event_type = event["event"]
122-
if "progressStart" in event_type:
123-
title = event["body"]["title"]
124-
self.assertIn("Progress tester", title)
125-
start_found = True
126-
if "progressUpdate" in event_type:
127-
message = event["body"]["message"]
128-
print(f"Progress update: {message}")
129-
# Check on the first update we set the initial detail.
130-
if not update_found:
131-
self.assertEqual("Step 1", message)
132-
update_found = True
133-
134-
self.assertTrue(start_found)
135-
self.assertTrue(update_found)
112+
self.verify_progress_events(
113+
expected_title="Progress tester",
114+
expected_message="Step 1",
115+
only_verify_first_update=True,
116+
)
136117

137118
@skipIfWindows
138119
def test_output_nodetails_indeterminate(self):
@@ -152,26 +133,8 @@ def test_output_nodetails_indeterminate(self):
152133
"`test-progress --seconds 1 --no-details", context="repl"
153134
)
154135

155-
self.dap_server.wait_for_event("progressEnd", 15)
156-
# Expect at least a start, an update, and end event
157-
# However because the underlying Progress instance is an RAII object and we can't guaruntee
158-
# it's deterministic destruction in the python API, we verify just start and update
159-
# otherwise this test could be flakey.
160-
self.assertTrue(len(self.dap_server.progress_events) > 0)
161-
start_found = False
162-
update_found = False
163-
for event in self.dap_server.progress_events:
164-
event_type = event["event"]
165-
if "progressStart" in event_type:
166-
title = event["body"]["title"]
167-
self.assertIn("Progress tester", title)
168-
start_found = True
169-
if "progressUpdate" in event_type:
170-
message = event["body"]["message"]
171-
# Check on the first update we set the initial detail.
172-
if not update_found:
173-
self.assertEqual("Initial Indeterminate Detail", message)
174-
update_found = True
175-
176-
self.assertTrue(start_found)
177-
self.assertTrue(update_found)
136+
self.verify_progress_events(
137+
expected_title="Progress tester",
138+
expected_message="Initial Indeterminate Detail",
139+
only_verify_first_update=True,
140+
)

0 commit comments

Comments
 (0)