| 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 functools |
| 5 import logging | 6 import logging |
| 6 | 7 |
| 7 from devil.android import device_errors | 8 from devil.android import device_errors |
| 8 from pylib import valgrind_tools | 9 from pylib import valgrind_tools |
| 9 from pylib.base import base_test_result | 10 from pylib.base import base_test_result |
| 10 from pylib.base import test_run | 11 from pylib.base import test_run |
| 11 from pylib.base import test_collection | 12 from pylib.base import test_collection |
| 12 | 13 |
| 13 | 14 |
| 14 def handle_shard_failures(f): | 15 def handle_shard_failures(f): |
| 15 """A decorator that handles device failures for per-device functions. | 16 """A decorator that handles device failures for per-device functions. |
| 16 | 17 |
| 17 Args: | 18 Args: |
| 18 f: the function being decorated. The function must take at least one | 19 f: the function being decorated. The function must take at least one |
| 19 argument, and that argument must be the device. | 20 argument, and that argument must be the device. |
| 20 """ | 21 """ |
| 22 @functools.wraps(f) |
| 21 def wrapper(dev, *args, **kwargs): | 23 def wrapper(dev, *args, **kwargs): |
| 22 try: | 24 try: |
| 23 return f(dev, *args, **kwargs) | 25 return f(dev, *args, **kwargs) |
| 24 except device_errors.CommandFailedError: | 26 except device_errors.CommandFailedError: |
| 25 logging.exception('Shard failed: %s(%s)', f.__name__, str(dev)) | 27 logging.exception('Shard failed: %s(%s)', f.__name__, str(dev)) |
| 26 except device_errors.CommandTimeoutError: | 28 except device_errors.CommandTimeoutError: |
| 27 logging.exception('Shard timed out: %s(%s)', f.__name__, str(dev)) | 29 logging.exception('Shard timed out: %s(%s)', f.__name__, str(dev)) |
| 28 except device_errors.DeviceUnreachableError: | 30 except device_errors.DeviceUnreachableError: |
| 29 logging.exception('Shard died: %s(%s)', f.__name__, str(dev)) | 31 logging.exception('Shard died: %s(%s)', f.__name__, str(dev)) |
| 30 return None | 32 return None |
| 31 | 33 |
| 32 wrapper.__name__ = f.__name__ | |
| 33 return wrapper | 34 return wrapper |
| 34 | 35 |
| 35 | 36 |
| 36 class LocalDeviceTestRun(test_run.TestRun): | 37 class LocalDeviceTestRun(test_run.TestRun): |
| 37 | 38 |
| 38 def __init__(self, env, test_instance): | 39 def __init__(self, env, test_instance): |
| 39 super(LocalDeviceTestRun, self).__init__(env, test_instance) | 40 super(LocalDeviceTestRun, self).__init__(env, test_instance) |
| 40 self._tools = {} | 41 self._tools = {} |
| 41 | 42 |
| 42 #override | 43 #override |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return test | 134 return test |
| 134 | 135 |
| 135 def _GetTests(self): | 136 def _GetTests(self): |
| 136 raise NotImplementedError | 137 raise NotImplementedError |
| 137 | 138 |
| 138 def _RunTest(self, device, test): | 139 def _RunTest(self, device, test): |
| 139 raise NotImplementedError | 140 raise NotImplementedError |
| 140 | 141 |
| 141 def _ShouldShard(self): | 142 def _ShouldShard(self): |
| 142 raise NotImplementedError | 143 raise NotImplementedError |
| OLD | NEW |