Chromium Code Reviews| Index: build/android/pylib/linker/test_runner.py |
| diff --git a/build/android/pylib/linker/test_runner.py b/build/android/pylib/linker/test_runner.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aea59a9709c14ce3fcb8147704f95e2b7bb121de |
| --- /dev/null |
| +++ b/build/android/pylib/linker/test_runner.py |
| @@ -0,0 +1,106 @@ |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Runs linker tests on a particular device.""" |
| + |
| +import logging |
| +import os.path |
| +import sys |
| +import time |
| +import traceback |
| + |
| +from pylib import constants |
| +from pylib.base import base_test_result |
| +from pylib.base import base_test_runner |
| +from pylib.utils import apk_helper |
| + |
| +import test_case |
| + |
| + |
| +# Name of the Android package to install for this to work. |
| +_PACKAGE_NAME = "ContentLinkerTest" |
|
frankf
2013/10/02 18:16:02
single quotes
digit1
2013/10/03 09:16:00
Done.
|
| + |
| + |
| +class LinkerExceptionTestResult(base_test_result.BaseTestResult): |
| + """Test result corresponding to a python exception in a host-custom test.""" |
| + |
| + def __init__(self, test_name, exc_info): |
| + """Constructs a LinkerExceptionTestResult object. |
| + |
| + Args: |
| + test_name: name of the test which raised an exception. |
| + exc_info: exception info, ostensibly from sys.exc_info(). |
| + """ |
| + exc_type, exc_value, exc_traceback = exc_info |
| + trace_info = ''.join(traceback.format_exception(exc_type, exc_value, |
| + exc_traceback)) |
| + log_msg = 'Exception:\n' + trace_info |
| + |
| + super(LinkerExceptionTestResult, self).__init__( |
| + test_name, |
| + base_test_result.ResultType.FAIL, |
| + log=str(exc_type) + ' ' + log_msg) |
|
frankf
2013/10/02 18:16:02
use string formating '%s %s'
digit1
2013/10/03 09:16:00
Done.
|
| + |
| + |
| +class LinkerTestRunner(base_test_runner.BaseTestRunner): |
| + """Orchestrates running a set of linker tests. |
| + |
| + Any Python exceptions in the tests are caught and translated into a failed |
| + result, rather than being re-raised on the main thread. |
| + """ |
| + |
| + #override |
| + def __init__(self, device, tool, push_deps, |
| + cleanup_test_files): |
|
frankf
2013/10/02 18:16:02
I think this fist on a single line
digit1
2013/10/03 09:16:00
Done.
|
| + """Creates a new LinkerTestRunner. |
| + |
| + Args: |
| + device: Attached android device. |
| + tool: Name of the Valgrind tool. |
| + push_deps: If True, push all dependencies to the device. |
| + cleanup_test_files: Whether or not to cleanup test files on device. |
| + """ |
| + |
| + super(LinkerTestRunner, self).__init__(device, tool, push_deps, |
| + cleanup_test_files) |
| + |
| + #override |
| + def InstallTestPackage(self): |
| + apk_path = os.path.join( |
| + constants.GetOutDirectory(), 'apks', '%s.apk' % _PACKAGE_NAME) |
| + |
| + if not os.path.exists(apk_path): |
| + raise Exception('%s not found, please build it' % apk_path) |
| + |
| + package_name = apk_helper.GetPackageName(apk_path) |
| + self.adb.ManagedInstall(apk_path, package_name) |
| + |
| + #override |
| + def RunTest(self, test): |
| + """Sets up and runs a test case. |
| + |
| + Args: |
| + test: An object which is ostensibly a subclass of LinkerTestCase. |
| + |
| + Returns: |
| + A TestRunResults object which contains the result produced by the test |
| + and, in the case of a failure, the test that should be retried. |
| + """ |
| + |
| + assert isinstance(test, test_case.LinkerTestCase) |
| + |
| + try: |
| + results = test.Run(self.device) |
| + except Exception: |
| + logging.exception('Caught exception while trying to run test: ' + |
| + test.tagged_name) |
| + exc_info = sys.exc_info() |
| + results = base_test_result.TestRunResults() |
| + results.AddResult(LinkerExceptionTestResult( |
| + test.tagged_name, exc_info)) |
| + |
| + if not results.DidRunPass(): |
| + return results, test |
| + else: |
| + return results, None |