| OLD | NEW |
| (Empty) |
| 1 # Copyright 2013 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 """Runs linker tests on a particular device.""" | |
| 6 | |
| 7 import logging | |
| 8 import os.path | |
| 9 import sys | |
| 10 import traceback | |
| 11 | |
| 12 from pylib import constants | |
| 13 from pylib.base import base_test_result | |
| 14 from pylib.base import base_test_runner | |
| 15 from pylib.linker import test_case | |
| 16 from pylib.utils import apk_helper | |
| 17 | |
| 18 | |
| 19 # Name of the Android package to install for this to work. | |
| 20 _PACKAGE_NAME = 'ChromiumLinkerTest' | |
| 21 | |
| 22 | |
| 23 class LinkerExceptionTestResult(base_test_result.BaseTestResult): | |
| 24 """Test result corresponding to a python exception in a host-custom test.""" | |
| 25 | |
| 26 def __init__(self, test_name, exc_info): | |
| 27 """Constructs a LinkerExceptionTestResult object. | |
| 28 | |
| 29 Args: | |
| 30 test_name: name of the test which raised an exception. | |
| 31 exc_info: exception info, ostensibly from sys.exc_info(). | |
| 32 """ | |
| 33 exc_type, exc_value, exc_traceback = exc_info | |
| 34 trace_info = ''.join(traceback.format_exception(exc_type, exc_value, | |
| 35 exc_traceback)) | |
| 36 log_msg = 'Exception:\n' + trace_info | |
| 37 | |
| 38 super(LinkerExceptionTestResult, self).__init__( | |
| 39 test_name, | |
| 40 base_test_result.ResultType.FAIL, | |
| 41 log="%s %s" % (exc_type, log_msg)) | |
| 42 | |
| 43 | |
| 44 class LinkerTestRunner(base_test_runner.BaseTestRunner): | |
| 45 """Orchestrates running a set of linker tests. | |
| 46 | |
| 47 Any Python exceptions in the tests are caught and translated into a failed | |
| 48 result, rather than being re-raised on the main thread. | |
| 49 """ | |
| 50 | |
| 51 #override | |
| 52 def __init__(self, device, tool): | |
| 53 """Creates a new LinkerTestRunner. | |
| 54 | |
| 55 Args: | |
| 56 device: Attached android device. | |
| 57 tool: Name of the Valgrind tool. | |
| 58 """ | |
| 59 super(LinkerTestRunner, self).__init__(device, tool) | |
| 60 | |
| 61 #override | |
| 62 def InstallTestPackage(self): | |
| 63 apk_path = os.path.join( | |
| 64 constants.GetOutDirectory(), 'apks', '%s.apk' % _PACKAGE_NAME) | |
| 65 | |
| 66 if not os.path.exists(apk_path): | |
| 67 raise Exception('%s not found, please build it' % apk_path) | |
| 68 | |
| 69 self.device.Install(apk_path) | |
| 70 | |
| 71 #override | |
| 72 def RunTest(self, test): | |
| 73 """Sets up and runs a test case. | |
| 74 | |
| 75 Args: | |
| 76 test: An object which is ostensibly a subclass of LinkerTestCaseBase. | |
| 77 | |
| 78 Returns: | |
| 79 A TestRunResults object which contains the result produced by the test | |
| 80 and, in the case of a failure, the test that should be retried. | |
| 81 """ | |
| 82 | |
| 83 assert isinstance(test, test_case.LinkerTestCaseBase) | |
| 84 | |
| 85 try: | |
| 86 results = test.Run(self.device) | |
| 87 except Exception: | |
| 88 logging.exception('Caught exception while trying to run test: ' + | |
| 89 test.tagged_name) | |
| 90 exc_info = sys.exc_info() | |
| 91 results = base_test_result.TestRunResults() | |
| 92 results.AddResult(LinkerExceptionTestResult( | |
| 93 test.tagged_name, exc_info)) | |
| 94 | |
| 95 if not results.DidRunPass(): | |
| 96 return results, test | |
| 97 else: | |
| 98 return results, None | |
| OLD | NEW |