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 sys | 25 import sys |
26 from glob import glob | 26 from glob import glob |
27 | 27 |
28 from constants import CHROME_DIR | 28 from constants import DIR_SOURCE_ROOT |
29 | 29 |
30 | 30 |
31 def SetChromeTimeoutScale(adb, scale): | 31 def SetChromeTimeoutScale(adb, scale): |
32 """Sets the timeout scale in /data/local/tmp/chrome_timeout_scale to scale.""" | 32 """Sets the timeout scale in /data/local/tmp/chrome_timeout_scale to scale.""" |
33 path = '/data/local/tmp/chrome_timeout_scale' | 33 path = '/data/local/tmp/chrome_timeout_scale' |
34 if not scale or scale == 1.0: | 34 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 | 35 # Delete if scale is None/0.0/1.0 since the default timeout scale is 1.0 |
36 adb.RunShellCommand('rm %s' % path) | 36 adb.RunShellCommand('rm %s' % path) |
37 else: | 37 else: |
38 adb.SetProtectedFileContents(path, '%f' % scale) | 38 adb.SetProtectedFileContents(path, '%f' % scale) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 # This is required because ASan is a compiler-based tool, and md5sum | 99 # This is required because ASan is a compiler-based tool, and md5sum |
100 # includes instrumented code from base. | 100 # includes instrumented code from base. |
101 adb.SetUtilWrapper(self.GetUtilWrapper()) | 101 adb.SetUtilWrapper(self.GetUtilWrapper()) |
102 | 102 |
103 def CopyFiles(self): | 103 def CopyFiles(self): |
104 """Copies ASan tools to the device.""" | 104 """Copies ASan tools to the device.""" |
105 files = (['tools/android/asan/asanwrapper.sh'] + | 105 files = (['tools/android/asan/asanwrapper.sh'] + |
106 glob('third_party/llvm-build/Release+Asserts/lib/clang/*/lib/' | 106 glob('third_party/llvm-build/Release+Asserts/lib/clang/*/lib/' |
107 'linux/libclang_rt.asan-arm-android.so')) | 107 'linux/libclang_rt.asan-arm-android.so')) |
108 for f in files: | 108 for f in files: |
109 self._adb.PushIfNeeded(os.path.join(CHROME_DIR, f), | 109 self._adb.PushIfNeeded(os.path.join(DIR_SOURCE_ROOT, f), |
110 os.path.join(AddressSanitizerTool.TMP_DIR, | 110 os.path.join(AddressSanitizerTool.TMP_DIR, |
111 os.path.basename(f))) | 111 os.path.basename(f))) |
112 | 112 |
113 def GetTestWrapper(self): | 113 def GetTestWrapper(self): |
114 return os.path.join(AddressSanitizerTool.TMP_DIR, | 114 return os.path.join(AddressSanitizerTool.TMP_DIR, |
115 AddressSanitizerTool.WRAPPER_NAME) | 115 AddressSanitizerTool.WRAPPER_NAME) |
116 | 116 |
117 def GetUtilWrapper(self): | 117 def GetUtilWrapper(self): |
118 """Returns the wrapper for utilities, such as forwarder. | 118 """Returns the wrapper for utilities, such as forwarder. |
119 | 119 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 def CopyFiles(self): | 154 def CopyFiles(self): |
155 """Copies Valgrind tools to the device.""" | 155 """Copies Valgrind tools to the device.""" |
156 self._adb.RunShellCommand('rm -r %s; mkdir %s' % | 156 self._adb.RunShellCommand('rm -r %s; mkdir %s' % |
157 (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR)) | 157 (ValgrindTool.VG_DIR, ValgrindTool.VG_DIR)) |
158 self._adb.RunShellCommand('rm -r %s; mkdir %s' % | 158 self._adb.RunShellCommand('rm -r %s; mkdir %s' % |
159 (ValgrindTool.VGLOGS_DIR, | 159 (ValgrindTool.VGLOGS_DIR, |
160 ValgrindTool.VGLOGS_DIR)) | 160 ValgrindTool.VGLOGS_DIR)) |
161 files = self.GetFilesForTool() | 161 files = self.GetFilesForTool() |
162 for f in files: | 162 for f in files: |
163 self._adb.PushIfNeeded(os.path.join(CHROME_DIR, f), | 163 self._adb.PushIfNeeded(os.path.join(DIR_SOURCE_ROOT, f), |
164 os.path.join(ValgrindTool.VG_DIR, | 164 os.path.join(ValgrindTool.VG_DIR, |
165 os.path.basename(f))) | 165 os.path.basename(f))) |
166 | 166 |
167 def SetupEnvironment(self): | 167 def SetupEnvironment(self): |
168 """Sets up device environment.""" | 168 """Sets up device environment.""" |
169 self._adb.RunShellCommand('chmod 777 /data/local/tmp') | 169 self._adb.RunShellCommand('chmod 777 /data/local/tmp') |
170 for prop in self._wrap_properties: | 170 for prop in self._wrap_properties: |
171 self._adb.RunShellCommand('setprop %s "logwrapper %s"' % ( | 171 self._adb.RunShellCommand('setprop %s "logwrapper %s"' % ( |
172 prop, self.GetTestWrapper())) | 172 prop, self.GetTestWrapper())) |
173 SetChromeTimeoutScale(self._adb, self.GetTimeoutScale()) | 173 SetChromeTimeoutScale(self._adb, self.GetTimeoutScale()) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if not tool_name: | 255 if not tool_name: |
256 return BaseTool() | 256 return BaseTool() |
257 | 257 |
258 ctor = TOOL_REGISTRY.get(tool_name) | 258 ctor = TOOL_REGISTRY.get(tool_name) |
259 if ctor: | 259 if ctor: |
260 return ctor(adb) | 260 return ctor(adb) |
261 else: | 261 else: |
262 print 'Unknown tool %s, available tools: %s' % ( | 262 print 'Unknown tool %s, available tools: %s' % ( |
263 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) | 263 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) |
264 sys.exit(1) | 264 sys.exit(1) |
OLD | NEW |