44
55from lldbsuite .test .decorators import *
66from lldbsuite .test .lldbtest import *
7+ import json
78import os
89import time
910
1011import lldbdap_testcase
1112
1213
1314class 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+ if only_verify_first_update and update_found :
36+ continue
37+ if expected_message is not None :
38+ self .assertIn (expected_message , message )
39+ if expected_not_in_message is not None :
40+ self .assertNotIn (expected_not_in_message , message )
41+ update_found = True
42+ if "progressEnd" in event_type :
43+ end_found = True
44+
45+ self .assertTrue (start_found )
46+ self .assertTrue (update_found )
47+ self .assertTrue (end_found )
48+
1449 @skipIfWindows
1550 def test_output (self ):
1651 program = self .getBuildArtifact ("a.out" )
1752 self .build_and_launch (program )
1853 progress_emitter = os .path .join (os .getcwd (), "Progress_emitter.py" )
19- print (f"Progress emitter path: { progress_emitter } " )
2054 source = "main.cpp"
21- # Set breakpoint in the thread function so we can step the threads
2255 breakpoint_ids = self .set_source_breakpoints (
2356 source , [line_number (source , "// break here" )]
2457 )
@@ -30,20 +63,73 @@ def test_output(self):
3063 "`test-progress --total 3 --seconds 1" , context = "repl"
3164 )
3265
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- start_found = True
45- if "progressUpdate" in event_type :
46- update_found = True
66+ self .verify_progress_events (
67+ expected_title = "Progress tester" ,
68+ expected_not_in_message = "Progress tester" ,
69+ )
4770
48- self .assertTrue (start_found )
49- self .assertTrue (update_found )
71+ @skipIfWindows
72+ def test_output_nodetails (self ):
73+ program = self .getBuildArtifact ("a.out" )
74+ self .build_and_launch (program )
75+ progress_emitter = os .path .join (os .getcwd (), "Progress_emitter.py" )
76+ source = "main.cpp"
77+ breakpoint_ids = self .set_source_breakpoints (
78+ source , [line_number (source , "// break here" )]
79+ )
80+ self .continue_to_breakpoints (breakpoint_ids )
81+ self .dap_server .request_evaluate (
82+ f"`command script import { progress_emitter } " , context = "repl"
83+ )
84+ self .dap_server .request_evaluate (
85+ "`test-progress --total 3 --seconds 1 --no-details" , context = "repl"
86+ )
87+
88+ self .verify_progress_events (
89+ expected_title = "Progress tester" ,
90+ expected_message = "Initial Detail" ,
91+ )
92+
93+ @skipIfWindows
94+ def test_output_indeterminate (self ):
95+ program = self .getBuildArtifact ("a.out" )
96+ self .build_and_launch (program )
97+ progress_emitter = os .path .join (os .getcwd (), "Progress_emitter.py" )
98+ source = "main.cpp"
99+ breakpoint_ids = self .set_source_breakpoints (
100+ source , [line_number (source , "// break here" )]
101+ )
102+ self .continue_to_breakpoints (breakpoint_ids )
103+ self .dap_server .request_evaluate (
104+ f"`command script import { progress_emitter } " , context = "repl"
105+ )
106+ self .dap_server .request_evaluate ("`test-progress --seconds 1" , context = "repl" )
107+
108+ self .verify_progress_events (
109+ expected_title = "Progress tester: Initial Indeterminate Detail" ,
110+ expected_message = "Step 1" ,
111+ only_verify_first_update = True ,
112+ )
113+
114+ @skipIfWindows
115+ def test_output_nodetails_indeterminate (self ):
116+ program = self .getBuildArtifact ("a.out" )
117+ self .build_and_launch (program )
118+ progress_emitter = os .path .join (os .getcwd (), "Progress_emitter.py" )
119+ source = "main.cpp"
120+ breakpoint_ids = self .set_source_breakpoints (
121+ source , [line_number (source , "// break here" )]
122+ )
123+ self .dap_server .request_evaluate (
124+ f"`command script import { progress_emitter } " , context = "repl"
125+ )
126+
127+ self .dap_server .request_evaluate (
128+ "`test-progress --seconds 1 --no-details" , context = "repl"
129+ )
130+
131+ self .verify_progress_events (
132+ expected_title = "Progress tester: Initial Indeterminate Detail" ,
133+ expected_message = "Initial Indeterminate Detail" ,
134+ only_verify_first_update = True ,
135+ )
0 commit comments