1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
34 def getADBProgramPID(program):
35 adbCmd = common.shellquote(common.ADB_BIN)
38 process = subprocess.Popen("%s shell ps" % adbCmd, shell=True, stdout=subprocess.PIPE)
41 for line in process.stdout.readlines():
46 fields = string.split(line)
47 fields = filter(lambda x: len(x) > 0, fields)
52 if fields[8] == program:
58 if process.returncode != 0:
59 print("adb shell ps returned %s" % str(process.returncode))
78 gdbServerProcess = None
82 debugDir = os.path.join(common.ANDROID_DIR, "debug")
84 if os.path.exists(debugDir):
85 shutil.rmtree(debugDir)
92 print("Starting intent...")
93 common.execute("%s shell am start -W -D -n com.drawelements.deqp/android.app.NativeActivity -e cmdLine \"unused %s\"" % (adbCmd, deqpCmdLine.replace("\"", "\\\"")))
94 print("Intent started")
96 # Kill existing gdbservers
97 print("Check and kill existing gdbserver")
98 gdbPid = getADBProgramPID("lib/gdbserver")
100 print("Found gdbserver with PID %i" % gdbPid)
101 common.execute("%s shell run-as com.drawelements.deqp kill -9 %i" % (adbCmd, gdbPid))
102 print("Killed gdbserver")
104 print("Couldn't find existing gdbserver")
106 programPid = getADBProgramPID("com.drawelements.deqp:testercore")
108 print("Find process PID")
110 common.die("Couldn't get PID of testercore")
111 print("Process running with PID %i" % programPid)
114 print("Start gdbserver for PID %i redirect stdout to gdbserver-stdout.txt" % programPid)
115 gdbServerProcess = subprocess.Popen("%s shell run-as com.drawelements.deqp lib/gdbserver localhost:%i --attach %i" % (adbCmd, targetGDBPort, programPid), shell=True, stdin=subprocess.PIPE, stdout=open("gdbserver-stdout.txt", "wb"), stderr=open("gdbserver-stderr.txt", "wb"))
116 print("gdbserver started")
120 gdbServerProcess.poll()
122 if gdbServerProcess.returncode != None:
123 common.die("gdbserver returned unexpectly with return code %i see gdbserver-stdout.txt for more info" % gdbServerProcess.returncode)
125 # Setup port forwarding
126 print("Forwarding local port to gdbserver port")
127 common.execute("%s forward tcp:%i tcp:%i" % (adbCmd, hostGDBPort, targetGDBPort))
129 # Pull some data files for debugger
130 print("Pull /system/bin/app_process from device")
131 common.execute("%s pull /system/bin/app_process" % adbCmd)
133 print("Pull /system/bin/linker from device")
134 common.execute("%s pull /system/bin/linker" % adbCmd)
136 for lib in deviceLibs:
137 print("Pull library %s from device" % lib)
138 common.execute("%s pull %s" % (adbCmd, lib))
140 print("Copy %s from build dir" % common.NATIVE_LIB_NAME)
141 shutil.copyfile(os.path.join(buildDir, common.NATIVE_LIB_NAME), common.NATIVE_LIB_NAME)
143 # Forward local port for jdb
144 print("Forward local port to jdb port")
145 common.execute("%s forward tcp:%i jdwp:%i" % (adbCmd, jdbPort, programPid))
148 print("Start jdb process redirectd stdout to jdb-stdout.txt")
149 jdbProcess = subprocess.Popen("%s -connect com.sun.jdi.SocketAttach:hostname=localhost,port=%i -sourcepath ../package" % (jdbCmd, jdbPort), shell=True, stdin=subprocess.PIPE, stdout=open("jdb-stdout.txt", "wb"), stderr=open("jdb-stderr.txt", "wb"))
150 print("Started jdb process")
153 print("Write gdb.setup")
154 gdbSetup = open("gdb.setup", "wb")
155 gdbSetup.write("file app_process\n")
156 gdbSetup.write("set solib-search-path .\n")
157 gdbSetup.write("target remote :%i\n" % hostGDBPort)
158 gdbSetup.write("set breakpoint pending on\n")
160 for breakpoint in breakpoints:
161 print("Set breakpoint at %s" % breakpoint)
162 gdbSetup.write("break %s\n" % breakpoint)
164 gdbSetup.write("set breakpoint pending off\n")
168 gdbProcess = subprocess.Popen("%s -x gdb.setup" % common.shellquote(gdbCmd), shell=True)
172 print("gdb returned with %i" % gdbProcess.returncode)
175 print("Close jdb process with 'quit'")
176 jdbProcess.stdin.write("quit\n")
178 print("JDB returned %s" % str(jdbProcess.returncode))
181 print("Kill gdbserver process")
182 gdbServerProcess.kill()
183 gdbServerProcess=None
184 print("Killed gdbserver process")
186 print("Kill program %i" % programPid)
187 common.execute("%s shell run-as com.drawelements.deqp -9 %i" % (adbCmd, programPid))
188 print("Killed program")
191 if jdbProcess and jdbProcess.returncode == None:
195 print("JDB returned %i" % jdbProcess.returncode)
197 if gdbProcess and gdbProcess.returncode == None:
201 print("GDB returned %i" % gdbProcess.returncode)
203 if gdbServerProcess and gdbServerProcess.returncode == None:
204 print("Kill gdbserver")
205 gdbServerProcess.kill()
206 elif gdbServerProcess:
207 print("GDB server returned %i" % gdbServerProcess.returncode)
209 print("Kill program %i" % programPid)
210 common.execute("%s shell run-as com.drawelements.deqp kill -9 %i" % (adbCmd, programPid))
211 print("Killed program")
215 if __name__ == "__main__":
216 parser = argparse.ArgumentParser()
218 defaultDeviceLibs = {
220 "/system/lib/libgenlock.so",
221 "/system/lib/libmemalloc.so",
222 "/system/lib/libqdutils.so",
223 "/system/lib/libsc-a3xx.so"
229 for device in defaultDeviceLibs:
230 defaultDevices += [device]
232 parser.add_argument('--adb', dest='adbCmd', default=common.shellquote(common.ADB_BIN), help="Path to adb command. Use absolute paths.")
233 parser.add_argument('--deqp-commandline', dest='deqpCmdLine', default="--deqp-log-filename=/sdcard/TestLog.qpa", help="Command line arguments passed to dEQP test binary.")
235 if common.getPlatform() == "linux":
236 parser.add_argument('--gdb', dest='gdbCmd', default=common.shellquote(os.path.join(common.ANDROID_NDK_PATH, "toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb")), help="gdb command used by script. Use absolute paths")
238 parser.add_argument('--gdb', dest='gdbCmd', default=common.shellquote(os.path.join(common.ANDROID_NDK_PATH, "toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/arm-linux-androideabi-gdb")), help="gdb command used by script. Use absolute paths")
240 parser.add_argument('--target-gdb-port', dest='targetGDBPort', default=60001, type=int, help="Port used by gdbserver on target.")
241 parser.add_argument('--host-gdb-port', dest='hostGDBPort', default=60002, type=int, help="Host port that is forwarded to device gdbserver port.")
242 parser.add_argument('--jdb', dest='jdbCmd', default="jdb", help="Path to jdb command. Use absolute paths.")
243 parser.add_argument('--jdb-port', dest='jdbPort', default=60003, type=int, help="Host port used to forward jdb commands to device.")
244 parser.add_argument('--build-dir', dest='buildDir', default="../../../deqp-build-android-9-armeabi-v7a-debug", help="Path to dEQP native build directory.")
245 parser.add_argument('--device-libs', dest='deviceLibs', default=[], nargs='+', help="List of libraries that should be pulled from device for debugging.")
246 parser.add_argument('--breakpoints', dest='breakpoints', default=["tcu::App::App"], nargs='+', help="List of breakpoints that are set by gdb.")
247 parser.add_argument('--device', dest='device', default=None, choices=defaultDevices, help="Pull default libraries for this device.")
249 args = parser.parse_args()
251 debug(adbCmd=os.path.normpath(args.adbCmd),
252 gdbCmd=os.path.normpath(args.gdbCmd),
253 targetGDBPort=args.targetGDBPort,
254 hostGDBPort=args.hostGDBPort,
255 jdbCmd=os.path.normpath(args.jdbCmd),
256 jdbPort=args.jdbPort,
257 deqpCmdLine=args.deqpCmdLine,
258 buildDir=args.buildDir,
259 deviceLibs=["/system/lib/libc.so", "/system/lib/libdl.so"] + args.deviceLibs + (defaultDeviceLibs[args.device] if args.device else []),
260 breakpoints=args.breakpoints)