1a40929dcSPavel Labathimport lldb 2a40929dcSPavel Labathimport time 3a40929dcSPavel Labathfrom lldbsuite.test.lldbtest import * 4a40929dcSPavel Labathfrom lldbsuite.test.decorators import * 5*33c0f93fSPavel Labathfrom lldbsuite.test.gdbclientutils import * 6*33c0f93fSPavel Labathfrom lldbsuite.test.lldbgdbclient import GDBRemoteTestBase 7a40929dcSPavel Labath 8a40929dcSPavel Labathclass TestPlatformKill(GDBRemoteTestBase): 9a40929dcSPavel Labath 10a40929dcSPavel Labath @skipIfRemote 11adc7d63fSPavel Labath @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr52451") 12a40929dcSPavel Labath def test_kill_different_platform(self): 13a40929dcSPavel Labath """Test connecting to a remote linux platform""" 14a40929dcSPavel Labath 15a40929dcSPavel Labath self.build(dictionary={"CXX_SOURCES":"sleep.cpp"}) 16a40929dcSPavel Labath host_process = self.spawnSubprocess(self.getBuildArtifact()) 17a40929dcSPavel Labath 18a40929dcSPavel Labath # Create a fake remote process with the same PID as host_process 19a40929dcSPavel Labath class MyResponder(MockGDBServerResponder): 20a40929dcSPavel Labath def __init__(self): 21a40929dcSPavel Labath MockGDBServerResponder.__init__(self) 22a40929dcSPavel Labath self.got_kill = False 23a40929dcSPavel Labath 24a40929dcSPavel Labath def qC(self): 25a40929dcSPavel Labath return "QC%x"%host_process.pid 26a40929dcSPavel Labath 27a40929dcSPavel Labath def k(self): 28a40929dcSPavel Labath self.got_kill = True 29a40929dcSPavel Labath return "X09" 30a40929dcSPavel Labath 31a40929dcSPavel Labath self.server.responder = MyResponder() 32a40929dcSPavel Labath 33a40929dcSPavel Labath error = lldb.SBError() 34a40929dcSPavel Labath target = self.dbg.CreateTarget("", "x86_64-pc-linux", "remote-linux", 35a40929dcSPavel Labath False, error) 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