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

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

Issue 1476723003: [pylib/devil] Create devil.android.base_tool and derive valgrind_tools classes from it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address John's comment Created 5 years 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/forwarder.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 """
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.
8
9 The interface is intended to be used as follows.
10
11 1. For tests that simply run a native process (i.e. no activity is spawned):
12
13 Call tool.CopyFiles(device).
14 Prepend test command line with tool.GetTestWrapper().
15
16 2. For tests that spawn an activity:
17
18 Call tool.CopyFiles(device).
19 Call tool.SetupEnvironment().
20 Run the test as usual.
21 Call tool.CleanUpEnvironment().
22 """
23 # pylint: disable=R0201 5 # pylint: disable=R0201
24 6
25 import glob 7 import glob
26 import logging 8 import logging
27 import os.path 9 import os.path
28 import subprocess 10 import subprocess
29 import sys 11 import sys
30 12
31 from devil.android import device_errors 13 from devil.android import device_errors
14 from devil.android.valgrind_tools import base_tool
32 from pylib.constants import DIR_SOURCE_ROOT 15 from pylib.constants import DIR_SOURCE_ROOT
33 16
34 17
35 def SetChromeTimeoutScale(device, scale): 18 def SetChromeTimeoutScale(device, scale):
36 """Sets the timeout scale in /data/local/tmp/chrome_timeout_scale to scale.""" 19 """Sets the timeout scale in /data/local/tmp/chrome_timeout_scale to scale."""
37 path = '/data/local/tmp/chrome_timeout_scale' 20 path = '/data/local/tmp/chrome_timeout_scale'
38 if not scale or scale == 1.0: 21 if not scale or scale == 1.0:
39 # Delete if scale is None/0.0/1.0 since the default timeout scale is 1.0 22 # Delete if scale is None/0.0/1.0 since the default timeout scale is 1.0
40 device.RunShellCommand('rm %s' % path) 23 device.RunShellCommand('rm %s' % path)
41 else: 24 else:
42 device.WriteFile(path, '%f' % scale, as_root=True) 25 device.WriteFile(path, '%f' % scale, as_root=True)
43 26
44 27
45 class BaseTool(object):
46 """A tool that does nothing."""
47 28
48 def __init__(self): 29 class AddressSanitizerTool(base_tool.BaseTool):
49 """Does nothing."""
50 pass
51
52 def GetTestWrapper(self):
53 """Returns a string that is to be prepended to the test command line."""
54 return ''
55
56 def GetUtilWrapper(self):
57 """Returns the wrapper name for the utilities.
58
59 Returns:
60 A string that is to be prepended to the command line of utility
61 processes (forwarder, etc.).
62 """
63 return ''
64
65 @classmethod
66 def CopyFiles(cls, device):
67 """Copies tool-specific files to the device, create directories, etc."""
68 pass
69
70 def SetupEnvironment(self):
71 """Sets up the system environment for a test.
72
73 This is a good place to set system properties.
74 """
75 pass
76
77 def CleanUpEnvironment(self):
78 """Cleans up environment."""
79 pass
80
81 def GetTimeoutScale(self):
82 """Returns a multiplier that should be applied to timeout values."""
83 return 1.0
84
85 def NeedsDebugInfo(self):
86 """Whether this tool requires debug info.
87
88 Returns:
89 True if this tool can not work with stripped binaries.
90 """
91 return False
92
93
94 class AddressSanitizerTool(BaseTool):
95 """AddressSanitizer tool.""" 30 """AddressSanitizer tool."""
96 31
97 WRAPPER_NAME = '/system/bin/asanwrapper' 32 WRAPPER_NAME = '/system/bin/asanwrapper'
98 # Disable memcmp overlap check.There are blobs (gl drivers) 33 # Disable memcmp overlap check.There are blobs (gl drivers)
99 # on some android devices that use memcmp on overlapping regions, 34 # on some android devices that use memcmp on overlapping regions,
100 # nothing we can do about that. 35 # nothing we can do about that.
101 EXTRA_OPTIONS = 'strict_memcmp=0,use_sigaltstack=1' 36 EXTRA_OPTIONS = 'strict_memcmp=0,use_sigaltstack=1'
102 37
103 def __init__(self, device): 38 def __init__(self, device):
104 super(AddressSanitizerTool, self).__init__() 39 super(AddressSanitizerTool, self).__init__()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 SetChromeTimeoutScale(self._device, self.GetTimeoutScale()) 78 SetChromeTimeoutScale(self._device, self.GetTimeoutScale())
144 79
145 def CleanUpEnvironment(self): 80 def CleanUpEnvironment(self):
146 SetChromeTimeoutScale(self._device, None) 81 SetChromeTimeoutScale(self._device, None)
147 82
148 def GetTimeoutScale(self): 83 def GetTimeoutScale(self):
149 # Very slow startup. 84 # Very slow startup.
150 return 20.0 85 return 20.0
151 86
152 87
153 class ValgrindTool(BaseTool): 88 class ValgrindTool(base_tool.BaseTool):
154 """Base abstract class for Valgrind tools.""" 89 """Base abstract class for Valgrind tools."""
155 90
156 VG_DIR = '/data/local/tmp/valgrind' 91 VG_DIR = '/data/local/tmp/valgrind'
157 VGLOGS_DIR = '/data/local/tmp/vglogs' 92 VGLOGS_DIR = '/data/local/tmp/vglogs'
158 93
159 def __init__(self, device): 94 def __init__(self, device):
160 super(ValgrindTool, self).__init__() 95 super(ValgrindTool, self).__init__()
161 self._device = device 96 self._device = device
162 # exactly 31 chars, SystemProperties::PROP_NAME_MAX 97 # exactly 31 chars, SystemProperties::PROP_NAME_MAX
163 self._wrap_properties = ['wrap.com.google.android.apps.ch', 98 self._wrap_properties = ['wrap.com.google.android.apps.ch',
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 def CreateTool(tool_name, device): 198 def CreateTool(tool_name, device):
264 """Creates a tool with the specified tool name. 199 """Creates a tool with the specified tool name.
265 200
266 Args: 201 Args:
267 tool_name: Name of the tool to create. 202 tool_name: Name of the tool to create.
268 device: A DeviceUtils instance. 203 device: A DeviceUtils instance.
269 Returns: 204 Returns:
270 A tool for the specified tool_name. 205 A tool for the specified tool_name.
271 """ 206 """
272 if not tool_name: 207 if not tool_name:
273 return BaseTool() 208 return base_tool.BaseTool()
274 209
275 ctor = TOOL_REGISTRY.get(tool_name) 210 ctor = TOOL_REGISTRY.get(tool_name)
276 if ctor: 211 if ctor:
277 return ctor(device) 212 return ctor(device)
278 else: 213 else:
279 print 'Unknown tool %s, available tools: %s' % ( 214 print 'Unknown tool %s, available tools: %s' % (
280 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) 215 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys())))
281 sys.exit(1) 216 sys.exit(1)
282 217
283 def PushFilesForTool(tool_name, device): 218 def PushFilesForTool(tool_name, device):
284 """Pushes the files required for |tool_name| to |device|. 219 """Pushes the files required for |tool_name| to |device|.
285 220
286 Args: 221 Args:
287 tool_name: Name of the tool to create. 222 tool_name: Name of the tool to create.
288 device: A DeviceUtils instance. 223 device: A DeviceUtils instance.
289 """ 224 """
290 if not tool_name: 225 if not tool_name:
291 return 226 return
292 227
293 clazz = TOOL_REGISTRY.get(tool_name) 228 clazz = TOOL_REGISTRY.get(tool_name)
294 if clazz: 229 if clazz:
295 clazz.CopyFiles(device) 230 clazz.CopyFiles(device)
296 else: 231 else:
297 print 'Unknown tool %s, available tools: %s' % ( 232 print 'Unknown tool %s, available tools: %s' % (
298 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) 233 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys())))
299 sys.exit(1) 234 sys.exit(1)
300 235
OLDNEW
« no previous file with comments | « build/android/pylib/forwarder.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698