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 """Base class for running tests on a single device.""" | 5 """Base class for running tests on a single device.""" |
6 | 6 |
| 7 import contextlib |
| 8 import httplib |
7 import logging | 9 import logging |
| 10 import os |
| 11 import tempfile |
8 import time | 12 import time |
9 | 13 |
10 from pylib import android_commands | 14 from pylib import android_commands |
| 15 from pylib import constants |
11 from pylib import ports | 16 from pylib import ports |
12 from pylib.chrome_test_server_spawner import SpawningServer | 17 from pylib.chrome_test_server_spawner import SpawningServer |
13 from pylib.forwarder import Forwarder | 18 from pylib.forwarder import Forwarder |
14 from pylib.valgrind_tools import CreateTool | 19 from pylib.valgrind_tools import CreateTool |
15 # TODO(frankf): Move this to pylib/utils | 20 # TODO(frankf): Move this to pylib/utils |
16 import lighttpd_server | 21 import lighttpd_server |
17 | 22 |
18 | 23 |
19 # A file on device to store ports of net test server. The format of the file is | 24 # A file on device to store ports of net test server. The format of the file is |
20 # test-spawner-server-port:test-server-port | 25 # test-spawner-server-port:test-server-port |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 self._spawning_server.CleanupState() | 174 self._spawning_server.CleanupState() |
170 | 175 |
171 def LaunchChromeTestServerSpawner(self): | 176 def LaunchChromeTestServerSpawner(self): |
172 """Launches test server spawner.""" | 177 """Launches test server spawner.""" |
173 server_ready = False | 178 server_ready = False |
174 error_msgs = [] | 179 error_msgs = [] |
175 # TODO(pliard): deflake this function. The for loop should be removed as | 180 # TODO(pliard): deflake this function. The for loop should be removed as |
176 # well as IsHttpServerConnectable(). spawning_server.Start() should also | 181 # well as IsHttpServerConnectable(). spawning_server.Start() should also |
177 # block until the server is ready. | 182 # block until the server is ready. |
178 # Try 3 times to launch test spawner server. | 183 # Try 3 times to launch test spawner server. |
179 for _ in xrange(0, 3): | 184 for i in xrange(0, 3): |
180 self.test_server_spawner_port = ports.AllocateTestServerPort() | 185 self.test_server_spawner_port = ports.AllocateTestServerPort() |
181 self._ForwardPorts( | 186 self._ForwardPorts( |
182 [(self.test_server_spawner_port, self.test_server_spawner_port)]) | 187 [(self.test_server_spawner_port, self.test_server_spawner_port)]) |
183 self._spawning_server = SpawningServer(self.test_server_spawner_port, | 188 self._spawning_server = SpawningServer(self.test_server_spawner_port, |
184 self.adb, | 189 self.adb, |
185 self.tool) | 190 self.tool) |
186 self._spawning_server.Start() | 191 self._spawning_server.Start() |
187 server_ready, error_msg = ports.IsHttpServerConnectable( | 192 server_ready, error_msg = ports.IsHttpServerConnectable( |
188 '127.0.0.1', self.test_server_spawner_port, path='/ping', | 193 '127.0.0.1', self.test_server_spawner_port, path='/ping', |
189 expected_read='ready') | 194 expected_read='ready') |
190 if server_ready: | 195 if server_ready: |
191 break | 196 break |
192 else: | 197 else: |
193 error_msgs.append(error_msg) | 198 error_msgs.append(error_msg) |
194 self._spawning_server.Stop() | 199 self._spawning_server.Stop() |
195 # Wait for 2 seconds then restart. | 200 # Wait for 2 seconds then restart. |
196 time.sleep(2) | 201 time.sleep(2) |
197 if not server_ready: | 202 if not server_ready: |
198 logging.error(';'.join(error_msgs)) | 203 logging.error(';'.join(error_msgs)) |
199 raise Exception('Can not start the test spawner server.') | 204 raise Exception('Can not start the test spawner server.') |
200 self._PushTestServerPortInfoToDevice() | 205 self._PushTestServerPortInfoToDevice() |
OLD | NEW |