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 logging | 7 import logging |
8 import time | 8 import time |
9 | 9 |
10 from pylib import ports | 10 from pylib import ports |
11 from pylib.chrome_test_server_spawner import SpawningServer | 11 from pylib.chrome_test_server_spawner import SpawningServer |
12 from pylib.device import device_utils | 12 from pylib.device import device_utils |
13 from pylib.forwarder import Forwarder | 13 from pylib.forwarder import Forwarder |
14 from pylib.valgrind_tools import CreateTool | 14 from pylib.valgrind_tools import CreateTool |
15 # TODO(frankf): Move this to pylib/utils | 15 # TODO(frankf): Move this to pylib/utils |
16 import lighttpd_server | 16 import lighttpd_server |
17 | 17 |
18 | 18 |
19 # A file on device to store ports of net test server. The format of the file is | 19 # 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 | 20 # test-spawner-server-port:test-server-port |
21 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' | 21 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' |
22 | 22 |
23 | 23 |
24 class BaseTestRunner(object): | 24 class BaseTestRunner(object): |
25 """Base class for running tests on a single device.""" | 25 """Base class for running tests on a single device.""" |
26 | 26 |
27 def __init__(self, device_serial, tool, push_deps=True, | 27 def __init__(self, device_serial, tool, cleanup_test_files=False): |
28 cleanup_test_files=False): | |
29 """ | 28 """ |
30 Args: | 29 Args: |
31 device: Tests will run on the device of this ID. | 30 device: Tests will run on the device of this ID. |
32 tool: Name of the Valgrind tool. | 31 tool: Name of the Valgrind tool. |
33 push_deps: If True, push all dependencies to the device. | |
34 cleanup_test_files: Whether or not to cleanup test files on device. | 32 cleanup_test_files: Whether or not to cleanup test files on device. |
35 """ | 33 """ |
36 self.device_serial = device_serial | 34 self.device_serial = device_serial |
37 self.device = device_utils.DeviceUtils(device_serial) | 35 self.device = device_utils.DeviceUtils(device_serial) |
38 self.tool = CreateTool(tool, self.device) | 36 self.tool = CreateTool(tool, self.device) |
39 self._http_server = None | 37 self._http_server = None |
40 self._forwarder_device_port = 8000 | 38 self._forwarder_device_port = 8000 |
41 self.forwarder_base_url = ('http://localhost:%d' % | 39 self.forwarder_base_url = ('http://localhost:%d' % |
42 self._forwarder_device_port) | 40 self._forwarder_device_port) |
43 self._spawning_server = None | 41 self._spawning_server = None |
44 # We will allocate port for test server spawner when calling method | 42 # We will allocate port for test server spawner when calling method |
45 # LaunchChromeTestServerSpawner and allocate port for test server when | 43 # LaunchChromeTestServerSpawner and allocate port for test server when |
46 # starting it in TestServerThread. | 44 # starting it in TestServerThread. |
47 self.test_server_spawner_port = 0 | 45 self.test_server_spawner_port = 0 |
48 self.test_server_port = 0 | 46 self.test_server_port = 0 |
49 self._push_deps = push_deps | |
50 self._cleanup_test_files = cleanup_test_files | 47 self._cleanup_test_files = cleanup_test_files |
51 | 48 |
52 def _PushTestServerPortInfoToDevice(self): | 49 def _PushTestServerPortInfoToDevice(self): |
53 """Pushes the latest port information to device.""" | 50 """Pushes the latest port information to device.""" |
54 self.device.WriteFile( | 51 self.device.WriteFile( |
55 self.device.GetExternalStoragePath() + '/' + | 52 self.device.GetExternalStoragePath() + '/' + |
56 NET_TEST_SERVER_PORT_INFO_FILE, | 53 NET_TEST_SERVER_PORT_INFO_FILE, |
57 '%d:%d' % (self.test_server_spawner_port, self.test_server_port)) | 54 '%d:%d' % (self.test_server_spawner_port, self.test_server_port)) |
58 | 55 |
59 def RunTest(self, test): | 56 def RunTest(self, test): |
(...skipping 12 matching lines...) Expand all Loading... |
72 """Installs the test package once before all tests are run.""" | 69 """Installs the test package once before all tests are run.""" |
73 pass | 70 pass |
74 | 71 |
75 def PushDataDeps(self): | 72 def PushDataDeps(self): |
76 """Push all data deps to device once before all tests are run.""" | 73 """Push all data deps to device once before all tests are run.""" |
77 pass | 74 pass |
78 | 75 |
79 def SetUp(self): | 76 def SetUp(self): |
80 """Run once before all tests are run.""" | 77 """Run once before all tests are run.""" |
81 self.InstallTestPackage() | 78 self.InstallTestPackage() |
82 push_size_before = self.device.old_interface.GetPushSizeInfo() | 79 self.PushDataDeps() |
83 if self._push_deps: | |
84 logging.warning('Pushing data files to device.') | |
85 self.PushDataDeps() | |
86 push_size_after = self.device.old_interface.GetPushSizeInfo() | |
87 logging.warning( | |
88 'Total data: %0.3fMB' % | |
89 ((push_size_after[0] - push_size_before[0]) / float(2 ** 20))) | |
90 logging.warning( | |
91 'Total data transferred: %0.3fMB' % | |
92 ((push_size_after[1] - push_size_before[1]) / float(2 ** 20))) | |
93 else: | |
94 logging.warning('Skipping pushing data to device.') | |
95 | 80 |
96 def TearDown(self): | 81 def TearDown(self): |
97 """Run once after all tests are run.""" | 82 """Run once after all tests are run.""" |
98 self.ShutdownHelperToolsForTestSuite() | 83 self.ShutdownHelperToolsForTestSuite() |
99 if self._cleanup_test_files: | 84 if self._cleanup_test_files: |
100 self.device.old_interface.RemovePushedFiles() | 85 self.device.old_interface.RemovePushedFiles() |
101 | 86 |
102 def LaunchTestHttpServer(self, document_root, port=None, | 87 def LaunchTestHttpServer(self, document_root, port=None, |
103 extra_config_contents=None): | 88 extra_config_contents=None): |
104 """Launches an HTTP server to serve HTTP tests. | 89 """Launches an HTTP server to serve HTTP tests. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 break | 177 break |
193 else: | 178 else: |
194 error_msgs.append(error_msg) | 179 error_msgs.append(error_msg) |
195 self._spawning_server.Stop() | 180 self._spawning_server.Stop() |
196 # Wait for 2 seconds then restart. | 181 # Wait for 2 seconds then restart. |
197 time.sleep(2) | 182 time.sleep(2) |
198 if not server_ready: | 183 if not server_ready: |
199 logging.error(';'.join(error_msgs)) | 184 logging.error(';'.join(error_msgs)) |
200 raise Exception('Can not start the test spawner server.') | 185 raise Exception('Can not start the test spawner server.') |
201 self._PushTestServerPortInfoToDevice() | 186 self._PushTestServerPortInfoToDevice() |
OLD | NEW |