Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 | 11 |
| 12 import android_commands | 12 import android_commands |
| 13 import constants | 13 import constants |
| 14 from chrome_test_server_spawner import SpawningServer | 14 from chrome_test_server_spawner import SpawningServer |
| 15 import constants | 15 import constants |
| 16 from flag_changer import FlagChanger | 16 from flag_changer import FlagChanger |
| 17 from forwarder import Forwarder | 17 from forwarder import Forwarder |
| 18 import lighttpd_server | 18 import lighttpd_server |
| 19 import ports | 19 import ports |
| 20 from valgrind_tools import CreateTool | 20 from valgrind_tools import CreateTool |
| 21 | 21 |
| 22 | 22 |
| 23 # A file on device to store ports of net test server. The format of the file is | 23 # A file on device to store ports of net test server. The format of the file is |
| 24 # test-spawner-server-port:test-server-port | 24 # test-spawner-server-port:test-server-port |
| 25 NET_TEST_SERVER_PORT_INFO_FILE = \ | 25 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' |
| 26 constants.TEST_DATA_DIR + '/net-test-server-ports' | |
| 27 | 26 |
| 28 | 27 |
| 29 class BaseTestRunner(object): | 28 class BaseTestRunner(object): |
| 30 """Base class for running tests on a single device. | 29 """Base class for running tests on a single device. |
| 31 | 30 |
| 32 A subclass should implement RunTests() with no parameter, so that calling | 31 A subclass should implement RunTests() with no parameter, so that calling |
| 33 the Run() method will set up tests, run them and tear them down. | 32 the Run() method will set up tests, run them and tear them down. |
| 34 """ | 33 """ |
| 35 | 34 |
| 36 def __init__(self, device, tool, shard_index, build_type): | 35 def __init__(self, device, tool, shard_index, build_type): |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 55 self._spawner_forwarder = None | 54 self._spawner_forwarder = None |
| 56 # We will allocate port for test server spawner when calling method | 55 # We will allocate port for test server spawner when calling method |
| 57 # LaunchChromeTestServerSpawner and allocate port for test server when | 56 # LaunchChromeTestServerSpawner and allocate port for test server when |
| 58 # starting it in TestServerThread. | 57 # starting it in TestServerThread. |
| 59 self.test_server_spawner_port = 0 | 58 self.test_server_spawner_port = 0 |
| 60 self.test_server_port = 0 | 59 self.test_server_port = 0 |
| 61 self.build_type = build_type | 60 self.build_type = build_type |
| 62 | 61 |
| 63 def _PushTestServerPortInfoToDevice(self): | 62 def _PushTestServerPortInfoToDevice(self): |
| 64 """Pushes the latest port information to device.""" | 63 """Pushes the latest port information to device.""" |
| 65 self.adb.SetFileContents(NET_TEST_SERVER_PORT_INFO_FILE, | 64 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + |
| 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/09/24 10:40:49
a bit unfair to add somone else's todo :) feel fre
felipeg
2012/09/25 03:27:21
Sorry
this was a spurious diff that I copied from
| |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 132 |
| 131 def StartForwarder(self, port_pairs): | 133 def StartForwarder(self, port_pairs): |
| 132 """Starts TCP traffic forwarding for the given |port_pairs|. | 134 """Starts TCP traffic forwarding for the given |port_pairs|. |
| 133 | 135 |
| 134 Args: | 136 Args: |
| 135 host_port_pairs: A list of (device_port, local_port) tuples to forward. | 137 host_port_pairs: A list of (device_port, local_port) tuples to forward. |
| 136 """ | 138 """ |
| 137 # Sometimes the forwarder device port may be already used. We have to kill | 139 # 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 | 140 # all forwarder processes to ensure that the forwarder can be started since |
| 139 # currently we can not associate the specified port to related pid. | 141 # currently we can not associate the specified port to related pid. |
| 140 self.adb.KillAll('forwarder') | 142 self.adb.KillAll('device_forwarder') |
| 141 if self._forwarder: | 143 if self._forwarder: |
| 142 self._forwarder.Close() | 144 self._forwarder.Close() |
| 143 self._forwarder = Forwarder( | 145 self._forwarder = Forwarder( |
| 144 self.adb, port_pairs, self.tool, '127.0.0.1', self.build_type) | 146 self.adb, port_pairs, self.tool, '127.0.0.1', self.build_type) |
| 145 | 147 |
| 146 def StartForwarderForHttpServer(self): | 148 def StartForwarderForHttpServer(self): |
| 147 """Starts a forwarder for the HTTP server. | 149 """Starts a forwarder for the HTTP server. |
| 148 | 150 |
| 149 The forwarder forwards HTTP requests and responses between host and device. | 151 The forwarder forwards HTTP requests and responses between host and device. |
| 150 """ | 152 """ |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 161 self.StartForwarderForHttpServer() | 163 self.StartForwarderForHttpServer() |
| 162 | 164 |
| 163 def ShutdownHelperToolsForTestSuite(self): | 165 def ShutdownHelperToolsForTestSuite(self): |
| 164 """Shuts down the server and the forwarder.""" | 166 """Shuts down the server and the forwarder.""" |
| 165 # Forwarders should be killed before the actual servers they're forwarding | 167 # 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 | 168 # to as they are clients potentially with open connections and to allow for |
| 167 # proper hand-shake/shutdown. | 169 # proper hand-shake/shutdown. |
| 168 if self._forwarder or self._spawner_forwarder: | 170 if self._forwarder or self._spawner_forwarder: |
| 169 # Kill all forwarders on the device and then kill the process on the host | 171 # Kill all forwarders on the device and then kill the process on the host |
| 170 # (if it exists) | 172 # (if it exists) |
| 171 self.adb.KillAll('forwarder') | 173 self.adb.KillAll('device_forwarder') |
| 172 if self._forwarder: | 174 if self._forwarder: |
| 173 self._forwarder.Close() | 175 self._forwarder.Close() |
| 174 if self._spawner_forwarder: | 176 if self._spawner_forwarder: |
| 175 self._spawner_forwarder.Close() | 177 self._spawner_forwarder.Close() |
| 176 if self._http_server: | 178 if self._http_server: |
| 177 self._http_server.ShutdownHttpServer() | 179 self._http_server.ShutdownHttpServer() |
| 178 if self._spawning_server: | 180 if self._spawning_server: |
| 179 self._spawning_server.Stop() | 181 self._spawning_server.Stop() |
| 180 self.flags.Restore() | 182 self.flags.Restore() |
| 181 | 183 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 204 # Wait for 2 seconds then restart. | 206 # Wait for 2 seconds then restart. |
| 205 time.sleep(2) | 207 time.sleep(2) |
| 206 if not server_ready: | 208 if not server_ready: |
| 207 logging.error(';'.join(error_msgs)) | 209 logging.error(';'.join(error_msgs)) |
| 208 raise Exception('Can not start the test spawner server.') | 210 raise Exception('Can not start the test spawner server.') |
| 209 self._PushTestServerPortInfoToDevice() | 211 self._PushTestServerPortInfoToDevice() |
| 210 self._spawner_forwarder = Forwarder( | 212 self._spawner_forwarder = Forwarder( |
| 211 self.adb, | 213 self.adb, |
| 212 [(self.test_server_spawner_port, self.test_server_spawner_port)], | 214 [(self.test_server_spawner_port, self.test_server_spawner_port)], |
| 213 self.tool, '127.0.0.1', self.build_type) | 215 self.tool, '127.0.0.1', self.build_type) |
| OLD | NEW |