1 2# lldb test suite imports 3from lldbsuite.test.decorators import * 4from lldbsuite.test.lldbtest import TestBase 5 6# gdb-remote-specific imports 7import lldbgdbserverutils 8from gdbremote_testcase import GdbRemoteTestCaseBase 9 10 11class TestGdbRemoteExitCode(GdbRemoteTestCaseBase): 12 13 mydir = TestBase.compute_mydir(__file__) 14 15 FAILED_LAUNCH_CODE = "E08" 16 17 def get_launch_fail_reason(self): 18 self.reset_test_sequence() 19 self.test_sequence.add_log_lines( 20 ["read packet: $qLaunchSuccess#00"], 21 True) 22 self.test_sequence.add_log_lines( 23 [{"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", 24 "capture": {1: "launch_result"}}], 25 True) 26 context = self.expect_gdbremote_sequence() 27 self.assertIsNotNone(context) 28 return context.get("launch_result")[1:] 29 30 def start_inferior(self): 31 launch_args = self.install_and_create_launch_args() 32 33 server = self.connect_to_debug_monitor() 34 self.assertIsNotNone(server) 35 36 self.add_no_ack_remote_stream() 37 self.test_sequence.add_log_lines( 38 ["read packet: %s" % lldbgdbserverutils.build_gdbremote_A_packet( 39 launch_args)], 40 True) 41 self.test_sequence.add_log_lines( 42 [{"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", 43 "capture": {1: "A_result"}}], 44 True) 45 context = self.expect_gdbremote_sequence() 46 self.assertIsNotNone(context) 47 48 launch_result = context.get("A_result") 49 self.assertIsNotNone(launch_result) 50 if launch_result == self.FAILED_LAUNCH_CODE: 51 fail_reason = self.get_launch_fail_reason() 52 self.fail("failed to launch inferior: " + fail_reason) 53 54 @debugserver_test 55 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 56 def test_start_inferior_debugserver(self): 57 self.init_debugserver_test() 58 self.build() 59 self.start_inferior() 60 61 @llgs_test 62 def test_start_inferior_llgs(self): 63 self.init_llgs_test() 64 self.build() 65 self.start_inferior() 66 67 def inferior_exit_0(self): 68 launch_args = self.install_and_create_launch_args() 69 70 server = self.connect_to_debug_monitor() 71 self.assertIsNotNone(server) 72 73 self.add_no_ack_remote_stream() 74 self.add_verified_launch_packets(launch_args) 75 self.test_sequence.add_log_lines( 76 ["read packet: $vCont;c#a8", 77 "send packet: $W00#00"], 78 True) 79 80 self.expect_gdbremote_sequence() 81 82 @debugserver_test 83 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 84 def test_inferior_exit_0_debugserver(self): 85 self.init_debugserver_test() 86 self.build() 87 self.inferior_exit_0() 88 89 @llgs_test 90 def test_inferior_exit_0_llgs(self): 91 self.init_llgs_test() 92 self.build() 93 self.inferior_exit_0() 94 95 def inferior_exit_42(self): 96 launch_args = self.install_and_create_launch_args() 97 98 server = self.connect_to_debug_monitor() 99 self.assertIsNotNone(server) 100 101 RETVAL = 42 102 103 # build launch args 104 launch_args += ["retval:%d" % RETVAL] 105 106 self.add_no_ack_remote_stream() 107 self.add_verified_launch_packets(launch_args) 108 self.test_sequence.add_log_lines( 109 ["read packet: $vCont;c#a8", 110 "send packet: $W{0:02x}#00".format(RETVAL)], 111 True) 112 113 self.expect_gdbremote_sequence() 114 115 @debugserver_test 116 @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet 117 def test_inferior_exit_42_debugserver(self): 118 self.init_debugserver_test() 119 self.build() 120 self.inferior_exit_42() 121 122 @llgs_test 123 def test_inferior_exit_42_llgs(self): 124 self.init_llgs_test() 125 self.build() 126 self.inferior_exit_42() 127