1515bc8c1Sserge-sans-paille#!/usr/bin/env python 20dc3ef37SVitaly Buka 30dc3ef37SVitaly Bukaimport os, signal, sys, subprocess, tempfile 40dc3ef37SVitaly Bukafrom android_common import * 50dc3ef37SVitaly Buka 6*f98ee40fSTobias HietaANDROID_TMPDIR = "/data/local/tmp/Output" 70dc3ef37SVitaly Buka 84a3e502dSEvgeniy Stepanovdevice_binary = host_to_device_path(sys.argv[0]) 90dc3ef37SVitaly Buka 10*f98ee40fSTobias Hieta 110dc3ef37SVitaly Bukadef build_env(): 120dc3ef37SVitaly Buka args = [] 130dc3ef37SVitaly Buka # Android linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir. 14*f98ee40fSTobias Hieta args.append("LD_LIBRARY_PATH=%s" % (ANDROID_TMPDIR,)) 1594210b12SVitaly Buka for (key, value) in list(os.environ.items()): 16*f98ee40fSTobias Hieta if key in ["ASAN_ACTIVATION_OPTIONS", "SCUDO_OPTIONS"] or key.endswith( 17*f98ee40fSTobias Hieta "SAN_OPTIONS" 18*f98ee40fSTobias Hieta ): 19bcdd4359SVitaly Buka args.append('%s="%s"' % (key, value.replace('"', '\\"'))) 20*f98ee40fSTobias Hieta return " ".join(args) 210dc3ef37SVitaly Buka 22*f98ee40fSTobias Hieta 23*f98ee40fSTobias Hietais_64bit = ( 24*f98ee40fSTobias Hieta str(subprocess.check_output(["file", sys.argv[0] + ".real"])).find("64-bit") != -1 25*f98ee40fSTobias Hieta) 260dc3ef37SVitaly Buka 270dc3ef37SVitaly Bukadevice_env = build_env() 28*f98ee40fSTobias Hietadevice_args = " ".join(sys.argv[1:]) # FIXME: escape? 29*f98ee40fSTobias Hietadevice_stdout = device_binary + ".stdout" 30*f98ee40fSTobias Hietadevice_stderr = device_binary + ".stderr" 31*f98ee40fSTobias Hietadevice_exitcode = device_binary + ".exitcode" 32*f98ee40fSTobias Hietaret = adb( 33*f98ee40fSTobias Hieta [ 34*f98ee40fSTobias Hieta "shell", 35*f98ee40fSTobias Hieta "cd %s && %s %s %s >%s 2>%s ; echo $? >%s" 36*f98ee40fSTobias Hieta % ( 37*f98ee40fSTobias Hieta ANDROID_TMPDIR, 38*f98ee40fSTobias Hieta device_env, 39*f98ee40fSTobias Hieta device_binary, 40*f98ee40fSTobias Hieta device_args, 41*f98ee40fSTobias Hieta device_stdout, 42*f98ee40fSTobias Hieta device_stderr, 43*f98ee40fSTobias Hieta device_exitcode, 44*f98ee40fSTobias Hieta ), 45*f98ee40fSTobias Hieta ] 46*f98ee40fSTobias Hieta) 470dc3ef37SVitaly Bukaif ret != 0: 480dc3ef37SVitaly Buka sys.exit(ret) 490dc3ef37SVitaly Buka 500dc3ef37SVitaly Bukasys.stdout.write(pull_from_device(device_stdout)) 510dc3ef37SVitaly Bukasys.stderr.write(pull_from_device(device_stderr)) 520dc3ef37SVitaly Bukaretcode = int(pull_from_device(device_exitcode)) 530dc3ef37SVitaly Buka# If the device process died with a signal, do abort(). 540dc3ef37SVitaly Buka# Not exactly the same, but good enough to fool "not --crash". 550dc3ef37SVitaly Bukaif retcode > 128: 560dc3ef37SVitaly Buka os.kill(os.getpid(), signal.SIGABRT) 570dc3ef37SVitaly Bukasys.exit(retcode) 58