1import os 2 3import dap_server 4import lldbdap_testcase 5from lldbsuite.test import lldbtest, lldbutil 6from lldbsuite.test.decorators import * 7 8 9class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase): 10 def test_command_directive_quiet_on_success(self): 11 program = self.getBuildArtifact("a.out") 12 command_quiet = ( 13 "settings set target.show-hex-variable-values-with-leading-zeroes false" 14 ) 15 command_not_quiet = ( 16 "settings set target.show-hex-variable-values-with-leading-zeroes true" 17 ) 18 self.build_and_launch( 19 program, 20 initCommands=["?" + command_quiet, command_not_quiet], 21 terminateCommands=["?" + command_quiet, command_not_quiet], 22 stopCommands=["?" + command_quiet, command_not_quiet], 23 exitCommands=["?" + command_quiet, command_not_quiet], 24 ) 25 full_output = self.collect_console( 26 timeout_secs=1.0, 27 pattern=command_not_quiet, 28 ) 29 self.assertNotIn(command_quiet, full_output) 30 self.assertIn(command_not_quiet, full_output) 31 32 def do_test_abort_on_error( 33 self, 34 use_init_commands=False, 35 use_launch_commands=False, 36 use_pre_run_commands=False, 37 use_post_run_commands=False, 38 ): 39 program = self.getBuildArtifact("a.out") 40 command_quiet = ( 41 "settings set target.show-hex-variable-values-with-leading-zeroes false" 42 ) 43 command_abort_on_error = "settings set foo bar" 44 commands = ["?!" + command_quiet, "!" + command_abort_on_error] 45 self.build_and_launch( 46 program, 47 initCommands=commands if use_init_commands else None, 48 launchCommands=commands if use_launch_commands else None, 49 preRunCommands=commands if use_pre_run_commands else None, 50 postRunCommands=commands if use_post_run_commands else None, 51 expectFailure=True, 52 ) 53 full_output = self.collect_console( 54 timeout_secs=1.0, 55 pattern=command_abort_on_error, 56 ) 57 self.assertNotIn(command_quiet, full_output) 58 self.assertIn(command_abort_on_error, full_output) 59 60 def test_command_directive_abort_on_error_init_commands(self): 61 self.do_test_abort_on_error(use_init_commands=True) 62 63 def test_command_directive_abort_on_error_launch_commands(self): 64 self.do_test_abort_on_error(use_launch_commands=True) 65 66 def test_command_directive_abort_on_error_pre_run_commands(self): 67 self.do_test_abort_on_error(use_pre_run_commands=True) 68 69 def test_command_directive_abort_on_error_post_run_commands(self): 70 self.do_test_abort_on_error(use_post_run_commands=True) 71 72 def test_command_directive_abort_on_error_attach_commands(self): 73 program = self.getBuildArtifact("a.out") 74 command_quiet = ( 75 "settings set target.show-hex-variable-values-with-leading-zeroes false" 76 ) 77 command_abort_on_error = "settings set foo bar" 78 self.build_and_create_debug_adaptor() 79 self.attach( 80 program, 81 attachCommands=["?!" + command_quiet, "!" + command_abort_on_error], 82 expectFailure=True, 83 ) 84 full_output = self.collect_console( 85 timeout_secs=1.0, 86 pattern=command_abort_on_error, 87 ) 88 self.assertNotIn(command_quiet, full_output) 89 self.assertIn(command_abort_on_error, full_output) 90