| 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 # pylint: disable=R0201 |
| 23 | 24 |
| 24 import os.path | 25 import os.path |
| 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 pylib.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: |
| 35 # Delete if scale is None/0.0/1.0 since the default timeout scale is 1.0 | 36 # Delete if scale is None/0.0/1.0 since the default timeout scale is 1.0 |
| 36 adb.RunShellCommand('rm %s' % path) | 37 adb.RunShellCommand('rm %s' % path) |
| 37 else: | 38 else: |
| 38 adb.SetProtectedFileContents(path, '%f' % scale) | 39 adb.SetProtectedFileContents(path, '%f' % scale) |
| 39 | 40 |
| 40 | 41 |
| 41 class BaseTool(object): | 42 class BaseTool(object): |
| 42 """A tool that does nothing.""" | 43 """A tool that does nothing.""" |
| 43 | 44 |
| 45 def __init__(self): |
| 46 """Does nothing.""" |
| 47 pass |
| 48 |
| 44 def GetTestWrapper(self): | 49 def GetTestWrapper(self): |
| 45 """Returns a string that is to be prepended to the test command line.""" | 50 """Returns a string that is to be prepended to the test command line.""" |
| 46 return '' | 51 return '' |
| 47 | 52 |
| 48 def GetUtilWrapper(self): | 53 def GetUtilWrapper(self): |
| 49 """Returns the wrapper name for the utilities. | 54 """Returns the wrapper name for the utilities. |
| 50 | 55 |
| 51 Returns: | 56 Returns: |
| 52 A string that is to be prepended to the command line of utility | 57 A string that is to be prepended to the command line of utility |
| 53 processes (forwarder, etc.). | 58 processes (forwarder, etc.). |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 return False | 87 return False |
| 83 | 88 |
| 84 | 89 |
| 85 class AddressSanitizerTool(BaseTool): | 90 class AddressSanitizerTool(BaseTool): |
| 86 """AddressSanitizer tool.""" | 91 """AddressSanitizer tool.""" |
| 87 | 92 |
| 88 TMP_DIR = '/data/local/tmp/asan' | 93 TMP_DIR = '/data/local/tmp/asan' |
| 89 WRAPPER_NAME = 'asanwrapper.sh' | 94 WRAPPER_NAME = 'asanwrapper.sh' |
| 90 | 95 |
| 91 def __init__(self, adb): | 96 def __init__(self, adb): |
| 97 super(AddressSanitizerTool, self).__init__() |
| 92 self._adb = adb | 98 self._adb = adb |
| 93 self._wrap_properties = ['wrap.com.google.android.apps.ch', | 99 self._wrap_properties = ['wrap.com.google.android.apps.ch', |
| 94 'wrap.org.chromium.native_test', | 100 'wrap.org.chromium.native_test', |
| 95 'wrap.org.chromium.content_shell', | 101 'wrap.org.chromium.content_shell', |
| 96 'wrap.org.chromium.chrome.testsh', | 102 'wrap.org.chromium.chrome.testsh', |
| 97 'wrap.org.chromium.android_webvi'] | 103 'wrap.org.chromium.android_webvi'] |
| 98 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan. | 104 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan. |
| 99 # This is required because ASan is a compiler-based tool, and md5sum | 105 # This is required because ASan is a compiler-based tool, and md5sum |
| 100 # includes instrumented code from base. | 106 # includes instrumented code from base. |
| 101 adb.SetUtilWrapper(self.GetUtilWrapper()) | 107 adb.SetUtilWrapper(self.GetUtilWrapper()) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return 20.0 | 146 return 20.0 |
| 141 | 147 |
| 142 | 148 |
| 143 class ValgrindTool(BaseTool): | 149 class ValgrindTool(BaseTool): |
| 144 """Base abstract class for Valgrind tools.""" | 150 """Base abstract class for Valgrind tools.""" |
| 145 | 151 |
| 146 VG_DIR = '/data/local/tmp/valgrind' | 152 VG_DIR = '/data/local/tmp/valgrind' |
| 147 VGLOGS_DIR = '/data/local/tmp/vglogs' | 153 VGLOGS_DIR = '/data/local/tmp/vglogs' |
| 148 | 154 |
| 149 def __init__(self, adb): | 155 def __init__(self, adb): |
| 156 super(ValgrindTool, self).__init__() |
| 150 self._adb = adb | 157 self._adb = adb |
| 151 # exactly 31 chars, SystemProperties::PROP_NAME_MAX | 158 # exactly 31 chars, SystemProperties::PROP_NAME_MAX |
| 152 self._wrap_properties = ['wrap.com.google.android.apps.ch', | 159 self._wrap_properties = ['wrap.com.google.android.apps.ch', |
| 153 'wrap.org.chromium.native_test'] | 160 'wrap.org.chromium.native_test'] |
| 154 | 161 |
| 155 def CopyFiles(self): | 162 def CopyFiles(self): |
| 156 """Copies Valgrind tools to the device.""" | 163 """Copies Valgrind tools to the device.""" |
| 157 self._adb.RunShellCommand('rm -r %s; mkdir %s' % | 164 self._adb.RunShellCommand('rm -r %s; mkdir %s' % |
| 158 (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR)) | 165 (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR)) |
| 159 self._adb.RunShellCommand('rm -r %s; mkdir %s' % | 166 self._adb.RunShellCommand('rm -r %s; mkdir %s' % |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 def GetTestWrapper(self): | 237 def GetTestWrapper(self): |
| 231 """Returns a string that is to be prepended to the test command line.""" | 238 """Returns a string that is to be prepended to the test command line.""" |
| 232 return ValgrindTool.VG_DIR + '/' + 'vg-chrome-wrapper-tsan.sh' | 239 return ValgrindTool.VG_DIR + '/' + 'vg-chrome-wrapper-tsan.sh' |
| 233 | 240 |
| 234 def GetTimeoutScale(self): | 241 def GetTimeoutScale(self): |
| 235 """Returns a multiplier that should be applied to timeout values.""" | 242 """Returns a multiplier that should be applied to timeout values.""" |
| 236 return 30.0 | 243 return 30.0 |
| 237 | 244 |
| 238 | 245 |
| 239 TOOL_REGISTRY = { | 246 TOOL_REGISTRY = { |
| 240 'memcheck': lambda x: MemcheckTool(x), | 247 'memcheck': MemcheckTool, |
| 241 'memcheck-renderer': lambda x: MemcheckTool(x), | 248 'memcheck-renderer': MemcheckTool, |
| 242 'tsan': lambda x: TSanTool(x), | 249 'tsan': TSanTool, |
| 243 'tsan-renderer': lambda x: TSanTool(x), | 250 'tsan-renderer': TSanTool, |
| 244 'asan': lambda x: AddressSanitizerTool(x), | 251 'asan': AddressSanitizerTool, |
| 245 } | 252 } |
| 246 | 253 |
| 247 | 254 |
| 248 def CreateTool(tool_name, adb): | 255 def CreateTool(tool_name, adb): |
| 249 """Creates a tool with the specified tool name. | 256 """Creates a tool with the specified tool name. |
| 250 | 257 |
| 251 Args: | 258 Args: |
| 252 tool_name: Name of the tool to create. | 259 tool_name: Name of the tool to create. |
| 253 adb: ADB interface the tool will use. | 260 adb: ADB interface the tool will use. |
| 254 Returns: | 261 Returns: |
| 255 A tool for the specified tool_name. | 262 A tool for the specified tool_name. |
| 256 """ | 263 """ |
| 257 if not tool_name: | 264 if not tool_name: |
| 258 return BaseTool() | 265 return BaseTool() |
| 259 | 266 |
| 260 ctor = TOOL_REGISTRY.get(tool_name) | 267 ctor = TOOL_REGISTRY.get(tool_name) |
| 261 if ctor: | 268 if ctor: |
| 262 return ctor(adb) | 269 return ctor(adb) |
| 263 else: | 270 else: |
| 264 print 'Unknown tool %s, available tools: %s' % ( | 271 print 'Unknown tool %s, available tools: %s' % ( |
| 265 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) | 272 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) |
| 266 sys.exit(1) | 273 sys.exit(1) |
| OLD | NEW |