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