61 lines · python
1#!/usr/bin/env python32 3import os, signal, sys, subprocess, tempfile4from android_common import *5 6ANDROID_TMPDIR = "/data/local/tmp/Output"7 8device_binary = host_to_device_path(sys.argv[0])9 10 11def build_env():12 args = []13 # Android linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir.14 args.append("LD_LIBRARY_PATH=%s" % (ANDROID_TMPDIR,))15 for key, value in list(os.environ.items()):16 if key in [17 "ASAN_ACTIVATION_OPTIONS",18 "SCUDO_OPTIONS",19 "HOME",20 "TMPDIR",21 ] or key.endswith("SAN_OPTIONS"):22 args.append('%s="%s"' % (key, value.replace('"', '\\"')))23 return " ".join(args)24 25 26is_64bit = (27 str(subprocess.check_output(["file", sys.argv[0] + ".real"])).find("64-bit") != -128)29 30device_env = build_env()31device_args = " ".join(sys.argv[1:]) # FIXME: escape?32device_stdout = device_binary + ".stdout"33device_stderr = device_binary + ".stderr"34device_exitcode = device_binary + ".exitcode"35ret = adb(36 [37 "shell",38 "cd %s && %s %s %s >%s 2>%s ; echo $? >%s"39 % (40 ANDROID_TMPDIR,41 device_env,42 device_binary,43 device_args,44 device_stdout,45 device_stderr,46 device_exitcode,47 ),48 ]49)50if ret != 0:51 sys.exit(ret)52 53sys.stdout.write(pull_from_device(device_stdout))54sys.stderr.write(pull_from_device(device_stderr))55retcode = int(pull_from_device(device_exitcode))56# If the device process died with a signal, do abort().57# Not exactly the same, but good enough to fool "not --crash".58if retcode > 128:59 os.kill(os.getpid(), signal.SIGABRT)60sys.exit(retcode)61