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 | 7 import contextlib |
8 import httplib | 8 import httplib |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 10 matching lines...) Expand all Loading... |
21 # TODO(frankf): Move this to pylib/utils | 21 # TODO(frankf): Move this to pylib/utils |
22 import lighttpd_server | 22 import lighttpd_server |
23 | 23 |
24 | 24 |
25 # A file on device to store ports of net test server. The format of the file is | 25 # A file on device to store ports of net test server. The format of the file is |
26 # test-spawner-server-port:test-server-port | 26 # test-spawner-server-port:test-server-port |
27 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' | 27 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' |
28 | 28 |
29 | 29 |
30 class BaseTestRunner(object): | 30 class BaseTestRunner(object): |
31 """Base class for running tests on a single device. | 31 """Base class for running tests on a single device.""" |
32 | 32 |
33 A subclass should implement RunTests() with no parameter, so that calling | 33 def __init__(self, device, tool, build_type, push_deps=True, |
34 the Run() method will set up tests, run them and tear them down. | 34 cleanup_test_files=False): |
35 """ | |
36 | |
37 def __init__(self, device, tool, build_type, push_deps): | |
38 """ | 35 """ |
39 Args: | 36 Args: |
40 device: Tests will run on the device of this ID. | 37 device: Tests will run on the device of this ID. |
41 shard_index: Index number of the shard on which the test suite will run. | 38 tool: Name of the Valgrind tool. |
42 build_type: 'Release' or 'Debug'. | 39 build_type: 'Release' or 'Debug'. |
43 push_deps: If True, push all dependencies to the device. | 40 push_deps: If True, push all dependencies to the device. |
| 41 cleanup_test_files: Whether or not to cleanup test files on device. |
44 """ | 42 """ |
45 self.device = device | 43 self.device = device |
46 self.adb = android_commands.AndroidCommands(device=device) | 44 self.adb = android_commands.AndroidCommands(device=device) |
47 self.tool = CreateTool(tool, self.adb) | 45 self.tool = CreateTool(tool, self.adb) |
48 self._http_server = None | 46 self._http_server = None |
49 self._forwarder = None | 47 self._forwarder = None |
50 self._forwarder_device_port = 8000 | 48 self._forwarder_device_port = 8000 |
51 self.forwarder_base_url = ('http://localhost:%d' % | 49 self.forwarder_base_url = ('http://localhost:%d' % |
52 self._forwarder_device_port) | 50 self._forwarder_device_port) |
53 self.flags = FlagChanger(self.adb) | 51 self.flags = FlagChanger(self.adb) |
54 self.flags.AddFlags(['--disable-fre']) | 52 self.flags.AddFlags(['--disable-fre']) |
55 self._spawning_server = None | 53 self._spawning_server = None |
56 self._spawner_forwarder = None | 54 self._spawner_forwarder = None |
57 # We will allocate port for test server spawner when calling method | 55 # We will allocate port for test server spawner when calling method |
58 # LaunchChromeTestServerSpawner and allocate port for test server when | 56 # LaunchChromeTestServerSpawner and allocate port for test server when |
59 # starting it in TestServerThread. | 57 # starting it in TestServerThread. |
60 self.test_server_spawner_port = 0 | 58 self.test_server_spawner_port = 0 |
61 self.test_server_port = 0 | 59 self.test_server_port = 0 |
62 self.build_type = build_type | 60 self.build_type = build_type |
63 self._push_deps = push_deps | 61 self._push_deps = push_deps |
| 62 self._cleanup_test_files = cleanup_test_files |
64 | 63 |
65 def _PushTestServerPortInfoToDevice(self): | 64 def _PushTestServerPortInfoToDevice(self): |
66 """Pushes the latest port information to device.""" | 65 """Pushes the latest port information to device.""" |
67 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + | 66 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + |
68 NET_TEST_SERVER_PORT_INFO_FILE, | 67 NET_TEST_SERVER_PORT_INFO_FILE, |
69 '%d:%d' % (self.test_server_spawner_port, | 68 '%d:%d' % (self.test_server_spawner_port, |
70 self.test_server_port)) | 69 self.test_server_port)) |
71 | 70 |
72 def RunTest(self, test): | 71 def RunTest(self, test): |
73 """Runs a test. Needs to be overridden. | 72 """Runs a test. Needs to be overridden. |
(...skipping 29 matching lines...) Expand all Loading... |
103 ((push_size_after[0] - push_size_before[0]) / float(2 ** 20))) | 102 ((push_size_after[0] - push_size_before[0]) / float(2 ** 20))) |
104 logging.warning( | 103 logging.warning( |
105 'Total data transferred: %0.3fMB' % | 104 'Total data transferred: %0.3fMB' % |
106 ((push_size_after[1] - push_size_before[1]) / float(2 ** 20))) | 105 ((push_size_after[1] - push_size_before[1]) / float(2 ** 20))) |
107 else: | 106 else: |
108 logging.warning('Skipping pushing data to device.') | 107 logging.warning('Skipping pushing data to device.') |
109 | 108 |
110 def TearDown(self): | 109 def TearDown(self): |
111 """Run once after all tests are run.""" | 110 """Run once after all tests are run.""" |
112 self.ShutdownHelperToolsForTestSuite() | 111 self.ShutdownHelperToolsForTestSuite() |
| 112 if self._cleanup_test_files: |
| 113 self.adb.RemovePushedFiles() |
113 | 114 |
114 def LaunchTestHttpServer(self, document_root, port=None, | 115 def LaunchTestHttpServer(self, document_root, port=None, |
115 extra_config_contents=None): | 116 extra_config_contents=None): |
116 """Launches an HTTP server to serve HTTP tests. | 117 """Launches an HTTP server to serve HTTP tests. |
117 | 118 |
118 Args: | 119 Args: |
119 document_root: Document root of the HTTP server. | 120 document_root: Document root of the HTTP server. |
120 port: port on which we want to the http server bind. | 121 port: port on which we want to the http server bind. |
121 extra_config_contents: Extra config contents for the HTTP server. | 122 extra_config_contents: Extra config contents for the HTTP server. |
122 """ | 123 """ |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 break | 210 break |
210 else: | 211 else: |
211 error_msgs.append(error_msg) | 212 error_msgs.append(error_msg) |
212 self._spawning_server.Stop() | 213 self._spawning_server.Stop() |
213 # Wait for 2 seconds then restart. | 214 # Wait for 2 seconds then restart. |
214 time.sleep(2) | 215 time.sleep(2) |
215 if not server_ready: | 216 if not server_ready: |
216 logging.error(';'.join(error_msgs)) | 217 logging.error(';'.join(error_msgs)) |
217 raise Exception('Can not start the test spawner server.') | 218 raise Exception('Can not start the test spawner server.') |
218 self._PushTestServerPortInfoToDevice() | 219 self._PushTestServerPortInfoToDevice() |
OLD | NEW |