Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1114)

Side by Side Diff: build/android/pylib/valgrind_tools.py

Issue 651923002: [Android] Push gtest deps in gtest/setup.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/pylib/instrumentation/test_runner.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(device).
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(device).
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 # pylint: disable=R0201 23 # pylint: disable=R0201
24 24
25 import glob 25 import glob
26 import logging 26 import logging
27 import os.path 27 import os.path
28 import subprocess 28 import subprocess
(...skipping 26 matching lines...) Expand all
55 55
56 def GetUtilWrapper(self): 56 def GetUtilWrapper(self):
57 """Returns the wrapper name for the utilities. 57 """Returns the wrapper name for the utilities.
58 58
59 Returns: 59 Returns:
60 A string that is to be prepended to the command line of utility 60 A string that is to be prepended to the command line of utility
61 processes (forwarder, etc.). 61 processes (forwarder, etc.).
62 """ 62 """
63 return '' 63 return ''
64 64
65 def CopyFiles(self): 65 @classmethod
66 def CopyFiles(cls, device):
66 """Copies tool-specific files to the device, create directories, etc.""" 67 """Copies tool-specific files to the device, create directories, etc."""
67 pass 68 pass
68 69
69 def SetupEnvironment(self): 70 def SetupEnvironment(self):
70 """Sets up the system environment for a test. 71 """Sets up the system environment for a test.
71 72
72 This is a good place to set system properties. 73 This is a good place to set system properties.
73 """ 74 """
74 pass 75 pass
75 76
(...skipping 23 matching lines...) Expand all
99 # nothing we can do about that. 100 # nothing we can do about that.
100 EXTRA_OPTIONS = 'strict_memcmp=0,use_sigaltstack=1' 101 EXTRA_OPTIONS = 'strict_memcmp=0,use_sigaltstack=1'
101 102
102 def __init__(self, device): 103 def __init__(self, device):
103 super(AddressSanitizerTool, self).__init__() 104 super(AddressSanitizerTool, self).__init__()
104 self._device = device 105 self._device = device
105 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan. 106 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan.
106 # This is required because ASan is a compiler-based tool, and md5sum 107 # This is required because ASan is a compiler-based tool, and md5sum
107 # includes instrumented code from base. 108 # includes instrumented code from base.
108 device.old_interface.SetUtilWrapper(self.GetUtilWrapper()) 109 device.old_interface.SetUtilWrapper(self.GetUtilWrapper())
110
111 @classmethod
112 def CopyFiles(cls, device):
113 """Copies ASan tools to the device."""
109 libs = glob.glob(os.path.join(DIR_SOURCE_ROOT, 114 libs = glob.glob(os.path.join(DIR_SOURCE_ROOT,
110 'third_party/llvm-build/Release+Asserts/', 115 'third_party/llvm-build/Release+Asserts/',
111 'lib/clang/*/lib/linux/', 116 'lib/clang/*/lib/linux/',
112 'libclang_rt.asan-arm-android.so')) 117 'libclang_rt.asan-arm-android.so'))
113 assert len(libs) == 1 118 assert len(libs) == 1
114 self._lib = libs[0]
115
116 def CopyFiles(self):
117 """Copies ASan tools to the device."""
118 subprocess.call([os.path.join(DIR_SOURCE_ROOT, 119 subprocess.call([os.path.join(DIR_SOURCE_ROOT,
119 'tools/android/asan/asan_device_setup.sh'), 120 'tools/android/asan/asan_device_setup.sh'),
120 '--device', str(self._device), 121 '--device', str(device),
121 '--lib', self._lib, 122 '--lib', libs[0],
122 '--extra-options', AddressSanitizerTool.EXTRA_OPTIONS]) 123 '--extra-options', AddressSanitizerTool.EXTRA_OPTIONS])
123 self._device.WaitUntilFullyBooted() 124 device.WaitUntilFullyBooted()
124 125
125 def GetTestWrapper(self): 126 def GetTestWrapper(self):
126 return AddressSanitizerTool.WRAPPER_NAME 127 return AddressSanitizerTool.WRAPPER_NAME
127 128
128 def GetUtilWrapper(self): 129 def GetUtilWrapper(self):
129 """Returns the wrapper for utilities, such as forwarder. 130 """Returns the wrapper for utilities, such as forwarder.
130 131
131 AddressSanitizer wrapper must be added to all instrumented binaries, 132 AddressSanitizer wrapper must be added to all instrumented binaries,
132 including forwarder and the like. This can be removed if such binaries 133 including forwarder and the like. This can be removed if such binaries
133 were built without instrumentation. """ 134 were built without instrumentation. """
(...skipping 23 matching lines...) Expand all
157 VG_DIR = '/data/local/tmp/valgrind' 158 VG_DIR = '/data/local/tmp/valgrind'
158 VGLOGS_DIR = '/data/local/tmp/vglogs' 159 VGLOGS_DIR = '/data/local/tmp/vglogs'
159 160
160 def __init__(self, device): 161 def __init__(self, device):
161 super(ValgrindTool, self).__init__() 162 super(ValgrindTool, self).__init__()
162 self._device = device 163 self._device = device
163 # exactly 31 chars, SystemProperties::PROP_NAME_MAX 164 # exactly 31 chars, SystemProperties::PROP_NAME_MAX
164 self._wrap_properties = ['wrap.com.google.android.apps.ch', 165 self._wrap_properties = ['wrap.com.google.android.apps.ch',
165 'wrap.org.chromium.native_test'] 166 'wrap.org.chromium.native_test']
166 167
167 def CopyFiles(self): 168 @classmethod
169 def CopyFiles(cls, device):
168 """Copies Valgrind tools to the device.""" 170 """Copies Valgrind tools to the device."""
169 self._device.RunShellCommand( 171 device.RunShellCommand(
170 'rm -r %s; mkdir %s' % (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR)) 172 'rm -r %s; mkdir %s' % (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR))
171 self._device.RunShellCommand( 173 device.RunShellCommand(
172 'rm -r %s; mkdir %s' % (ValgrindTool.VGLOGS_DIR, 174 'rm -r %s; mkdir %s' % (ValgrindTool.VGLOGS_DIR,
173 ValgrindTool.VGLOGS_DIR)) 175 ValgrindTool.VGLOGS_DIR))
174 files = self.GetFilesForTool() 176 files = cls.GetFilesForTool()
175 self._device.PushChangedFiles( 177 device.PushChangedFiles(
176 [((os.path.join(DIR_SOURCE_ROOT, f), 178 [((os.path.join(DIR_SOURCE_ROOT, f),
177 os.path.join(ValgrindTool.VG_DIR, os.path.basename(f))) 179 os.path.join(ValgrindTool.VG_DIR, os.path.basename(f)))
178 for f in files)]) 180 for f in files)])
179 181
180 def SetupEnvironment(self): 182 def SetupEnvironment(self):
181 """Sets up device environment.""" 183 """Sets up device environment."""
182 self._device.RunShellCommand('chmod 777 /data/local/tmp') 184 self._device.RunShellCommand('chmod 777 /data/local/tmp')
183 self._device.RunShellCommand('setenforce 0') 185 self._device.RunShellCommand('setenforce 0')
184 for prop in self._wrap_properties: 186 for prop in self._wrap_properties:
185 self._device.RunShellCommand( 187 self._device.RunShellCommand(
186 'setprop %s "logwrapper %s"' % (prop, self.GetTestWrapper())) 188 'setprop %s "logwrapper %s"' % (prop, self.GetTestWrapper()))
187 SetChromeTimeoutScale(self._device, self.GetTimeoutScale()) 189 SetChromeTimeoutScale(self._device, self.GetTimeoutScale())
188 190
189 def CleanUpEnvironment(self): 191 def CleanUpEnvironment(self):
190 """Cleans up device environment.""" 192 """Cleans up device environment."""
191 for prop in self._wrap_properties: 193 for prop in self._wrap_properties:
192 self._device.RunShellCommand('setprop %s ""' % (prop,)) 194 self._device.RunShellCommand('setprop %s ""' % (prop,))
193 SetChromeTimeoutScale(self._device, None) 195 SetChromeTimeoutScale(self._device, None)
194 196
195 def GetFilesForTool(self): 197 @staticmethod
198 def GetFilesForTool():
196 """Returns a list of file names for the tool.""" 199 """Returns a list of file names for the tool."""
197 raise NotImplementedError() 200 raise NotImplementedError()
198 201
199 def NeedsDebugInfo(self): 202 def NeedsDebugInfo(self):
200 """Whether this tool requires debug info. 203 """Whether this tool requires debug info.
201 204
202 Returns: 205 Returns:
203 True if this tool can not work with stripped binaries. 206 True if this tool can not work with stripped binaries.
204 """ 207 """
205 return True 208 return True
206 209
207 210
208 class MemcheckTool(ValgrindTool): 211 class MemcheckTool(ValgrindTool):
209 """Memcheck tool.""" 212 """Memcheck tool."""
210 213
211 def __init__(self, device): 214 def __init__(self, device):
212 super(MemcheckTool, self).__init__(device) 215 super(MemcheckTool, self).__init__(device)
213 216
214 def GetFilesForTool(self): 217 @staticmethod
218 def GetFilesForTool():
215 """Returns a list of file names for the tool.""" 219 """Returns a list of file names for the tool."""
216 return ['tools/valgrind/android/vg-chrome-wrapper.sh', 220 return ['tools/valgrind/android/vg-chrome-wrapper.sh',
217 'tools/valgrind/memcheck/suppressions.txt', 221 'tools/valgrind/memcheck/suppressions.txt',
218 'tools/valgrind/memcheck/suppressions_android.txt'] 222 'tools/valgrind/memcheck/suppressions_android.txt']
219 223
220 def GetTestWrapper(self): 224 def GetTestWrapper(self):
221 """Returns a string that is to be prepended to the test command line.""" 225 """Returns a string that is to be prepended to the test command line."""
222 return ValgrindTool.VG_DIR + '/' + 'vg-chrome-wrapper.sh' 226 return ValgrindTool.VG_DIR + '/' + 'vg-chrome-wrapper.sh'
223 227
224 def GetTimeoutScale(self): 228 def GetTimeoutScale(self):
225 """Returns a multiplier that should be applied to timeout values.""" 229 """Returns a multiplier that should be applied to timeout values."""
226 return 30 230 return 30
227 231
228 232
229 class TSanTool(ValgrindTool): 233 class TSanTool(ValgrindTool):
230 """ThreadSanitizer tool. See http://code.google.com/p/data-race-test .""" 234 """ThreadSanitizer tool. See http://code.google.com/p/data-race-test ."""
231 235
232 def __init__(self, device): 236 def __init__(self, device):
233 super(TSanTool, self).__init__(device) 237 super(TSanTool, self).__init__(device)
234 238
235 def GetFilesForTool(self): 239 @staticmethod
240 def GetFilesForTool():
236 """Returns a list of file names for the tool.""" 241 """Returns a list of file names for the tool."""
237 return ['tools/valgrind/android/vg-chrome-wrapper-tsan.sh', 242 return ['tools/valgrind/android/vg-chrome-wrapper-tsan.sh',
238 'tools/valgrind/tsan/suppressions.txt', 243 'tools/valgrind/tsan/suppressions.txt',
239 'tools/valgrind/tsan/suppressions_android.txt', 244 'tools/valgrind/tsan/suppressions_android.txt',
240 'tools/valgrind/tsan/ignores.txt'] 245 'tools/valgrind/tsan/ignores.txt']
241 246
242 def GetTestWrapper(self): 247 def GetTestWrapper(self):
243 """Returns a string that is to be prepended to the test command line.""" 248 """Returns a string that is to be prepended to the test command line."""
244 return ValgrindTool.VG_DIR + '/' + 'vg-chrome-wrapper-tsan.sh' 249 return ValgrindTool.VG_DIR + '/' + 'vg-chrome-wrapper-tsan.sh'
245 250
(...skipping 23 matching lines...) Expand all
269 if not tool_name: 274 if not tool_name:
270 return BaseTool() 275 return BaseTool()
271 276
272 ctor = TOOL_REGISTRY.get(tool_name) 277 ctor = TOOL_REGISTRY.get(tool_name)
273 if ctor: 278 if ctor:
274 return ctor(device) 279 return ctor(device)
275 else: 280 else:
276 print 'Unknown tool %s, available tools: %s' % ( 281 print 'Unknown tool %s, available tools: %s' % (
277 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) 282 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys())))
278 sys.exit(1) 283 sys.exit(1)
284
285 def PushFilesForTool(tool_name, device):
286 """Pushes the files required for |tool_name| to |device|.
287
288 Args:
289 tool_name: Name of the tool to create.
290 device: A DeviceUtils instance.
291 """
292 if not tool_name:
293 return
294
295 clazz = TOOL_REGISTRY.get(tool_name)
296 if clazz:
297 clazz.CopyFiles(device)
298 else:
299 print 'Unknown tool %s, available tools: %s' % (
300 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys())))
301 sys.exit(1)
302
OLDNEW
« no previous file with comments | « build/android/pylib/instrumentation/test_runner.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698