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

Side by Side Diff: build/android/pylib/base_test_runner.py

Issue 11148018: Upstream the android python scripts changes that enable the new Forwarder2 to be used in our test f… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 import contextlib 5 import contextlib
6 import httplib 6 import httplib
7 import logging 7 import logging
8 import os 8 import os
9 import tempfile 9 import tempfile
10 import time 10 import time
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 """Pushes the latest port information to device.""" 63 """Pushes the latest port information to device."""
64 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + 64 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' +
65 NET_TEST_SERVER_PORT_INFO_FILE, 65 NET_TEST_SERVER_PORT_INFO_FILE,
66 '%d:%d' % (self.test_server_spawner_port, 66 '%d:%d' % (self.test_server_spawner_port,
67 self.test_server_port)) 67 self.test_server_port))
68 68
69 def Run(self): 69 def Run(self):
70 """Calls subclass functions to set up tests, run them and tear them down. 70 """Calls subclass functions to set up tests, run them and tear them down.
71 71
72 Returns: 72 Returns:
73 Test results returned from RunTests(). 73 Test results returned from RunTests(). TODO(tonyg): It looks like
bulach 2012/10/15 19:31:55 I think we should remove this todo (and from downs
felipeg 2012/10/16 14:11:44 Done.
74 different tests interpret this differently. Some return strings, others
75 bools. We need to solidify this API.
74 """ 76 """
75 if not self.HasTests(): 77 if not self.HasTests():
76 return True 78 return True
77 self.SetUp() 79 self.SetUp()
78 try: 80 try:
79 return self.RunTests() 81 return self.RunTests()
80 finally: 82 finally:
81 self.TearDown() 83 self.TearDown()
82 84
83 def SetUp(self): 85 def SetUp(self):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 extra_config_contents: Extra config contents for the HTTP server. 122 extra_config_contents: Extra config contents for the HTTP server.
121 """ 123 """
122 self._http_server = lighttpd_server.LighttpdServer( 124 self._http_server = lighttpd_server.LighttpdServer(
123 document_root, port=port, extra_config_contents=extra_config_contents) 125 document_root, port=port, extra_config_contents=extra_config_contents)
124 if self._http_server.StartupHttpServer(): 126 if self._http_server.StartupHttpServer():
125 logging.info('http server started: http://localhost:%s', 127 logging.info('http server started: http://localhost:%s',
126 self._http_server.port) 128 self._http_server.port)
127 else: 129 else:
128 logging.critical('Failed to start http server') 130 logging.critical('Failed to start http server')
129 self.StartForwarderForHttpServer() 131 self.StartForwarderForHttpServer()
132 return (self._forwarder_device_port, self._http_server.port)
130 133
131 def StartForwarder(self, port_pairs): 134 def StartForwarder(self, port_pairs):
132 """Starts TCP traffic forwarding for the given |port_pairs|. 135 """Starts TCP traffic forwarding for the given |port_pairs|.
133 136
134 Args: 137 Args:
135 host_port_pairs: A list of (device_port, local_port) tuples to forward. 138 host_port_pairs: A list of (device_port, local_port) tuples to forward.
136 """ 139 """
137 # Sometimes the forwarder device port may be already used. We have to kill
138 # all forwarder processes to ensure that the forwarder can be started since
139 # currently we can not associate the specified port to related pid.
140 self.adb.KillAll('forwarder')
141 if self._forwarder: 140 if self._forwarder:
142 self._forwarder.Close() 141 self._forwarder.Close()
143 self._forwarder = Forwarder( 142 self._forwarder = Forwarder(
144 self.adb, port_pairs, self.tool, '127.0.0.1', self.build_type) 143 self.adb, port_pairs, self.tool, '127.0.0.1', self.build_type)
145 144
146 def StartForwarderForHttpServer(self): 145 def StartForwarderForHttpServer(self):
147 """Starts a forwarder for the HTTP server. 146 """Starts a forwarder for the HTTP server.
148 147
149 The forwarder forwards HTTP requests and responses between host and device. 148 The forwarder forwards HTTP requests and responses between host and device.
150 """ 149 """
(...skipping 10 matching lines...) Expand all
161 self.StartForwarderForHttpServer() 160 self.StartForwarderForHttpServer()
162 161
163 def ShutdownHelperToolsForTestSuite(self): 162 def ShutdownHelperToolsForTestSuite(self):
164 """Shuts down the server and the forwarder.""" 163 """Shuts down the server and the forwarder."""
165 # Forwarders should be killed before the actual servers they're forwarding 164 # Forwarders should be killed before the actual servers they're forwarding
166 # to as they are clients potentially with open connections and to allow for 165 # to as they are clients potentially with open connections and to allow for
167 # proper hand-shake/shutdown. 166 # proper hand-shake/shutdown.
168 if self._forwarder or self._spawner_forwarder: 167 if self._forwarder or self._spawner_forwarder:
169 # Kill all forwarders on the device and then kill the process on the host 168 # Kill all forwarders on the device and then kill the process on the host
170 # (if it exists) 169 # (if it exists)
171 self.adb.KillAll('forwarder') 170 self.adb.KillAll('device_forwarder')
172 if self._forwarder: 171 if self._forwarder:
173 self._forwarder.Close() 172 self._forwarder.Close()
174 if self._spawner_forwarder: 173 if self._spawner_forwarder:
175 self._spawner_forwarder.Close() 174 self._spawner_forwarder.Close()
176 if self._http_server: 175 if self._http_server:
177 self._http_server.ShutdownHttpServer() 176 self._http_server.ShutdownHttpServer()
178 if self._spawning_server: 177 if self._spawning_server:
179 self._spawning_server.Stop() 178 self._spawning_server.Stop()
180 self.flags.Restore() 179 self.flags.Restore()
181 180
(...skipping 22 matching lines...) Expand all
204 # Wait for 2 seconds then restart. 203 # Wait for 2 seconds then restart.
205 time.sleep(2) 204 time.sleep(2)
206 if not server_ready: 205 if not server_ready:
207 logging.error(';'.join(error_msgs)) 206 logging.error(';'.join(error_msgs))
208 raise Exception('Can not start the test spawner server.') 207 raise Exception('Can not start the test spawner server.')
209 self._PushTestServerPortInfoToDevice() 208 self._PushTestServerPortInfoToDevice()
210 self._spawner_forwarder = Forwarder( 209 self._spawner_forwarder = Forwarder(
211 self.adb, 210 self.adb,
212 [(self.test_server_spawner_port, self.test_server_spawner_port)], 211 [(self.test_server_spawner_port, self.test_server_spawner_port)],
213 self.tool, '127.0.0.1', self.build_type) 212 self.tool, '127.0.0.1', self.build_type)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698