| 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(). |
| 74 """ | 74 """ |
| 75 if not self.HasTests(): | 75 if not self.HasTests(): |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 # Wait for 2 seconds then restart. | 204 # Wait for 2 seconds then restart. |
| 205 time.sleep(2) | 205 time.sleep(2) |
| 206 if not server_ready: | 206 if not server_ready: |
| 207 logging.error(';'.join(error_msgs)) | 207 logging.error(';'.join(error_msgs)) |
| 208 raise Exception('Can not start the test spawner server.') | 208 raise Exception('Can not start the test spawner server.') |
| 209 self._PushTestServerPortInfoToDevice() | 209 self._PushTestServerPortInfoToDevice() |
| 210 self._spawner_forwarder = Forwarder( | 210 self._spawner_forwarder = Forwarder( |
| 211 self.adb, | 211 self.adb, |
| 212 [(self.test_server_spawner_port, self.test_server_spawner_port)], | 212 [(self.test_server_spawner_port, self.test_server_spawner_port)], |
| 213 self.tool, '127.0.0.1', self.build_type) | 213 self.tool, '127.0.0.1', self.build_type) |
| OLD | NEW |