OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import glob | |
6 import logging | |
7 import os | |
8 import sys | |
9 | |
10 import android_commands | |
11 from android_commands import errors | |
12 from base_test_runner import BaseTestRunner | |
13 import constants | |
14 import debug_info | |
15 import perf_tests_helper | |
16 from test_package_apk import TestPackageApk | |
17 from test_package_executable import TestPackageExecutable | |
18 from test_result import BaseTestResult, TestResults | |
19 from utils import run_tests_helper | |
20 | |
21 | |
22 class SingleTestRunner(BaseTestRunner): | |
23 """Single test suite attached to a single device. | |
24 | |
25 Args: | |
26 device: Device to run the tests. | |
27 test_suite: A specific test suite to run, empty to run all. | |
28 gtest_filter: A gtest_filter flag. | |
29 test_arguments: Additional arguments to pass to the test binary. | |
30 timeout: Timeout for each test. | |
31 cleanup_test_files: Whether or not to cleanup test files on device. | |
32 tool: Name of the Valgrind tool. | |
33 shard_index: index number of the shard on which the test suite will run. | |
34 dump_debug_info: Whether or not to dump debug information. | |
35 build_type: 'Release' or 'Debug'. | |
36 in_webkit_checkout: Whether the suite is being run from a WebKit checkout. | |
37 """ | |
38 | |
39 def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout, | |
40 cleanup_test_files, tool_name, shard_index, dump_debug_info, | |
41 fast_and_loose, build_type, in_webkit_checkout): | |
42 BaseTestRunner.__init__(self, device, tool_name, shard_index, build_type) | |
43 self._running_on_emulator = self.device.startswith('emulator') | |
44 self._gtest_filter = gtest_filter | |
45 self._test_arguments = test_arguments | |
46 self.test_results = TestResults() | |
47 if dump_debug_info: | |
48 self.dump_debug_info = debug_info.GTestDebugInfo( | |
49 self.adb, device, | |
50 os.path.basename(test_suite), gtest_filter) | |
51 else: | |
52 self.dump_debug_info = None | |
53 self.fast_and_loose = fast_and_loose | |
54 self.in_webkit_checkout = in_webkit_checkout | |
55 | |
56 logging.warning('Test suite: ' + test_suite) | |
57 if os.path.splitext(test_suite)[1] == '.apk': | |
58 self.test_package = TestPackageApk( | |
59 self.adb, | |
60 device, | |
61 test_suite, | |
62 timeout, | |
63 cleanup_test_files, | |
64 self.tool, | |
65 self.dump_debug_info) | |
66 else: | |
67 # Put a copy into the android out/target directory, to allow stack trace | |
68 # generation. | |
69 symbols_dir = os.path.join(constants.CHROME_DIR, 'out', build_type, | |
70 'lib.target') | |
71 self.test_package = TestPackageExecutable( | |
72 self.adb, | |
73 device, | |
74 test_suite, timeout, | |
75 cleanup_test_files, | |
76 self.tool, | |
77 self.dump_debug_info, | |
78 symbols_dir) | |
79 | |
80 def _TestSuiteRequiresMockTestServer(self): | |
81 """Returns True if the test suite requires mock test server.""" | |
82 tests_require_net_test_server = ['unit_tests', 'net_unittests', | |
83 'content_unittests'] | |
84 return (self.test_package.test_suite_basename in | |
85 tests_require_net_test_server) | |
86 | |
87 def _GetFilterFileName(self): | |
88 """Returns the filename of gtest filter.""" | |
89 return os.path.join( | |
90 sys.path[0], 'gtest_filter', | |
91 self.test_package.test_suite_basename + '_disabled') | |
92 | |
93 def _GetAdditionalEmulatorFilterName(self): | |
94 """Returns the filename of additional gtest filter for emulator.""" | |
95 return os.path.join( | |
96 sys.path[0], 'gtest_filter', | |
97 self.test_package.test_suite_basename + | |
98 '_emulator_additional_disabled') | |
99 | |
100 def GetDisabledTests(self): | |
101 """Returns a list of disabled tests. | |
102 | |
103 Returns: | |
104 A list of disabled tests obtained from gtest_filter/test_suite_disabled. | |
105 """ | |
106 disabled_tests = run_tests_helper.GetExpectations(self._GetFilterFileName()) | |
107 if self._running_on_emulator: | |
108 # Append emulator's filter file. | |
109 disabled_tests.extend(run_tests_helper.GetExpectations( | |
110 self._GetAdditionalEmulatorFilterName())) | |
111 return disabled_tests | |
112 | |
113 def GetDataFilesForTestSuite(self): | |
114 """Returns a list of data files/dirs needed by the test suite.""" | |
115 # Ideally, we'd just push all test data. However, it has >100MB, and a lot | |
116 # of the files are not relevant (some are used for browser_tests, others for | |
117 # features not supported, etc..). | |
118 if self.test_package.test_suite_basename in ['base_unittests', | |
119 'sql_unittests', | |
120 'unit_tests']: | |
121 test_files = [ | |
122 'base/data/file_util_unittest', | |
123 'base/data/json/bom_feff.json', | |
124 'base/prefs/test/data/pref_service', | |
125 'chrome/test/data/download-test1.lib', | |
126 'chrome/test/data/extensions/bad_magic.crx', | |
127 'chrome/test/data/extensions/good.crx', | |
128 'chrome/test/data/extensions/icon1.png', | |
129 'chrome/test/data/extensions/icon2.png', | |
130 'chrome/test/data/extensions/icon3.png', | |
131 'chrome/test/data/extensions/allow_silent_upgrade/', | |
132 'chrome/test/data/extensions/app/', | |
133 'chrome/test/data/extensions/bad/', | |
134 'chrome/test/data/extensions/effective_host_permissions/', | |
135 'chrome/test/data/extensions/empty_manifest/', | |
136 'chrome/test/data/extensions/good/Extensions/', | |
137 'chrome/test/data/extensions/manifest_tests/', | |
138 'chrome/test/data/extensions/page_action/', | |
139 'chrome/test/data/extensions/permissions/', | |
140 'chrome/test/data/extensions/script_and_capture/', | |
141 'chrome/test/data/extensions/unpacker/', | |
142 'chrome/test/data/bookmarks/', | |
143 'chrome/test/data/components/', | |
144 'chrome/test/data/extensions/json_schema_test.js', | |
145 'chrome/test/data/History/', | |
146 'chrome/test/data/json_schema_validator/', | |
147 'chrome/test/data/pref_service/', | |
148 'chrome/test/data/serializer_nested_test.js', | |
149 'chrome/test/data/serializer_test.js', | |
150 'chrome/test/data/serializer_test_nowhitespace.js', | |
151 'chrome/test/data/top_sites/', | |
152 'chrome/test/data/web_app_info/', | |
153 'chrome/test/data/web_database', | |
154 'chrome/test/data/webui/', | |
155 'chrome/test/data/zip', | |
156 'chrome/third_party/mock4js/', | |
157 'content/browser/gpu/software_rendering_list.json', | |
158 'net/data/cache_tests/insert_load1', | |
159 'net/data/cache_tests/dirty_entry5', | |
160 'net/data/ssl/certificates/', | |
161 'ui/base/test/data/data_pack_unittest', | |
162 ] | |
163 if self.test_package.test_suite_basename == 'unit_tests': | |
164 test_files += ['chrome/test/data/simple_open_search.xml'] | |
165 # The following are spell check data. Now only list the data under | |
166 # third_party/hunspell_dictionaries which are used by unit tests. | |
167 old_cwd = os.getcwd() | |
168 os.chdir(constants.CHROME_DIR) | |
169 test_files += glob.glob('third_party/hunspell_dictionaries/*.bdic') | |
170 os.chdir(old_cwd) | |
171 return test_files | |
172 elif self.test_package.test_suite_basename == 'media_unittests': | |
173 return [ | |
174 'media/test/data', | |
175 ] | |
176 elif self.test_package.test_suite_basename == 'net_unittests': | |
177 return [ | |
178 'chrome/test/data/animate1.gif', | |
179 'chrome/test/data/simple.html', | |
180 'net/data/cache_tests', | |
181 'net/data/filter_unittests', | |
182 'net/data/ftp', | |
183 'net/data/proxy_resolver_v8_unittest', | |
184 'net/data/ssl/certificates', | |
185 'net/data/url_request_unittest/', | |
186 'net/data/proxy_script_fetcher_unittest' | |
187 ] | |
188 elif self.test_package.test_suite_basename == 'ui_tests': | |
189 return [ | |
190 'chrome/test/data/dromaeo', | |
191 'chrome/test/data/json2.js', | |
192 'chrome/test/data/sunspider', | |
193 'chrome/test/data/v8_benchmark', | |
194 'chrome/test/perf/v8_benchmark_uitest.js', | |
195 ] | |
196 elif self.test_package.test_suite_basename == 'content_unittests': | |
197 return [ | |
198 'content/test/data/gpu/webgl_conformance_test_expectations.txt', | |
199 'net/data/ssl/certificates/', | |
200 'webkit/data/dom_storage/webcore_test_database.localstorage', | |
201 'third_party/hyphen/hyph_en_US.dic', | |
202 ] | |
203 elif self.test_package.test_suite_basename == 'media_unittests': | |
204 return [ | |
205 'media/test/data', | |
206 ] | |
207 return [] | |
208 | |
209 def LaunchHelperToolsForTestSuite(self): | |
210 """Launches helper tools for the test suite. | |
211 | |
212 Sometimes one test may need to run some helper tools first in order to | |
213 successfully complete the test. | |
214 """ | |
215 if self._TestSuiteRequiresMockTestServer(): | |
216 self.LaunchChromeTestServerSpawner() | |
217 | |
218 def StripAndCopyFiles(self): | |
219 """Strips and copies the required data files for the test suite.""" | |
220 self.test_package.StripAndCopyExecutable() | |
221 self.test_package.PushDataAndPakFiles() | |
222 self.tool.CopyFiles() | |
223 test_data = self.GetDataFilesForTestSuite() | |
224 if test_data and not self.fast_and_loose: | |
225 # Make sure SD card is ready. | |
226 self.adb.WaitForSdCardReady(20) | |
227 for data in test_data: | |
228 self.CopyTestData([data], self.adb.GetExternalStorage()) | |
229 if self.test_package.test_suite_basename == 'webkit_unit_tests': | |
230 self.PushWebKitUnitTestsData() | |
231 | |
232 def PushWebKitUnitTestsData(self): | |
233 """Pushes the webkit_unit_tests data files to the device. | |
234 | |
235 The path of this directory is different when the suite is being run as | |
236 part of a WebKit check-out. | |
237 """ | |
238 webkit_src = os.path.join(constants.CHROME_DIR, 'third_party', 'WebKit') | |
239 if self.in_webkit_checkout: | |
240 webkit_src = os.path.join(constants.CHROME_DIR, '..', '..', '..') | |
241 | |
242 self.adb.PushIfNeeded( | |
243 os.path.join(webkit_src, 'Source/WebKit/chromium/tests/data'), | |
244 os.path.join( | |
245 self.adb.GetExternalStorage(), | |
246 'third_party/WebKit/Source/WebKit/chromium/tests/data')) | |
247 | |
248 def RunTests(self): | |
249 """Runs tests on a single device. | |
250 | |
251 Returns: | |
252 A TestResults object. | |
253 """ | |
254 try: | |
255 self.test_package.CreateTestRunnerScript(self._gtest_filter, | |
256 self._test_arguments) | |
257 self.test_results = self.test_package.RunTestsAndListResults() | |
258 except errors.DeviceUnresponsiveError as e: | |
259 # Make sure this device is not attached | |
260 if android_commands.IsDeviceAttached(self.device): | |
261 raise e | |
262 | |
263 # TODO(frankf): We should report these as "skipped" not "failures". | |
264 # Wrap the results | |
265 logging.warning(e) | |
266 failed_tests = [] | |
267 for t in self._gtest_filter.split(':'): | |
268 failed_tests += [BaseTestResult(t, '')] | |
269 self.test_results = TestResults.FromRun( | |
270 failed=failed_tests, device_exception=self.device) | |
271 | |
272 return self.test_results | |
273 | |
274 def SetUp(self): | |
275 """Sets up necessary test enviroment for the test suite.""" | |
276 super(SingleTestRunner, self).SetUp() | |
277 self.adb.ClearApplicationState(constants.CHROME_PACKAGE) | |
278 if self.dump_debug_info: | |
279 self.dump_debug_info.StartRecordingLog(True) | |
280 self.StripAndCopyFiles() | |
281 self.LaunchHelperToolsForTestSuite() | |
282 self.tool.SetupEnvironment() | |
283 | |
284 def TearDown(self): | |
285 """Cleans up the test enviroment for the test suite.""" | |
286 self.tool.CleanUpEnvironment() | |
287 if self.test_package.cleanup_test_files: | |
288 self.adb.RemovePushedFiles() | |
289 if self.dump_debug_info: | |
290 self.dump_debug_info.StopRecordingLog() | |
291 if self.dump_debug_info: | |
292 self.dump_debug_info.ArchiveNewCrashFiles() | |
293 super(SingleTestRunner, self).TearDown() | |
OLD | NEW |