| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import collections | 5 import collections |
| 6 import itertools | 6 import itertools |
| 7 import os | 7 import os |
| 8 import posixpath | 8 import posixpath |
| 9 | 9 |
| 10 from devil.android import device_errors | 10 from devil.android import device_errors |
| 11 from devil.android import device_temp_file | 11 from devil.android import device_temp_file |
| 12 from devil.android import ports | 12 from devil.android import ports |
| 13 from devil.utils import reraiser_thread | 13 from devil.utils import reraiser_thread |
| 14 from pylib import constants | 14 from pylib import constants |
| 15 from pylib.base import base_test_result |
| 15 from pylib.gtest import gtest_test_instance | 16 from pylib.gtest import gtest_test_instance |
| 16 from pylib.local import local_test_server_spawner | 17 from pylib.local import local_test_server_spawner |
| 17 from pylib.local.device import local_device_environment | 18 from pylib.local.device import local_device_environment |
| 18 from pylib.local.device import local_device_test_run | 19 from pylib.local.device import local_device_test_run |
| 19 | 20 |
| 20 _COMMAND_LINE_FLAGS_SUPPORTED = True | 21 _COMMAND_LINE_FLAGS_SUPPORTED = True |
| 21 | 22 |
| 22 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen. | 23 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen. |
| 23 _EXTRA_COMMAND_LINE_FILE = ( | 24 _EXTRA_COMMAND_LINE_FILE = ( |
| 24 'org.chromium.native_test.NativeTestActivity.CommandLineFile') | 25 'org.chromium.native_test.NativeTestActivity.CommandLineFile') |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 223 |
| 223 def __init__(self, env, test_instance): | 224 def __init__(self, env, test_instance): |
| 224 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) | 225 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) |
| 225 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) | 226 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) |
| 226 super(LocalDeviceGtestRun, self).__init__(env, test_instance) | 227 super(LocalDeviceGtestRun, self).__init__(env, test_instance) |
| 227 | 228 |
| 228 if self._test_instance.apk: | 229 if self._test_instance.apk: |
| 229 self._delegate = _ApkDelegate(self._test_instance) | 230 self._delegate = _ApkDelegate(self._test_instance) |
| 230 elif self._test_instance.exe: | 231 elif self._test_instance.exe: |
| 231 self._delegate = _ExeDelegate(self, self._test_instance.exe) | 232 self._delegate = _ExeDelegate(self, self._test_instance.exe) |
| 232 | 233 self._crashes = set() |
| 233 self._servers = collections.defaultdict(list) | 234 self._servers = collections.defaultdict(list) |
| 234 | 235 |
| 235 #override | 236 #override |
| 236 def TestPackage(self): | 237 def TestPackage(self): |
| 237 return self._test_instance.suite | 238 return self._test_instance.suite |
| 238 | 239 |
| 239 #override | 240 #override |
| 240 def SetUp(self): | 241 def SetUp(self): |
| 241 @local_device_test_run.handle_shard_failures_with( | 242 @local_device_test_run.handle_shard_failures_with( |
| 242 on_failure=self._env.BlacklistDevice) | 243 on_failure=self._env.BlacklistDevice) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 step() | 277 step() |
| 277 | 278 |
| 278 self._env.parallel_devices.pMap(individual_device_set_up) | 279 self._env.parallel_devices.pMap(individual_device_set_up) |
| 279 | 280 |
| 280 #override | 281 #override |
| 281 def _ShouldShard(self): | 282 def _ShouldShard(self): |
| 282 return True | 283 return True |
| 283 | 284 |
| 284 #override | 285 #override |
| 285 def _CreateShards(self, tests): | 286 def _CreateShards(self, tests): |
| 287 # _crashes are tests that might crash and make the tests in the same shard |
| 288 # following the crashed testcase not run. |
| 289 # Thus we need to create separate shards for each crashed testcase, |
| 290 # so that other tests can be run. |
| 286 device_count = len(self._env.devices) | 291 device_count = len(self._env.devices) |
| 287 shards = [] | 292 shards = [] |
| 293 |
| 294 # Add shards with only one suspect testcase. |
| 295 shards += [[crash] for crash in self._crashes if crash in tests] |
| 296 |
| 297 # Delete suspect testcase from tests. |
| 298 tests = [test for test in tests if not test in self._crashes] |
| 299 |
| 288 for i in xrange(0, device_count): | 300 for i in xrange(0, device_count): |
| 289 unbounded_shard = tests[i::device_count] | 301 unbounded_shard = tests[i::device_count] |
| 290 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] | 302 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] |
| 291 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] | 303 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] |
| 292 return shards | 304 return shards |
| 293 | 305 |
| 294 #override | 306 #override |
| 295 def _GetTests(self): | 307 def _GetTests(self): |
| 296 if self._test_instance.extract_test_list_from_filter: | 308 if self._test_instance.extract_test_list_from_filter: |
| 297 # When the exact list of tests to run is given via command-line (e.g. when | 309 # When the exact list of tests to run is given via command-line (e.g. when |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 s.Reset() | 343 s.Reset() |
| 332 if self._test_instance.app_files: | 344 if self._test_instance.app_files: |
| 333 self._delegate.PullAppFiles(device, self._test_instance.app_files, | 345 self._delegate.PullAppFiles(device, self._test_instance.app_files, |
| 334 self._test_instance.app_file_dir) | 346 self._test_instance.app_file_dir) |
| 335 if not self._test_instance.skip_clear_data: | 347 if not self._test_instance.skip_clear_data: |
| 336 self._delegate.Clear(device) | 348 self._delegate.Clear(device) |
| 337 | 349 |
| 338 # Parse the output. | 350 # Parse the output. |
| 339 # TODO(jbudorick): Transition test scripts away from parsing stdout. | 351 # TODO(jbudorick): Transition test scripts away from parsing stdout. |
| 340 results = self._test_instance.ParseGTestOutput(output) | 352 results = self._test_instance.ParseGTestOutput(output) |
| 353 |
| 354 # Check whether there are any crashed testcases. |
| 355 self._crashes.update(r.GetName() for r in results |
| 356 if r.GetType() == base_test_result.ResultType.CRASH) |
| 341 return results | 357 return results |
| 342 | 358 |
| 343 #override | 359 #override |
| 344 def TearDown(self): | 360 def TearDown(self): |
| 345 @local_device_test_run.handle_shard_failures | 361 @local_device_test_run.handle_shard_failures |
| 346 def individual_device_tear_down(dev): | 362 def individual_device_tear_down(dev): |
| 347 for s in self._servers.get(str(dev), []): | 363 for s in self._servers.get(str(dev), []): |
| 348 s.TearDown() | 364 s.TearDown() |
| 349 | 365 |
| 350 tool = self.GetTool(dev) | 366 tool = self.GetTool(dev) |
| 351 tool.CleanUpEnvironment() | 367 tool.CleanUpEnvironment() |
| 352 | 368 |
| 353 self._env.parallel_devices.pMap(individual_device_tear_down) | 369 self._env.parallel_devices.pMap(individual_device_tear_down) |
| OLD | NEW |