aboutsummaryrefslogtreecommitdiff
path: root/test/asan/android_commands
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-01-07 19:55:37 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-01-07 19:55:37 +0000
commitca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (patch)
tree9b19e801150082c33e9152275829a6ce90614b55 /test/asan/android_commands
parent8ef50bf3d1c287b5013c3168de77a462dfce3495 (diff)
downloadsrc-ca9211ecdede9bdedb812b2243a4abdb8dacd1b9.tar.gz
src-ca9211ecdede9bdedb812b2243a4abdb8dacd1b9.zip
Import compiler-rt trunk r224034.vendor/compiler-rt/compiler-rt-r224034
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=276789 svn path=/vendor/compiler-rt/compiler-rt-r224034/; revision=276790; tag=vendor/compiler-rt/compiler-rt-r224034
Diffstat (limited to 'test/asan/android_commands')
-rw-r--r--test/asan/android_commands/android_common.py29
-rwxr-xr-xtest/asan/android_commands/android_compile.py36
-rwxr-xr-xtest/asan/android_commands/android_run.py34
3 files changed, 99 insertions, 0 deletions
diff --git a/test/asan/android_commands/android_common.py b/test/asan/android_commands/android_common.py
new file mode 100644
index 000000000000..43ac7b48d770
--- /dev/null
+++ b/test/asan/android_commands/android_common.py
@@ -0,0 +1,29 @@
+import os, subprocess, tempfile
+import time
+
+ANDROID_TMPDIR = '/data/local/tmp/Output'
+ADB = os.environ.get('ADB', 'adb')
+
+verbose = False
+if os.environ.get('ANDROID_RUN_VERBOSE') == '1':
+ verbose = True
+
+def adb(args):
+ if verbose:
+ print args
+ devnull = open(os.devnull, 'w')
+ return subprocess.call([ADB] + args, stdout=devnull, stderr=subprocess.STDOUT)
+
+def pull_from_device(path):
+ tmp = tempfile.mktemp()
+ adb(['pull', path, tmp])
+ text = open(tmp, 'r').read()
+ os.unlink(tmp)
+ return text
+
+def push_to_device(path):
+ # Workaround for https://code.google.com/p/android/issues/detail?id=65857
+ dst_path = os.path.join(ANDROID_TMPDIR, os.path.basename(path))
+ tmp_path = dst_path + '.push'
+ adb(['push', path, tmp_path])
+ adb(['shell', 'cp "%s" "%s" 2>&1' % (tmp_path, dst_path)])
diff --git a/test/asan/android_commands/android_compile.py b/test/asan/android_commands/android_compile.py
new file mode 100755
index 000000000000..4b880886b0c1
--- /dev/null
+++ b/test/asan/android_commands/android_compile.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+import os, sys, subprocess
+from android_common import *
+
+
+here = os.path.abspath(os.path.dirname(sys.argv[0]))
+android_run = os.path.join(here, 'android_run.py')
+
+output = None
+output_type = 'executable'
+
+args = sys.argv[1:]
+while args:
+ arg = args.pop(0)
+ if arg == '-shared':
+ output_type = 'shared'
+ elif arg == '-c':
+ output_type = 'object'
+ elif arg == '-o':
+ output = args.pop(0)
+
+if output == None:
+ print "No output file name!"
+ sys.exit(1)
+
+ret = subprocess.call(sys.argv[1:])
+if ret != 0:
+ sys.exit(ret)
+
+if output_type in ['executable', 'shared']:
+ push_to_device(output)
+
+if output_type == 'executable':
+ os.rename(output, output + '.real')
+ os.symlink(android_run, output)
diff --git a/test/asan/android_commands/android_run.py b/test/asan/android_commands/android_run.py
new file mode 100755
index 000000000000..7f8c612a0cf0
--- /dev/null
+++ b/test/asan/android_commands/android_run.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import os, sys, subprocess, tempfile
+from android_common import *
+
+ANDROID_TMPDIR = '/data/local/tmp/Output'
+
+here = os.path.abspath(os.path.dirname(sys.argv[0]))
+device_binary = os.path.join(ANDROID_TMPDIR, os.path.basename(sys.argv[0]))
+
+def build_env():
+ args = []
+ # Android linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir.
+ args.append('LD_LIBRARY_PATH=%s:%s' %
+ (ANDROID_TMPDIR, os.environ.get('LD_LIBRARY_PATH', '')))
+ for (key, value) in os.environ.items():
+ if key in ['ASAN_OPTIONS']:
+ args.append('%s="%s"' % (key, value))
+ return ' '.join(args)
+
+device_env = build_env()
+device_args = ' '.join(sys.argv[1:]) # FIXME: escape?
+device_stdout = device_binary + '.stdout'
+device_stderr = device_binary + '.stderr'
+device_exitcode = device_binary + '.exitcode'
+ret = adb(['shell', 'cd %s && %s asanwrapper %s %s >%s 2>%s ; echo $? >%s' %
+ (ANDROID_TMPDIR, device_env, device_binary, device_args,
+ device_stdout, device_stderr, device_exitcode)])
+if ret != 0:
+ sys.exit(ret)
+
+sys.stdout.write(pull_from_device(device_stdout))
+sys.stderr.write(pull_from_device(device_stderr))
+sys.exit(int(pull_from_device(device_exitcode)))