5 from lldbsuite
.test
.lldbtest
import *
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.gdbclientutils
import *
8 from lldbsuite
.test
.lldbgdbclient
import GDBRemoteTestBase
12 return binascii
.hexlify(string
.encode()).decode()
15 class TestPlatformClient(GDBRemoteTestBase
):
16 def test_process_list_with_all_users(self
):
17 """Test connecting to a remote linux platform"""
19 class MyResponder(MockGDBServerResponder
):
21 MockGDBServerResponder
.__init
__(self
)
22 self
.currentQsProc
= 0
23 self
.all_users
= False
25 def qfProcessInfo(self
, packet
):
26 if "all_users:1" in packet
:
28 name
= hexlify("/a/test_process")
32 ["/system/bin/sh", "-c", "/data/local/tmp/lldb-server"],
36 "pid:10;ppid:1;uid:2;gid:3;euid:4;egid:5;name:"
43 self
.all_users
= False
46 def qsProcessInfo(self
):
48 if self
.currentQsProc
== 0:
49 self
.currentQsProc
= 1
50 name
= hexlify("/b/another_test_process")
51 # This intentionally has a badly encoded argument
52 args
= "X".join(map(hexlify
, ["/system/bin/ls", "--help"]))
54 "pid:11;ppid:2;uid:3;gid:4;euid:5;egid:6;name:"
60 elif self
.currentQsProc
== 1:
61 self
.currentQsProc
= 0
66 self
.server
.responder
= MyResponder()
69 self
.runCmd("platform select remote-linux")
70 self
.runCmd("platform connect " + self
.server
.get_connect_url())
71 self
.assertTrue(self
.dbg
.GetSelectedPlatform().IsConnected())
73 "platform process list -x",
75 "2 matching processes were found",
77 "another_test_process",
81 "platform process list -xv",
83 "PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE ARGUMENTS",
84 "10 1 2 3 4 5 /system/bin/sh -c /data/local/tmp/lldb-server",
89 "platform process list -xv", substrs
=["/system/bin/ls"], matching
=False
92 "platform process list",
95 'error: no processes were found on the "remote-linux" platform'
99 self
.dbg
.GetSelectedPlatform().DisconnectRemote()
101 class TimeoutResponder(MockGDBServerResponder
):
102 """A mock server, which takes a very long time to compute the working
106 MockGDBServerResponder
.__init
__(self
)
108 def qGetWorkingDir(self
):
110 return hexlify("/foo/bar")
112 def test_no_timeout(self
):
113 """Test that we honor the timeout setting. With a large enough timeout,
114 we should get the CWD successfully."""
116 self
.server
.responder
= TestPlatformClient
.TimeoutResponder()
117 self
.runCmd("settings set plugin.process.gdb-remote.packet-timeout 30")
118 plat
= lldb
.SBPlatform("remote-linux")
122 lldb
.SBPlatformConnectOptions(self
.server
.get_connect_url())
125 self
.assertEqual(plat
.GetWorkingDirectory(), "/foo/bar")
127 plat
.DisconnectRemote()
129 def test_timeout(self
):
130 """Test that we honor the timeout setting. With a small timeout, CWD
131 retrieval should fail."""
133 self
.server
.responder
= TestPlatformClient
.TimeoutResponder()
134 self
.runCmd("settings set plugin.process.gdb-remote.packet-timeout 3")
135 plat
= lldb
.SBPlatform("remote-linux")
139 lldb
.SBPlatformConnectOptions(self
.server
.get_connect_url())
142 self
.assertIsNone(plat
.GetWorkingDirectory())
144 plat
.DisconnectRemote()