| 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 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if not self.HasTests(): | 75 if not self.HasTests(): |
| 76 return True | 76 return True |
| 77 self.SetUp() | 77 self.SetUp() |
| 78 try: | 78 try: |
| 79 return self.RunTests() | 79 return self.RunTests() |
| 80 finally: | 80 finally: |
| 81 self.TearDown() | 81 self.TearDown() |
| 82 | 82 |
| 83 def SetUp(self): | 83 def SetUp(self): |
| 84 """Called before tests run.""" | 84 """Called before tests run.""" |
| 85 Forwarder.KillDevice(self.adb) | 85 Forwarder.KillDevice(self.adb, self.build_type) |
| 86 | 86 |
| 87 def HasTests(self): | 87 def HasTests(self): |
| 88 """Whether the test suite has tests to run.""" | 88 """Whether the test suite has tests to run.""" |
| 89 return True | 89 return True |
| 90 | 90 |
| 91 def RunTests(self): | 91 def RunTests(self): |
| 92 """Runs the tests. Need to be overridden.""" | 92 """Runs the tests. Need to be overridden.""" |
| 93 raise NotImplementedError | 93 raise NotImplementedError |
| 94 | 94 |
| 95 def TearDown(self): | 95 def TearDown(self): |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 # will be left open even after the forwarder has been killed. | 162 # will be left open even after the forwarder has been killed. |
| 163 if not ports.IsDevicePortUsed(self.adb, | 163 if not ports.IsDevicePortUsed(self.adb, |
| 164 self._forwarder_device_port): | 164 self._forwarder_device_port): |
| 165 self.StartForwarderForHttpServer() | 165 self.StartForwarderForHttpServer() |
| 166 | 166 |
| 167 def ShutdownHelperToolsForTestSuite(self): | 167 def ShutdownHelperToolsForTestSuite(self): |
| 168 """Shuts down the server and the forwarder.""" | 168 """Shuts down the server and the forwarder.""" |
| 169 # Forwarders should be killed before the actual servers they're forwarding | 169 # Forwarders should be killed before the actual servers they're forwarding |
| 170 # to as they are clients potentially with open connections and to allow for | 170 # to as they are clients potentially with open connections and to allow for |
| 171 # proper hand-shake/shutdown. | 171 # proper hand-shake/shutdown. |
| 172 Forwarder.KillDevice(self.adb) | 172 Forwarder.KillDevice(self.adb, self.build_type) |
| 173 if self._http_server: | 173 if self._http_server: |
| 174 self._http_server.ShutdownHttpServer() | 174 self._http_server.ShutdownHttpServer() |
| 175 if self._spawning_server: | 175 if self._spawning_server: |
| 176 self._spawning_server.Stop() | 176 self._spawning_server.Stop() |
| 177 self.flags.Restore() | 177 self.flags.Restore() |
| 178 | 178 |
| 179 def LaunchChromeTestServerSpawner(self): | 179 def LaunchChromeTestServerSpawner(self): |
| 180 """Launches test server spawner.""" | 180 """Launches test server spawner.""" |
| 181 server_ready = False | 181 server_ready = False |
| 182 error_msgs = [] | 182 error_msgs = [] |
| (...skipping 18 matching lines...) Expand all Loading... |
| 201 # Wait for 2 seconds then restart. | 201 # Wait for 2 seconds then restart. |
| 202 time.sleep(2) | 202 time.sleep(2) |
| 203 if not server_ready: | 203 if not server_ready: |
| 204 logging.error(';'.join(error_msgs)) | 204 logging.error(';'.join(error_msgs)) |
| 205 raise Exception('Can not start the test spawner server.') | 205 raise Exception('Can not start the test spawner server.') |
| 206 self._PushTestServerPortInfoToDevice() | 206 self._PushTestServerPortInfoToDevice() |
| 207 self._spawner_forwarder = self._CreateAndRunForwarder( | 207 self._spawner_forwarder = self._CreateAndRunForwarder( |
| 208 self.adb, | 208 self.adb, |
| 209 [(self.test_server_spawner_port, self.test_server_spawner_port)], | 209 [(self.test_server_spawner_port, self.test_server_spawner_port)], |
| 210 self.tool, '127.0.0.1', self.build_type) | 210 self.tool, '127.0.0.1', self.build_type) |
| OLD | NEW |