OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 Classes in this file define additional actions that need to be taken to run a | 6 Classes in this file define additional actions that need to be taken to run a |
7 test under some kind of runtime error detection tool. | 7 test under some kind of runtime error detection tool. |
8 | 8 |
9 The interface is intended to be used as follows. | 9 The interface is intended to be used as follows. |
10 | 10 |
11 1. For tests that simply run a native process (i.e. no activity is spawned): | 11 1. For tests that simply run a native process (i.e. no activity is spawned): |
12 | 12 |
13 Call tool.CopyFiles(). | 13 Call tool.CopyFiles(). |
14 Prepend test command line with tool.GetTestWrapper(). | 14 Prepend test command line with tool.GetTestWrapper(). |
15 | 15 |
16 2. For tests that spawn an activity: | 16 2. For tests that spawn an activity: |
17 | 17 |
18 Call tool.CopyFiles(). | 18 Call tool.CopyFiles(). |
19 Call tool.SetupEnvironment(). | 19 Call tool.SetupEnvironment(). |
20 Run the test as usual. | 20 Run the test as usual. |
21 Call tool.CleanUpEnvironment(). | 21 Call tool.CleanUpEnvironment(). |
22 """ | 22 """ |
23 | 23 |
24 import os.path | 24 import os.path |
| 25 import subprocess |
25 import sys | 26 import sys |
26 from glob import glob | 27 from glob import glob |
27 | 28 |
28 from constants import DIR_SOURCE_ROOT | 29 from constants import DIR_SOURCE_ROOT |
29 | 30 |
30 | 31 |
31 def SetChromeTimeoutScale(adb, scale): | 32 def SetChromeTimeoutScale(adb, scale): |
32 """Sets the timeout scale in /data/local/tmp/chrome_timeout_scale to scale.""" | 33 """Sets the timeout scale in /data/local/tmp/chrome_timeout_scale to scale.""" |
33 path = '/data/local/tmp/chrome_timeout_scale' | 34 path = '/data/local/tmp/chrome_timeout_scale' |
34 if not scale or scale == 1.0: | 35 if not scale or scale == 1.0: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 79 |
79 Returns: | 80 Returns: |
80 True if this tool can not work with stripped binaries. | 81 True if this tool can not work with stripped binaries. |
81 """ | 82 """ |
82 return False | 83 return False |
83 | 84 |
84 | 85 |
85 class AddressSanitizerTool(BaseTool): | 86 class AddressSanitizerTool(BaseTool): |
86 """AddressSanitizer tool.""" | 87 """AddressSanitizer tool.""" |
87 | 88 |
88 TMP_DIR = '/data/local/tmp/asan' | 89 WRAPPER_NAME = '/system/bin/asanwrapper' |
89 WRAPPER_NAME = 'asanwrapper.sh' | 90 EXTRA_OPTIONS = 'allocator_may_return_null=1,strict_memcmp=0' |
90 | 91 |
91 def __init__(self, adb): | 92 def __init__(self, adb): |
92 self._adb = adb | 93 self._adb = adb |
93 self._wrap_properties = ['wrap.com.google.android.apps.ch', | |
94 'wrap.org.chromium.native_test', | |
95 'wrap.org.chromium.content_shell', | |
96 'wrap.org.chromium.chrome.testsh', | |
97 'wrap.org.chromium.android_webvi'] | |
98 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan. | 94 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan. |
99 # This is required because ASan is a compiler-based tool, and md5sum | 95 # This is required because ASan is a compiler-based tool, and md5sum |
100 # includes instrumented code from base. | 96 # includes instrumented code from base. |
101 adb.SetUtilWrapper(self.GetUtilWrapper()) | 97 adb.SetUtilWrapper(self.GetUtilWrapper()) |
102 | 98 |
103 def CopyFiles(self): | 99 def CopyFiles(self): |
104 """Copies ASan tools to the device.""" | 100 """Copies ASan tools to the device.""" |
105 files = (['tools/android/asan/asanwrapper.sh'] + | 101 subprocess.call([os.path.join(DIR_SOURCE_ROOT, |
106 glob('third_party/llvm-build/Release+Asserts/lib/clang/*/lib/' | 102 'tools/android/asan/asan_device_setup.sh'), |
107 'linux/libclang_rt.asan-arm-android.so')) | 103 '--device', self._adb.GetDevice(), |
108 for f in files: | 104 '--extra-options', AddressSanitizerTool.EXTRA_OPTIONS]) |
109 self._adb.PushIfNeeded(os.path.join(DIR_SOURCE_ROOT, f), | 105 self._adb.WaitForDevicePm() |
110 os.path.join(AddressSanitizerTool.TMP_DIR, | |
111 os.path.basename(f))) | |
112 | 106 |
113 def GetTestWrapper(self): | 107 def GetTestWrapper(self): |
114 return os.path.join(AddressSanitizerTool.TMP_DIR, | 108 return AddressSanitizerTool.WRAPPER_NAME |
115 AddressSanitizerTool.WRAPPER_NAME) | |
116 | 109 |
117 def GetUtilWrapper(self): | 110 def GetUtilWrapper(self): |
118 """Returns the wrapper for utilities, such as forwarder. | 111 """Returns the wrapper for utilities, such as forwarder. |
119 | 112 |
120 AddressSanitizer wrapper must be added to all instrumented binaries, | 113 AddressSanitizer wrapper must be added to all instrumented binaries, |
121 including forwarder and the like. This can be removed if such binaries | 114 including forwarder and the like. This can be removed if such binaries |
122 were built without instrumentation. """ | 115 were built without instrumentation. """ |
123 return self.GetTestWrapper() | 116 return self.GetTestWrapper() |
124 | 117 |
125 def SetupEnvironment(self): | 118 def SetupEnvironment(self): |
126 self._adb.EnableAdbRoot() | 119 self._adb.EnableAdbRoot() |
127 self._adb.RunShellCommand('setenforce 0') | |
128 for prop in self._wrap_properties: | |
129 self._adb.RunShellCommand('setprop %s "logwrapper %s"' % ( | |
130 prop, self.GetTestWrapper())) | |
131 SetChromeTimeoutScale(self._adb, self.GetTimeoutScale()) | 120 SetChromeTimeoutScale(self._adb, self.GetTimeoutScale()) |
132 | 121 |
133 def CleanUpEnvironment(self): | 122 def CleanUpEnvironment(self): |
134 for prop in self._wrap_properties: | |
135 self._adb.RunShellCommand('setprop %s ""' % (prop,)) | |
136 SetChromeTimeoutScale(self._adb, None) | 123 SetChromeTimeoutScale(self._adb, None) |
137 | 124 |
138 def GetTimeoutScale(self): | 125 def GetTimeoutScale(self): |
139 # Very slow startup. | 126 # Very slow startup. |
140 return 20.0 | 127 return 20.0 |
141 | 128 |
142 | 129 |
143 class ValgrindTool(BaseTool): | 130 class ValgrindTool(BaseTool): |
144 """Base abstract class for Valgrind tools.""" | 131 """Base abstract class for Valgrind tools.""" |
145 | 132 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if not tool_name: | 244 if not tool_name: |
258 return BaseTool() | 245 return BaseTool() |
259 | 246 |
260 ctor = TOOL_REGISTRY.get(tool_name) | 247 ctor = TOOL_REGISTRY.get(tool_name) |
261 if ctor: | 248 if ctor: |
262 return ctor(adb) | 249 return ctor(adb) |
263 else: | 250 else: |
264 print 'Unknown tool %s, available tools: %s' % ( | 251 print 'Unknown tool %s, available tools: %s' % ( |
265 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) | 252 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) |
266 sys.exit(1) | 253 sys.exit(1) |
OLD | NEW |