]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/sanitizer_common/android_commands/android_run.py
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / sanitizer_common / android_commands / android_run.py
1 #!/usr/bin/python
2
3 import os, signal, sys, subprocess, tempfile
4 from android_common import *
5
6 ANDROID_TMPDIR = '/data/local/tmp/Output'
7
8 device_binary = host_to_device_path(sys.argv[0])
9
10 def build_env():
11     args = []
12     # Android linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir.
13     args.append('LD_LIBRARY_PATH=%s' % (ANDROID_TMPDIR,))
14     for (key, value) in os.environ.items():
15         if key in ['ASAN_ACTIVATION_OPTIONS', 'SCUDO_OPTIONS'] or key.endswith('SAN_OPTIONS'):
16             args.append('%s="%s"' % (key, value))
17     return ' '.join(args)
18
19 is_64bit = (subprocess.check_output(['file', sys.argv[0] + '.real']).find('64-bit') != -1)
20
21 device_env = build_env()
22 device_args = ' '.join(sys.argv[1:]) # FIXME: escape?
23 device_stdout = device_binary + '.stdout'
24 device_stderr = device_binary + '.stderr'
25 device_exitcode = device_binary + '.exitcode'
26 ret = adb(['shell', 'cd %s && %s %s %s >%s 2>%s ; echo $? >%s' %
27            (ANDROID_TMPDIR, device_env, device_binary, device_args,
28             device_stdout, device_stderr, device_exitcode)])
29 if ret != 0:
30     sys.exit(ret)
31
32 sys.stdout.write(pull_from_device(device_stdout))
33 sys.stderr.write(pull_from_device(device_stderr))
34 retcode = int(pull_from_device(device_exitcode))
35 # If the device process died with a signal, do abort().
36 # Not exactly the same, but good enough to fool "not --crash".
37 if retcode > 128:
38   os.kill(os.getpid(), signal.SIGABRT)
39 sys.exit(retcode)