Skip to content

Commit 681352c

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

File tree

2 files changed

+55
-91
lines changed

2 files changed

+55
-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: 54 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@
1212

1313

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

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)
69+
self.verify_progress_events(
70+
expected_title="Progress tester",
71+
expected_not_in_message="Progress tester",
72+
)
5573

5674
@skipIfWindows
5775
def test_output_nodetails(self):
@@ -71,27 +89,10 @@ def test_output_nodetails(self):
7189
"`test-progress --total 3 --seconds 1 --no-details", context="repl"
7290
)
7391

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)
92+
self.verify_progress_events(
93+
expected_title="Progress tester",
94+
expected_message="Initial Detail",
95+
)
9596

9697
@skipIfWindows
9798
def test_output_indeterminate(self):
@@ -109,30 +110,11 @@ def test_output_indeterminate(self):
109110
)
110111
self.dap_server.request_evaluate("`test-progress --seconds 1", context="repl")
111112

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)
113+
self.verify_progress_events(
114+
expected_title="Progress tester",
115+
expected_message="Step 1",
116+
only_verify_first_update=True,
117+
)
136118

137119
@skipIfWindows
138120
def test_output_nodetails_indeterminate(self):
@@ -152,26 +134,8 @@ def test_output_nodetails_indeterminate(self):
152134
"`test-progress --seconds 1 --no-details", context="repl"
153135
)
154136

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)
137+
self.verify_progress_events(
138+
expected_title="Progress tester",
139+
expected_message="Initial Indeterminate Detail",
140+
only_verify_first_update=True,
141+
)

0 commit comments

Comments
 (0)