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 # TODO(jbudorick) Deprecate and remove this class and all subclasses after | 7 # TODO(jbudorick) Deprecate and remove this class and all subclasses after |
8 # any relevant parts have been ported to the new environment + test instance | 8 # any relevant parts have been ported to the new environment + test instance |
9 # model. | 9 # model. |
10 | 10 |
11 import logging | 11 import logging |
12 | 12 |
13 from pylib import ports | 13 from pylib import ports |
14 from pylib.device import device_utils | 14 from pylib.device import device_utils |
15 from pylib.forwarder import Forwarder | 15 from pylib.forwarder import Forwarder |
16 from pylib.valgrind_tools import CreateTool | 16 from pylib.valgrind_tools import CreateTool |
17 # TODO(frankf): Move this to pylib/utils | 17 # TODO(frankf): Move this to pylib/utils |
18 import lighttpd_server | 18 import lighttpd_server |
19 | 19 |
20 | 20 |
21 # A file on device to store ports of net test server. The format of the file is | 21 # A file on device to store ports of net test server. The format of the file is |
22 # test-spawner-server-port:test-server-port | 22 # test-spawner-server-port:test-server-port |
23 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' | 23 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' |
24 | 24 |
25 | 25 |
26 class BaseTestRunner(object): | 26 class BaseTestRunner(object): |
27 """Base class for running tests on a single device.""" | 27 """Base class for running tests on a single device.""" |
28 | 28 |
29 def __init__(self, device_serial, tool): | 29 def __init__(self, device_serial, tool, cleanup_test_files=False): |
30 """ | 30 """ |
31 Args: | 31 Args: |
32 device: Tests will run on the device of this ID. | 32 device: Tests will run on the device of this ID. |
33 tool: Name of the Valgrind tool. | 33 tool: Name of the Valgrind tool. |
| 34 cleanup_test_files: Whether or not to cleanup test files on device. |
34 """ | 35 """ |
35 self.device_serial = device_serial | 36 self.device_serial = device_serial |
36 self.device = device_utils.DeviceUtils(device_serial) | 37 self.device = device_utils.DeviceUtils(device_serial) |
37 self.tool = CreateTool(tool, self.device) | 38 self.tool = CreateTool(tool, self.device) |
38 self._http_server = None | 39 self._http_server = None |
39 self._forwarder_device_port = 8000 | 40 self._forwarder_device_port = 8000 |
40 self.forwarder_base_url = ('http://localhost:%d' % | 41 self.forwarder_base_url = ('http://localhost:%d' % |
41 self._forwarder_device_port) | 42 self._forwarder_device_port) |
42 # We will allocate port for test server spawner when calling method | 43 # We will allocate port for test server spawner when calling method |
43 # LaunchChromeTestServerSpawner and allocate port for test server when | 44 # LaunchChromeTestServerSpawner and allocate port for test server when |
44 # starting it in TestServerThread. | 45 # starting it in TestServerThread. |
45 self.test_server_spawner_port = 0 | 46 self.test_server_spawner_port = 0 |
46 self.test_server_port = 0 | 47 self.test_server_port = 0 |
| 48 self._cleanup_test_files = cleanup_test_files |
47 | 49 |
48 def _PushTestServerPortInfoToDevice(self): | 50 def _PushTestServerPortInfoToDevice(self): |
49 """Pushes the latest port information to device.""" | 51 """Pushes the latest port information to device.""" |
50 self.device.WriteFile( | 52 self.device.WriteFile( |
51 self.device.GetExternalStoragePath() + '/' + | 53 self.device.GetExternalStoragePath() + '/' + |
52 NET_TEST_SERVER_PORT_INFO_FILE, | 54 NET_TEST_SERVER_PORT_INFO_FILE, |
53 '%d:%d' % (self.test_server_spawner_port, self.test_server_port)) | 55 '%d:%d' % (self.test_server_spawner_port, self.test_server_port)) |
54 | 56 |
55 def RunTest(self, test): | 57 def RunTest(self, test): |
56 """Runs a test. Needs to be overridden. | 58 """Runs a test. Needs to be overridden. |
(...skipping 11 matching lines...) Expand all Loading... |
68 """Installs the test package once before all tests are run.""" | 70 """Installs the test package once before all tests are run.""" |
69 pass | 71 pass |
70 | 72 |
71 def SetUp(self): | 73 def SetUp(self): |
72 """Run once before all tests are run.""" | 74 """Run once before all tests are run.""" |
73 self.InstallTestPackage() | 75 self.InstallTestPackage() |
74 | 76 |
75 def TearDown(self): | 77 def TearDown(self): |
76 """Run once after all tests are run.""" | 78 """Run once after all tests are run.""" |
77 self.ShutdownHelperToolsForTestSuite() | 79 self.ShutdownHelperToolsForTestSuite() |
| 80 if self._cleanup_test_files: |
| 81 self.device.old_interface.RemovePushedFiles() |
78 | 82 |
79 def LaunchTestHttpServer(self, document_root, port=None, | 83 def LaunchTestHttpServer(self, document_root, port=None, |
80 extra_config_contents=None): | 84 extra_config_contents=None): |
81 """Launches an HTTP server to serve HTTP tests. | 85 """Launches an HTTP server to serve HTTP tests. |
82 | 86 |
83 Args: | 87 Args: |
84 document_root: Document root of the HTTP server. | 88 document_root: Document root of the HTTP server. |
85 port: port on which we want to the http server bind. | 89 port: port on which we want to the http server bind. |
86 extra_config_contents: Extra config contents for the HTTP server. | 90 extra_config_contents: Extra config contents for the HTTP server. |
87 """ | 91 """ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 # will be left open even after the forwarder has been killed. | 132 # will be left open even after the forwarder has been killed. |
129 if not ports.IsDevicePortUsed(self.device, self._forwarder_device_port): | 133 if not ports.IsDevicePortUsed(self.device, self._forwarder_device_port): |
130 self._ForwardPortsForHttpServer() | 134 self._ForwardPortsForHttpServer() |
131 | 135 |
132 def ShutdownHelperToolsForTestSuite(self): | 136 def ShutdownHelperToolsForTestSuite(self): |
133 """Shuts down the server and the forwarder.""" | 137 """Shuts down the server and the forwarder.""" |
134 if self._http_server: | 138 if self._http_server: |
135 self._UnmapPorts([(self._forwarder_device_port, self._http_server.port)]) | 139 self._UnmapPorts([(self._forwarder_device_port, self._http_server.port)]) |
136 self._http_server.ShutdownHttpServer() | 140 self._http_server.ShutdownHttpServer() |
137 | 141 |
OLD | NEW |