OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
frankf
2014/01/18 01:55:57
You should also move this into pylib/utils in a fu
| |
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 | 90 |
91 def __init__(self, adb): | 91 def __init__(self, adb): |
92 self._adb = adb | 92 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. | 93 # Configure AndroidCommands to run utils (such as md5sum_bin) under ASan. |
99 # This is required because ASan is a compiler-based tool, and md5sum | 94 # This is required because ASan is a compiler-based tool, and md5sum |
100 # includes instrumented code from base. | 95 # includes instrumented code from base. |
101 adb.SetUtilWrapper(self.GetUtilWrapper()) | 96 adb.SetUtilWrapper(self.GetUtilWrapper()) |
102 | 97 |
103 def CopyFiles(self): | 98 def CopyFiles(self): |
104 """Copies ASan tools to the device.""" | 99 """Copies ASan tools to the device.""" |
105 files = (['tools/android/asan/asanwrapper.sh'] + | 100 subprocess.call([os.path.join(DIR_SOURCE_ROOT, |
106 glob('third_party/llvm-build/Release+Asserts/lib/clang/*/lib/' | 101 'tools/android/asan/asan_device_setup.sh'), |
107 'linux/libclang_rt.asan-arm-android.so')) | 102 self._adb.GetDevice()]) |
108 for f in files: | 103 # Reboot is required after asan_device_setup.sh. |
bulach
2014/01/17 13:27:53
is it always required? can we detect if the proper
eugenis
2014/01/20 13:51:18
Yes, definitely.
| |
109 self._adb.PushIfNeeded(os.path.join(DIR_SOURCE_ROOT, f), | 104 # Unfortunately, this way we reboot the device twice before running the |
110 os.path.join(AddressSanitizerTool.TMP_DIR, | 105 # tests. |
111 os.path.basename(f))) | 106 self._adb.Reboot() |
112 | 107 |
113 def GetTestWrapper(self): | 108 def GetTestWrapper(self): |
114 return os.path.join(AddressSanitizerTool.TMP_DIR, | 109 return AddressSanitizerTool.WRAPPER_NAME |
115 AddressSanitizerTool.WRAPPER_NAME) | |
116 | 110 |
117 def GetUtilWrapper(self): | 111 def GetUtilWrapper(self): |
118 """Returns the wrapper for utilities, such as forwarder. | 112 """Returns the wrapper for utilities, such as forwarder. |
119 | 113 |
120 AddressSanitizer wrapper must be added to all instrumented binaries, | 114 AddressSanitizer wrapper must be added to all instrumented binaries, |
121 including forwarder and the like. This can be removed if such binaries | 115 including forwarder and the like. This can be removed if such binaries |
122 were built without instrumentation. """ | 116 were built without instrumentation. """ |
123 return self.GetTestWrapper() | 117 return self.GetTestWrapper() |
124 | 118 |
125 def SetupEnvironment(self): | 119 def SetupEnvironment(self): |
126 self._adb.EnableAdbRoot() | 120 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()) | 121 SetChromeTimeoutScale(self._adb, self.GetTimeoutScale()) |
132 | 122 |
133 def CleanUpEnvironment(self): | 123 def CleanUpEnvironment(self): |
134 for prop in self._wrap_properties: | |
135 self._adb.RunShellCommand('setprop %s ""' % (prop,)) | |
136 SetChromeTimeoutScale(self._adb, None) | 124 SetChromeTimeoutScale(self._adb, None) |
137 | 125 |
138 def GetTimeoutScale(self): | 126 def GetTimeoutScale(self): |
139 # Very slow startup. | 127 # Very slow startup. |
140 return 20.0 | 128 return 20.0 |
141 | 129 |
142 | 130 |
143 class ValgrindTool(BaseTool): | 131 class ValgrindTool(BaseTool): |
144 """Base abstract class for Valgrind tools.""" | 132 """Base abstract class for Valgrind tools.""" |
145 | 133 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 if not tool_name: | 245 if not tool_name: |
258 return BaseTool() | 246 return BaseTool() |
259 | 247 |
260 ctor = TOOL_REGISTRY.get(tool_name) | 248 ctor = TOOL_REGISTRY.get(tool_name) |
261 if ctor: | 249 if ctor: |
262 return ctor(adb) | 250 return ctor(adb) |
263 else: | 251 else: |
264 print 'Unknown tool %s, available tools: %s' % ( | 252 print 'Unknown tool %s, available tools: %s' % ( |
265 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) | 253 tool_name, ', '.join(sorted(TOOL_REGISTRY.keys()))) |
266 sys.exit(1) | 254 sys.exit(1) |
OLD | NEW |