OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 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 logging |
| 6 import sys |
| 7 import traceback |
| 8 |
| 9 from pylib.base import base_test_result |
| 10 from pylib.linker import test_case |
| 11 from pylib.local.device import local_device_environment |
| 12 from pylib.local.device import local_device_test_run |
| 13 |
| 14 |
| 15 class LinkerExceptionTestResult(base_test_result.BaseTestResult): |
| 16 """Test result corresponding to a python exception in a host-custom test.""" |
| 17 |
| 18 def __init__(self, test_name, exc_info): |
| 19 """Constructs a LinkerExceptionTestResult object. |
| 20 |
| 21 Args: |
| 22 test_name: name of the test which raised an exception. |
| 23 exc_info: exception info, ostensibly from sys.exc_info(). |
| 24 """ |
| 25 exc_type, exc_value, exc_traceback = exc_info |
| 26 trace_info = ''.join(traceback.format_exception(exc_type, exc_value, |
| 27 exc_traceback)) |
| 28 log_msg = 'Exception:\n' + trace_info |
| 29 |
| 30 super(LinkerExceptionTestResult, self).__init__( |
| 31 test_name, |
| 32 base_test_result.ResultType.FAIL, |
| 33 log="%s %s" % (exc_type, log_msg)) |
| 34 |
| 35 |
| 36 class LocalDeviceLinkerTestRun(local_device_test_run.LocalDeviceTestRun): |
| 37 |
| 38 def _CreateShards(self, tests): |
| 39 return tests |
| 40 |
| 41 def _GetTests(self): |
| 42 min_device_sdk = min(d.build_version_sdk for d in self._env.devices) |
| 43 return self._test_instance.GetTests(min_device_sdk) |
| 44 |
| 45 def _GetUniqueTestName(self, test): |
| 46 return test.qualified_name |
| 47 |
| 48 def _RunTest(self, device, test): |
| 49 assert isinstance(test, test_case.LinkerTestCaseBase) |
| 50 |
| 51 try: |
| 52 result = test.Run(device) |
| 53 except Exception: # pylint: disable=broad-except |
| 54 logging.exception('Caught exception while trying to run test: ' + |
| 55 test.tagged_name) |
| 56 exc_info = sys.exc_info() |
| 57 result = LinkerExceptionTestResult(test.tagged_name, exc_info) |
| 58 |
| 59 return result, None |
| 60 |
| 61 def SetUp(self): |
| 62 @local_device_environment.handle_shard_failures_with( |
| 63 on_failure=self._env.BlacklistDevice) |
| 64 def individual_device_set_up(dev): |
| 65 dev.Install(self._test_instance.test_apk) |
| 66 |
| 67 self._env.parallel_devices.pMap(individual_device_set_up) |
| 68 |
| 69 def _ShouldShard(self): |
| 70 return True |
| 71 |
| 72 def TearDown(self): |
| 73 pass |
| 74 |
| 75 def TestPackage(self): |
| 76 pass |
OLD | NEW |