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 """Runs the Java tests. See more information on run_instrumentation_tests.py.""" | 5 """Runs the Java tests. See more information on run_instrumentation_tests.py.""" |
6 | 6 |
7 import fnmatch | 7 import fnmatch |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 self.wait_for_debugger = options.wait_for_debugger | 123 self.wait_for_debugger = options.wait_for_debugger |
124 | 124 |
125 self.tests_iter = tests_iter | 125 self.tests_iter = tests_iter |
126 self.coverage = coverage | 126 self.coverage = coverage |
127 self.apks = apks | 127 self.apks = apks |
128 self.test_apk = apks[0] | 128 self.test_apk = apks[0] |
129 self.instrumentation_class_path = self.test_apk.GetPackageName() | 129 self.instrumentation_class_path = self.test_apk.GetPackageName() |
130 self.ports_to_forward = ports_to_forward | 130 self.ports_to_forward = ports_to_forward |
131 | 131 |
132 self.test_results = TestResults() | 132 self.test_results = TestResults() |
133 # List of forwarders created by this instance of TestRunner. | 133 self.forwarder = None |
134 self.forwarders = [] | |
135 | 134 |
136 if self.coverage: | 135 if self.coverage: |
137 if os.path.exists(TestRunner._COVERAGE_MERGED_FILENAME): | 136 if os.path.exists(TestRunner._COVERAGE_MERGED_FILENAME): |
138 os.remove(TestRunner._COVERAGE_MERGED_FILENAME) | 137 os.remove(TestRunner._COVERAGE_MERGED_FILENAME) |
139 if not os.path.exists(TestRunner._COVERAGE_META_INFO_PATH): | 138 if not os.path.exists(TestRunner._COVERAGE_META_INFO_PATH): |
140 raise FatalTestException('FATAL ERROR in ' + sys.argv[0] + | 139 raise FatalTestException('FATAL ERROR in ' + sys.argv[0] + |
141 ' : Coverage meta info [' + | 140 ' : Coverage meta info [' + |
142 TestRunner._COVERAGE_META_INFO_PATH + | 141 TestRunner._COVERAGE_META_INFO_PATH + |
143 '] does not exist.') | 142 '] does not exist.') |
144 if (not TestRunner._COVERAGE_WEB_ROOT_DIR or | 143 if (not TestRunner._COVERAGE_WEB_ROOT_DIR or |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 if not self.adb.IsRootEnabled(): | 262 if not self.adb.IsRootEnabled(): |
264 logging.warning('Unable to enable java asserts for %s, non rooted device', | 263 logging.warning('Unable to enable java asserts for %s, non rooted device', |
265 self.device) | 264 self.device) |
266 else: | 265 else: |
267 if self.adb.SetJavaAssertsEnabled(enable=True): | 266 if self.adb.SetJavaAssertsEnabled(enable=True): |
268 self.adb.Reboot(full_reboot=False) | 267 self.adb.Reboot(full_reboot=False) |
269 | 268 |
270 # We give different default value to launch HTTP server based on shard index | 269 # We give different default value to launch HTTP server based on shard index |
271 # because it may have race condition when multiple processes are trying to | 270 # because it may have race condition when multiple processes are trying to |
272 # launch lighttpd with same port at same time. | 271 # launch lighttpd with same port at same time. |
273 # This line *must* come before the forwarding below, as it nukes all | 272 http_server_ports = self.LaunchTestHttpServer( |
274 # the other forwarders. A more comprehensive fix might be to pull the | 273 os.path.join(constants.CHROME_DIR), |
275 # forwarder-killing line up to here, but that might violate assumptions | 274 (constants.LIGHTTPD_RANDOM_PORT_FIRST + self.shard_index)) |
276 # implicit in other places. | |
277 self.LaunchTestHttpServer(os.path.join(constants.CHROME_DIR), | |
278 (constants.LIGHTTPD_RANDOM_PORT_FIRST + | |
279 self.shard_index)) | |
280 | |
281 if self.ports_to_forward: | 275 if self.ports_to_forward: |
282 for port in self.ports_to_forward: | 276 port_pairs = [(port, port) for port in self.ports_to_forward] |
283 self.forwarders.append(Forwarder( | 277 # We need to remember which ports the HTTP server is using, since the |
284 self.adb, [(port, port)], self.tool, '127.0.0.1', self.build_type)) | 278 # forwarder will stomp on them otherwise. |
| 279 port_pairs.append(http_server_ports) |
| 280 self.forwarder = Forwarder( |
| 281 self.adb, port_pairs, self.tool, '127.0.0.1', self.build_type) |
285 self.CopyTestFilesOnce() | 282 self.CopyTestFilesOnce() |
286 self.flags.AddFlags(['--enable-test-intents']) | 283 self.flags.AddFlags(['--enable-test-intents']) |
287 | 284 |
288 def TearDown(self): | 285 def TearDown(self): |
289 """Cleans up the test harness and saves outstanding data from test run.""" | 286 """Cleans up the test harness and saves outstanding data from test run.""" |
290 if self.forwarders: | 287 if self.forwarder: |
291 for forwarder in self.forwarders: | 288 self.forwarder.Close() |
292 forwarder.Close() | |
293 self.GenerateCoverageReportIfNeeded() | 289 self.GenerateCoverageReportIfNeeded() |
294 super(TestRunner, self).TearDown() | 290 super(TestRunner, self).TearDown() |
295 | 291 |
296 def TestSetup(self, test): | 292 def TestSetup(self, test): |
297 """Sets up the test harness for running a particular test. | 293 """Sets up the test harness for running a particular test. |
298 | 294 |
299 Args: | 295 Args: |
300 test: The name of the test that will be run. | 296 test: The name of the test that will be run. |
301 """ | 297 """ |
302 self.SetupPerfMonitoringIfNeeded(test) | 298 self.SetupPerfMonitoringIfNeeded(test) |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 | 583 |
588 logging.info('Will run: %s', str(tests)) | 584 logging.info('Will run: %s', str(tests)) |
589 | 585 |
590 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): | 586 if len(attached_devices) > 1 and (coverage or options.wait_for_debugger): |
591 logging.warning('Coverage / debugger can not be sharded, ' | 587 logging.warning('Coverage / debugger can not be sharded, ' |
592 'using first available device') | 588 'using first available device') |
593 attached_devices = attached_devices[:1] | 589 attached_devices = attached_devices[:1] |
594 sharder = TestSharder(attached_devices, options, tests, apks) | 590 sharder = TestSharder(attached_devices, options, tests, apks) |
595 test_results = sharder.RunShardedTests() | 591 test_results = sharder.RunShardedTests() |
596 return test_results | 592 return test_results |
OLD | NEW |