101 lines · python
1"""2Test lldb-dap output events3"""4 5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7import json8import os9import time10import re11 12import lldbdap_testcase13 14 15class TestDAP_progress(lldbdap_testcase.DAPTestCaseBase):16 def verify_progress_events(17 self,18 expected_title,19 expected_message=None,20 expected_message_regex=None,21 expected_not_in_message=None,22 only_verify_first_update=False,23 ):24 self.dap_server.wait_for_event(["progressEnd"])25 self.assertTrue(len(self.dap_server.progress_events) > 0)26 start_found = False27 update_found = False28 end_found = False29 for event in self.dap_server.progress_events:30 event_type = event["event"]31 if "progressStart" in event_type:32 title = event["body"]["title"]33 self.assertIn(expected_title, title)34 start_found = True35 if "progressUpdate" in event_type:36 message = event["body"]["message"]37 if only_verify_first_update and update_found:38 continue39 if expected_message is not None:40 self.assertIn(expected_message, message)41 if expected_message_regex is not None:42 self.assertTrue(re.match(expected_message_regex, message))43 if expected_not_in_message is not None:44 self.assertNotIn(expected_not_in_message, message)45 update_found = True46 if "progressEnd" in event_type:47 end_found = True48 49 self.assertTrue(start_found)50 self.assertTrue(update_found)51 self.assertTrue(end_found)52 self.dap_server.progress_events.clear()53 54 @skipIfWindows55 def test(self):56 program = self.getBuildArtifact("a.out")57 self.build_and_launch(program, stopOnEntry=True)58 progress_emitter = os.path.join(os.getcwd(), "Progress_emitter.py")59 self.dap_server.request_evaluate(60 f"`command script import {progress_emitter}", context="repl"61 )62 63 # Test details.64 self.dap_server.request_evaluate(65 "`test-progress --total 3 --seconds 1", context="repl"66 )67 68 self.verify_progress_events(69 expected_title="Progress tester",70 expected_not_in_message="Progress tester",71 )72 73 # Test no details.74 self.dap_server.request_evaluate(75 "`test-progress --total 3 --seconds 1 --no-details", context="repl"76 )77 78 self.verify_progress_events(79 expected_title="Progress tester",80 expected_message="Initial Detail",81 )82 83 # Test details indeterminate.84 self.dap_server.request_evaluate("`test-progress --seconds 1", context="repl")85 86 self.verify_progress_events(87 expected_title="Progress tester: Initial Indeterminate Detail",88 expected_message_regex=r"Step [0-9]+",89 )90 91 # Test no details indeterminate.92 self.dap_server.request_evaluate(93 "`test-progress --seconds 1 --no-details", context="repl"94 )95 96 self.verify_progress_events(97 expected_title="Progress tester: Initial Indeterminate Detail",98 expected_message="Initial Indeterminate Detail",99 only_verify_first_update=True,100 )101