Chromium Code Reviews| 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 fnmatch | 5 import fnmatch |
| 6 import functools | 6 import functools |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from devil.android import device_errors | 9 from devil.android import device_errors |
| 10 from pylib import valgrind_tools | 10 from pylib import valgrind_tools |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 """ | 22 """ |
| 23 return handle_shard_failures_with(None)(f) | 23 return handle_shard_failures_with(None)(f) |
| 24 | 24 |
| 25 | 25 |
| 26 def handle_shard_failures_with(on_failure): | 26 def handle_shard_failures_with(on_failure): |
| 27 """A decorator that handles device failures for per-device functions. | 27 """A decorator that handles device failures for per-device functions. |
| 28 | 28 |
| 29 This calls on_failure in the event of a failure. | 29 This calls on_failure in the event of a failure. |
| 30 | 30 |
| 31 Args: | 31 Args: |
| 32 f: the function being decorated. The function must take at least one | 32 f: the function being decorated. The function must take at least one |
|
jbudorick
2015/10/28 23:34:05
nit: update this now that the function must take a
bpastene
2015/10/28 23:41:57
The decorated function doesn't change. The on_fail
jbudorick
2015/10/28 23:45:15
oh, right. derp.
| |
| 33 argument, and that argument must be the device. | 33 argument, and that argument must be the device. |
| 34 on_failure: A unary function to call on failure. | 34 on_failure: A binary function to call on failure. |
| 35 """ | 35 """ |
| 36 def decorator(f): | 36 def decorator(f): |
| 37 @functools.wraps(f) | 37 @functools.wraps(f) |
| 38 def wrapper(dev, *args, **kwargs): | 38 def wrapper(dev, *args, **kwargs): |
| 39 try: | 39 try: |
| 40 return f(dev, *args, **kwargs) | 40 return f(dev, *args, **kwargs) |
| 41 except device_errors.CommandFailedError: | 41 except device_errors.CommandFailedError: |
| 42 logging.exception('Shard failed: %s(%s)', f.__name__, str(dev)) | 42 logging.exception('Shard failed: %s(%s)', f.__name__, str(dev)) |
| 43 except device_errors.CommandTimeoutError: | 43 except device_errors.CommandTimeoutError: |
| 44 logging.exception('Shard timed out: %s(%s)', f.__name__, str(dev)) | 44 logging.exception('Shard timed out: %s(%s)', f.__name__, str(dev)) |
| 45 except device_errors.DeviceUnreachableError: | 45 except device_errors.DeviceUnreachableError: |
| 46 logging.exception('Shard died: %s(%s)', f.__name__, str(dev)) | 46 logging.exception('Shard died: %s(%s)', f.__name__, str(dev)) |
| 47 if on_failure: | 47 if on_failure: |
| 48 on_failure(dev) | 48 on_failure(dev, f.__name__) |
| 49 return None | 49 return None |
| 50 | 50 |
| 51 return wrapper | 51 return wrapper |
| 52 | 52 |
| 53 return decorator | 53 return decorator |
| 54 | 54 |
| 55 | 55 |
| 56 class LocalDeviceTestRun(test_run.TestRun): | 56 class LocalDeviceTestRun(test_run.TestRun): |
| 57 | 57 |
| 58 def __init__(self, env, test_instance): | 58 def __init__(self, env, test_instance): |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 return test | 161 return test |
| 162 | 162 |
| 163 def _GetTests(self): | 163 def _GetTests(self): |
| 164 raise NotImplementedError | 164 raise NotImplementedError |
| 165 | 165 |
| 166 def _RunTest(self, device, test): | 166 def _RunTest(self, device, test): |
| 167 raise NotImplementedError | 167 raise NotImplementedError |
| 168 | 168 |
| 169 def _ShouldShard(self): | 169 def _ShouldShard(self): |
| 170 raise NotImplementedError | 170 raise NotImplementedError |
| OLD | NEW |