Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: build/android/pylib/host_driven/test_case.py

Issue 132463007: Enable presubmit pylint in build/android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase vs tot and only disabling F0401 in specific spots Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Base class for host-driven test cases. 5 """Base class for host-driven test cases.
6 6
7 This test case is intended to serve as the base class for any host-driven 7 This test case is intended to serve as the base class for any host-driven
8 test cases. It is similar to the Python unitttest module in that test cases 8 test cases. It is similar to the Python unitttest module in that test cases
9 inherit from this class and add methods which will be run as tests. 9 inherit from this class and add methods which will be run as tests.
10 10
11 When a HostDrivenTestCase object is instantiated, its purpose is to run only one 11 When a HostDrivenTestCase object is instantiated, its purpose is to run only one
12 test method in the derived class. The test runner gives it the name of the test 12 test method in the derived class. The test runner gives it the name of the test
13 method the instance will run. The test runner calls SetUp with the device ID 13 method the instance will run. The test runner calls SetUp with the device ID
14 which the test method will run against. The test runner runs the test method 14 which the test method will run against. The test runner runs the test method
15 itself, collecting the result, and calls TearDown. 15 itself, collecting the result, and calls TearDown.
16 16
17 Tests can perform arbitrary Python commands and asserts in test methods. Tests 17 Tests can perform arbitrary Python commands and asserts in test methods. Tests
18 that run instrumentation tests can make use of the _RunJavaTestFilters helper 18 that run instrumentation tests can make use of the _RunJavaTestFilters helper
19 function to trigger Java tests and convert results into a single host-driven 19 function to trigger Java tests and convert results into a single host-driven
20 test result. 20 test result.
21 """ 21 """
22 22
23 import logging 23 import logging
24 import os 24 import os
25 import time 25 import time
26 26
27 from pylib import android_commands 27 from pylib import android_commands
28 from pylib import constants
29 from pylib import forwarder 28 from pylib import forwarder
30 from pylib import valgrind_tools 29 from pylib import valgrind_tools
31 from pylib.base import base_test_result 30 from pylib.base import base_test_result
32 from pylib.instrumentation import test_package 31 from pylib.instrumentation import test_package
33 from pylib.instrumentation import test_result 32 from pylib.instrumentation import test_result
34 from pylib.instrumentation import test_runner 33 from pylib.instrumentation import test_runner
35 34
36 # aka the parent of com.google.android 35 # aka the parent of com.google.android
37 BASE_ROOT = 'src' + os.sep 36 BASE_ROOT = 'src' + os.sep
38 37
39 38
40 class HostDrivenTestCase(object): 39 class HostDrivenTestCase(object):
41 """Base class for host-driven test cases.""" 40 """Base class for host-driven test cases."""
42 41
43 _HOST_DRIVEN_TAG = 'HostDriven' 42 _HOST_DRIVEN_TAG = 'HostDriven'
44 43
45 def __init__(self, test_name, instrumentation_options=None): 44 def __init__(self, test_name, instrumentation_options=None):
46 """Create a test case initialized to run |test_name|. 45 """Create a test case initialized to run |test_name|.
47 46
48 Args: 47 Args:
49 test_name: The name of the method to run as the test. 48 test_name: The name of the method to run as the test.
50 instrumentation_options: An InstrumentationOptions object. 49 instrumentation_options: An InstrumentationOptions object.
51 """ 50 """
52 self.test_name = test_name
53 class_name = self.__class__.__name__ 51 class_name = self.__class__.__name__
54 self.qualified_name = '%s.%s' % (class_name, self.test_name) 52 self.adb = None
53 self.cleanup_test_files = False
54 self.device_id = ''
55 self.has_forwarded_ports = False
56 self.instrumentation_options = instrumentation_options
57 self.ports_to_forward = []
58 self.push_deps = False
59 self.shard_index = 0
60
55 # Use tagged_name when creating results, so that we can identify host-driven 61 # Use tagged_name when creating results, so that we can identify host-driven
56 # tests in the overall results. 62 # tests in the overall results.
63 self.test_name = test_name
64 self.qualified_name = '%s.%s' % (class_name, self.test_name)
57 self.tagged_name = '%s_%s' % (self._HOST_DRIVEN_TAG, self.qualified_name) 65 self.tagged_name = '%s_%s' % (self._HOST_DRIVEN_TAG, self.qualified_name)
58 66
59 self.instrumentation_options = instrumentation_options
60 self.ports_to_forward = []
61 self.has_forwarded_ports = False
62
63 # TODO(bulach): make ports_to_forward not optional and move the Forwarder 67 # TODO(bulach): make ports_to_forward not optional and move the Forwarder
64 # mapping here. 68 # mapping here.
65 def SetUp(self, device, shard_index, push_deps, 69 def SetUp(self, device, shard_index, push_deps,
66 cleanup_test_files, ports_to_forward=[]): 70 cleanup_test_files, ports_to_forward=None):
71 if not ports_to_forward:
72 ports_to_forward = []
67 self.device_id = device 73 self.device_id = device
68 self.shard_index = shard_index 74 self.shard_index = shard_index
69 self.adb = android_commands.AndroidCommands(self.device_id) 75 self.adb = android_commands.AndroidCommands(self.device_id)
70 self.push_deps = push_deps 76 self.push_deps = push_deps
71 self.cleanup_test_files = cleanup_test_files 77 self.cleanup_test_files = cleanup_test_files
72 if ports_to_forward: 78 if ports_to_forward:
73 self.ports_to_forward = ports_to_forward 79 self.ports_to_forward = ports_to_forward
74 80
75 def TearDown(self): 81 def TearDown(self):
76 pass 82 pass
77 83
78 # TODO(craigdh): Remove GetOutDir once references have been removed
79 # downstream.
80 def GetOutDir(self):
81 return constants.GetOutDirectory()
82
83 def Run(self): 84 def Run(self):
84 logging.info('Running host-driven test: %s', self.tagged_name) 85 logging.info('Running host-driven test: %s', self.tagged_name)
85 # Get the test method on the derived class and execute it 86 # Get the test method on the derived class and execute it
86 return getattr(self, self.test_name)() 87 return getattr(self, self.test_name)()
87 88
88 def __GetHostForwarderLog(self): 89 @staticmethod
90 def __GetHostForwarderLog():
89 return ('-- Begin Full HostForwarder log\n' 91 return ('-- Begin Full HostForwarder log\n'
90 '%s\n' 92 '%s\n'
91 '--End Full HostForwarder log\n' % forwarder.Forwarder.GetHostLog()) 93 '--End Full HostForwarder log\n' % forwarder.Forwarder.GetHostLog())
92 94
93 def __StartForwarder(self): 95 def __StartForwarder(self):
94 logging.warning('Forwarding %s %s', self.ports_to_forward, 96 logging.warning('Forwarding %s %s', self.ports_to_forward,
95 self.has_forwarded_ports) 97 self.has_forwarded_ports)
96 if self.ports_to_forward and not self.has_forwarded_ports: 98 if self.ports_to_forward and not self.has_forwarded_ports:
97 self.has_forwarded_ports = True 99 self.has_forwarded_ports = True
98 tool = valgrind_tools.CreateTool(None, self.adb) 100 tool = valgrind_tools.CreateTool(None, self.adb)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 test_type = base_test_result.ResultType.PASS 146 test_type = base_test_result.ResultType.PASS
145 log = '' 147 log = ''
146 148
147 test_pkg = test_package.TestPackage( 149 test_pkg = test_package.TestPackage(
148 self.instrumentation_options.test_apk_path, 150 self.instrumentation_options.test_apk_path,
149 self.instrumentation_options.test_apk_jar_path) 151 self.instrumentation_options.test_apk_jar_path)
150 152
151 start_ms = int(time.time()) * 1000 153 start_ms = int(time.time()) * 1000
152 done = False 154 done = False
153 for test_filter in test_filters: 155 for test_filter in test_filters:
154 tests = test_pkg._GetAllMatchingTests(None, None, test_filter) 156 tests = test_pkg.GetAllMatchingTests(None, None, test_filter)
155 # Filters should always result in >= 1 test. 157 # Filters should always result in >= 1 test.
156 if len(tests) == 0: 158 if len(tests) == 0:
157 raise Exception('Java test filter "%s" returned no tests.' 159 raise Exception('Java test filter "%s" returned no tests.'
158 % test_filter) 160 % test_filter)
159 for test in tests: 161 for test in tests:
160 # We're only running one test at a time, so this TestRunResults object 162 # We're only running one test at a time, so this TestRunResults object
161 # will hold only one result. 163 # will hold only one result.
162 java_result = self.__RunJavaTest(test, test_pkg, additional_flags) 164 java_result = self.__RunJavaTest(test, test_pkg, additional_flags)
163 assert len(java_result.GetAll()) == 1 165 assert len(java_result.GetAll()) == 1
164 if not java_result.DidRunPass(): 166 if not java_result.DidRunPass():
(...skipping 11 matching lines...) Expand all
176 overall_result.AddResult( 178 overall_result.AddResult(
177 test_result.InstrumentationTestResult( 179 test_result.InstrumentationTestResult(
178 self.tagged_name, test_type, start_ms, duration_ms, log=log)) 180 self.tagged_name, test_type, start_ms, duration_ms, log=log))
179 return overall_result 181 return overall_result
180 182
181 def __str__(self): 183 def __str__(self):
182 return self.tagged_name 184 return self.tagged_name
183 185
184 def __repr__(self): 186 def __repr__(self):
185 return self.tagged_name 187 return self.tagged_name
OLDNEW
« no previous file with comments | « build/android/pylib/host_driven/setup.py ('k') | build/android/pylib/host_driven/test_info_collection.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698