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" | |
frankf
2013/10/02 18:16:02
single quotes
digit1
2013/10/03 09:16:00
Done.
| |
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=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.
| |
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, | |
55 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.
| |
56 """Creates a new LinkerTestRunner. | |
57 | |
58 Args: | |
59 device: Attached android device. | |
60 tool: Name of the Valgrind tool. | |
61 push_deps: If True, push all dependencies to the device. | |
62 cleanup_test_files: Whether or not to cleanup test files on device. | |
63 """ | |
64 | |
65 super(LinkerTestRunner, self).__init__(device, tool, push_deps, | |
66 cleanup_test_files) | |
67 | |
68 #override | |
69 def InstallTestPackage(self): | |
70 apk_path = os.path.join( | |
71 constants.GetOutDirectory(), 'apks', '%s.apk' % _PACKAGE_NAME) | |
72 | |
73 if not os.path.exists(apk_path): | |
74 raise Exception('%s not found, please build it' % apk_path) | |
75 | |
76 package_name = apk_helper.GetPackageName(apk_path) | |
77 self.adb.ManagedInstall(apk_path, package_name) | |
78 | |
79 #override | |
80 def RunTest(self, test): | |
81 """Sets up and runs a test case. | |
82 | |
83 Args: | |
84 test: An object which is ostensibly a subclass of LinkerTestCase. | |
85 | |
86 Returns: | |
87 A TestRunResults object which contains the result produced by the test | |
88 and, in the case of a failure, the test that should be retried. | |
89 """ | |
90 | |
91 assert isinstance(test, test_case.LinkerTestCase) | |
92 | |
93 try: | |
94 results = test.Run(self.device) | |
95 except Exception: | |
96 logging.exception('Caught exception while trying to run test: ' + | |
97 test.tagged_name) | |
98 exc_info = sys.exc_info() | |
99 results = base_test_result.TestRunResults() | |
100 results.AddResult(LinkerExceptionTestResult( | |
101 test.tagged_name, exc_info)) | |
102 | |
103 if not results.DidRunPass(): | |
104 return results, test | |
105 else: | |
106 return results, None | |
OLD | NEW |