1a40929dcSPavel Labathimport lldb 2a40929dcSPavel Labathimport time 3a40929dcSPavel Labathfrom lldbsuite.test.lldbtest import * 4a40929dcSPavel Labathfrom lldbsuite.test.decorators import * 533c0f93fSPavel Labathfrom lldbsuite.test.gdbclientutils import * 633c0f93fSPavel Labathfrom lldbsuite.test.lldbgdbclient import GDBRemoteTestBase 7a40929dcSPavel Labath 8a40929dcSPavel Labath 9*2238dcc3SJonas Devlieghereclass TestPlatformKill(GDBRemoteTestBase): 10a40929dcSPavel Labath @skipIfRemote 11a40929dcSPavel Labath def test_kill_different_platform(self): 12a40929dcSPavel Labath """Test connecting to a remote linux platform""" 13a40929dcSPavel Labath 14a40929dcSPavel Labath self.build(dictionary={"CXX_SOURCES": "sleep.cpp"}) 15a40929dcSPavel Labath host_process = self.spawnSubprocess(self.getBuildArtifact()) 16a40929dcSPavel Labath 17a40929dcSPavel Labath # Create a fake remote process with the same PID as host_process 18a40929dcSPavel Labath class MyResponder(MockGDBServerResponder): 19a40929dcSPavel Labath def __init__(self): 20a40929dcSPavel Labath MockGDBServerResponder.__init__(self) 21a40929dcSPavel Labath self.got_kill = False 22a40929dcSPavel Labath 23a40929dcSPavel Labath def qC(self): 24a40929dcSPavel Labath return "QC%x" % host_process.pid 25a40929dcSPavel Labath 26a40929dcSPavel Labath def k(self): 27a40929dcSPavel Labath self.got_kill = True 28a40929dcSPavel Labath return "X09" 29a40929dcSPavel Labath 30a40929dcSPavel Labath self.server.responder = MyResponder() 31a40929dcSPavel Labath 32a40929dcSPavel Labath error = lldb.SBError() 33*2238dcc3SJonas Devlieghere target = self.dbg.CreateTarget( 34*2238dcc3SJonas Devlieghere "", "x86_64-pc-linux", "remote-linux", False, error 35*2238dcc3SJonas Devlieghere ) 36a40929dcSPavel Labath self.assertSuccess(error) 37a40929dcSPavel Labath process = self.connect(target) 38a40929dcSPavel Labath self.assertEqual(process.GetProcessID(), host_process.pid) 39a40929dcSPavel Labath 40a40929dcSPavel Labath host_platform = lldb.SBPlatform("host") 41a40929dcSPavel Labath self.assertSuccess(host_platform.Kill(host_process.pid)) 42a40929dcSPavel Labath 43a40929dcSPavel Labath # Host dies, remote process lives. 44a40929dcSPavel Labath self.assertFalse(self.server.responder.got_kill) 45a40929dcSPavel Labath self.assertIsNotNone(host_process.wait(timeout=10)) 46a40929dcSPavel Labath 47a40929dcSPavel Labath # Now kill the remote one as well 48a40929dcSPavel Labath self.assertSuccess(process.Kill()) 49a40929dcSPavel Labath self.assertTrue(self.server.responder.got_kill) 50