2da8dd59e17c2dd322ab746ee98f516e585cccfd
[openbsd] /
1 import lldb
2 import binascii
3 import os
4 from lldbsuite.test.lldbtest import *
5 from lldbsuite.test.decorators import *
6 from gdbclientutils import *
7
8 def hexlify(string):
9     return binascii.hexlify(string.encode()).decode()
10
11 class TestPlatformClient(GDBRemoteTestBase):
12
13     def test_process_list_with_all_users(self):
14         """Test connecting to a remote linux platform"""
15
16         class MyResponder(MockGDBServerResponder):
17             def __init__(self):
18                 MockGDBServerResponder.__init__(self)
19                 self.currentQsProc = 0
20                 self.all_users = False
21
22             def qfProcessInfo(self, packet):
23                 if "all_users:1" in packet:
24                     self.all_users = True
25                     name = hexlify("/a/test_process")
26                     args = "-".join(map(hexlify,
27                                         ["/system/bin/sh", "-c", "/data/local/tmp/lldb-server"]))
28                     return "pid:10;ppid:1;uid:2;gid:3;euid:4;egid:5;name:" + name + ";args:" + args + ";"
29                 else:
30                     self.all_users = False
31                     return "E04"
32
33             def qsProcessInfo(self):
34                 if self.all_users:
35                     if self.currentQsProc == 0:
36                         self.currentQsProc = 1
37                         name = hexlify("/b/another_test_process")
38                         # This intentionally has a badly encoded argument
39                         args = "X".join(map(hexlify,
40                                             ["/system/bin/ls", "--help"]))
41                         return "pid:11;ppid:2;uid:3;gid:4;euid:5;egid:6;name:" + name + ";args:" + args + ";"
42                     elif self.currentQsProc == 1:
43                         self.currentQsProc = 0
44                         return "E04"
45                 else:
46                     return "E04"
47
48         self.server.responder = MyResponder()
49
50         try:
51             self.runCmd("platform select remote-linux")
52             self.runCmd("platform connect connect://localhost:%d" %
53                         self.server.port)
54             self.assertTrue(self.dbg.GetSelectedPlatform().IsConnected())
55             self.expect("platform process list -x",
56                         substrs=["2 matching processes were found", "test_process", "another_test_process"])
57             self.expect("platform process list -xv",
58                         substrs=[
59                             "PID    PARENT USER       GROUP      EFF USER   EFF GROUP  TRIPLE                         ARGUMENTS",
60                             "10     1      2          3          4          5                                         /system/bin/sh -c /data/local/tmp/lldb-server",
61                             "11     2      3          4          5          6"])
62             self.expect("platform process list -xv", substrs=["/system/bin/ls"], matching=False)
63             self.expect("platform process list",
64                         error=True,
65                         substrs=["error: no processes were found on the \"remote-linux\" platform"])
66         finally:
67             self.dbg.GetSelectedPlatform().DisconnectRemote()