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.
5 """Runs linker tests on a particular device."""
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
21 # Name of the Android package to install for this to work.
22 _PACKAGE_NAME = 'ChromiumLinkerTest'
25 class LinkerExceptionTestResult(base_test_result.BaseTestResult):
26 """Test result corresponding to a python exception in a host-custom test."""
28 def __init__(self, test_name, exc_info):
29 """Constructs a LinkerExceptionTestResult object.
32 test_name: name of the test which raised an exception.
33 exc_info: exception info, ostensibly from sys.exc_info().
35 exc_type, exc_value, exc_traceback = exc_info
36 trace_info = ''.join(traceback.format_exception(exc_type, exc_value,
38 log_msg = 'Exception:\n' + trace_info
40 super(LinkerExceptionTestResult, self).__init__(
42 base_test_result.ResultType.FAIL,
43 log = "%s %s" % (exc_type, log_msg))
46 class LinkerTestRunner(base_test_runner.BaseTestRunner):
47 """Orchestrates running a set of linker tests.
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.
54 def __init__(self, device, tool, push_deps, cleanup_test_files):
55 """Creates a new LinkerTestRunner.
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.
64 super(LinkerTestRunner, self).__init__(device, tool, push_deps,
68 def InstallTestPackage(self):
69 apk_path = os.path.join(
70 constants.GetOutDirectory(), 'apks', '%s.apk' % _PACKAGE_NAME)
72 if not os.path.exists(apk_path):
73 raise Exception('%s not found, please build it' % apk_path)
75 package_name = apk_helper.GetPackageName(apk_path)
76 self.adb.ManagedInstall(apk_path, package_name)
79 def RunTest(self, test):
80 """Sets up and runs a test case.
83 test: An object which is ostensibly a subclass of LinkerTestCaseBase.
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.
90 assert isinstance(test, test_case.LinkerTestCaseBase)
93 results = test.Run(self.device)
95 logging.exception('Caught exception while trying to run test: ' +
97 exc_info = sys.exc_info()
98 results = base_test_result.TestRunResults()
99 results.AddResult(LinkerExceptionTestResult(
100 test.tagged_name, exc_info))
102 if not results.DidRunPass():