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

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

Issue 221823011: [Android] Change object types from AndroidCommands to DeviceUtils in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Frank's comments. Created 6 years, 8 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
28 from pylib import constants 27 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
31 from pylib.device import device_utils
32 from pylib.instrumentation import test_package 32 from pylib.instrumentation import test_package
33 from pylib.instrumentation import test_result 33 from pylib.instrumentation import test_result
34 from pylib.instrumentation import test_runner 34 from pylib.instrumentation import test_runner
35 35
36 # aka the parent of com.google.android 36 # aka the parent of com.google.android
37 BASE_ROOT = 'src' + os.sep 37 BASE_ROOT = 'src' + os.sep
38 38
39 39
40 class HostDrivenTestCase(object): 40 class HostDrivenTestCase(object):
41 """Base class for host-driven test cases.""" 41 """Base class for host-driven test cases."""
42 42
43 _HOST_DRIVEN_TAG = 'HostDriven' 43 _HOST_DRIVEN_TAG = 'HostDriven'
44 44
45 def __init__(self, test_name, instrumentation_options=None): 45 def __init__(self, test_name, instrumentation_options=None):
46 """Create a test case initialized to run |test_name|. 46 """Create a test case initialized to run |test_name|.
47 47
48 Args: 48 Args:
49 test_name: The name of the method to run as the test. 49 test_name: The name of the method to run as the test.
50 instrumentation_options: An InstrumentationOptions object. 50 instrumentation_options: An InstrumentationOptions object.
51 """ 51 """
52 class_name = self.__class__.__name__ 52 class_name = self.__class__.__name__
53 self.adb = None
54 self.cleanup_test_files = False 53 self.cleanup_test_files = False
54 self.device = None
55 self.device_id = '' 55 self.device_id = ''
56 self.has_forwarded_ports = False 56 self.has_forwarded_ports = False
57 self.instrumentation_options = instrumentation_options 57 self.instrumentation_options = instrumentation_options
58 self.ports_to_forward = [] 58 self.ports_to_forward = []
59 self.push_deps = False 59 self.push_deps = False
60 self.shard_index = 0 60 self.shard_index = 0
61 61
62 # Use tagged_name when creating results, so that we can identify host-driven 62 # Use tagged_name when creating results, so that we can identify host-driven
63 # tests in the overall results. 63 # tests in the overall results.
64 self.test_name = test_name 64 self.test_name = test_name
65 self.qualified_name = '%s.%s' % (class_name, self.test_name) 65 self.qualified_name = '%s.%s' % (class_name, self.test_name)
66 self.tagged_name = '%s_%s' % (self._HOST_DRIVEN_TAG, self.qualified_name) 66 self.tagged_name = '%s_%s' % (self._HOST_DRIVEN_TAG, self.qualified_name)
67 67
68 # TODO(bulach): make ports_to_forward not optional and move the Forwarder 68 # TODO(bulach): make ports_to_forward not optional and move the Forwarder
69 # mapping here. 69 # mapping here.
70 def SetUp(self, device, shard_index, push_deps, 70 def SetUp(self, device, shard_index, push_deps,
71 cleanup_test_files, ports_to_forward=None): 71 cleanup_test_files, ports_to_forward=None):
72 if not ports_to_forward: 72 if not ports_to_forward:
73 ports_to_forward = [] 73 ports_to_forward = []
74 self.device_id = device 74 self.device_id = device
75 self.shard_index = shard_index 75 self.shard_index = shard_index
76 self.adb = android_commands.AndroidCommands(self.device_id) 76 self.device = device_utils.DeviceUtils(self.device_id)
77 self.push_deps = push_deps 77 self.push_deps = push_deps
78 self.cleanup_test_files = cleanup_test_files 78 self.cleanup_test_files = cleanup_test_files
79 if ports_to_forward: 79 if ports_to_forward:
80 self.ports_to_forward = ports_to_forward 80 self.ports_to_forward = ports_to_forward
81 81
82 def TearDown(self): 82 def TearDown(self):
83 pass 83 pass
84 84
85 # TODO(craigdh): Remove GetOutDir once references have been removed 85 # TODO(craigdh): Remove GetOutDir once references have been removed
86 # downstream. 86 # downstream.
(...skipping 10 matching lines...) Expand all
97 def __GetHostForwarderLog(): 97 def __GetHostForwarderLog():
98 return ('-- Begin Full HostForwarder log\n' 98 return ('-- Begin Full HostForwarder log\n'
99 '%s\n' 99 '%s\n'
100 '--End Full HostForwarder log\n' % forwarder.Forwarder.GetHostLog()) 100 '--End Full HostForwarder log\n' % forwarder.Forwarder.GetHostLog())
101 101
102 def __StartForwarder(self): 102 def __StartForwarder(self):
103 logging.warning('Forwarding %s %s', self.ports_to_forward, 103 logging.warning('Forwarding %s %s', self.ports_to_forward,
104 self.has_forwarded_ports) 104 self.has_forwarded_ports)
105 if self.ports_to_forward and not self.has_forwarded_ports: 105 if self.ports_to_forward and not self.has_forwarded_ports:
106 self.has_forwarded_ports = True 106 self.has_forwarded_ports = True
107 tool = valgrind_tools.CreateTool(None, self.adb) 107 tool = valgrind_tools.CreateTool(None, self.device)
108 forwarder.Forwarder.Map([(port, port) for port in self.ports_to_forward], 108 forwarder.Forwarder.Map([(port, port) for port in self.ports_to_forward],
109 self.adb, tool) 109 self.device, tool)
110 110
111 def __RunJavaTest(self, test, test_pkg, additional_flags=None): 111 def __RunJavaTest(self, test, test_pkg, additional_flags=None):
112 """Runs a single Java test in a Java TestRunner. 112 """Runs a single Java test in a Java TestRunner.
113 113
114 Args: 114 Args:
115 test: Fully qualified test name (ex. foo.bar.TestClass#testMethod) 115 test: Fully qualified test name (ex. foo.bar.TestClass#testMethod)
116 test_pkg: TestPackage object. 116 test_pkg: TestPackage object.
117 additional_flags: A list of additional flags to add to the command line. 117 additional_flags: A list of additional flags to add to the command line.
118 118
119 Returns: 119 Returns:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 overall_result.AddResult( 185 overall_result.AddResult(
186 test_result.InstrumentationTestResult( 186 test_result.InstrumentationTestResult(
187 self.tagged_name, test_type, start_ms, duration_ms, log=log)) 187 self.tagged_name, test_type, start_ms, duration_ms, log=log))
188 return overall_result 188 return overall_result
189 189
190 def __str__(self): 190 def __str__(self):
191 return self.tagged_name 191 return self.tagged_name
192 192
193 def __repr__(self): 193 def __repr__(self):
194 return self.tagged_name 194 return self.tagged_name
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698