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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 self.test_server_port = 0 | 58 self.test_server_port = 0 |
59 self.build_type = build_type | 59 self.build_type = build_type |
60 | 60 |
61 def _PushTestServerPortInfoToDevice(self): | 61 def _PushTestServerPortInfoToDevice(self): |
62 """Pushes the latest port information to device.""" | 62 """Pushes the latest port information to device.""" |
63 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + | 63 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + |
64 NET_TEST_SERVER_PORT_INFO_FILE, | 64 NET_TEST_SERVER_PORT_INFO_FILE, |
65 '%d:%d' % (self.test_server_spawner_port, | 65 '%d:%d' % (self.test_server_spawner_port, |
66 self.test_server_port)) | 66 self.test_server_port)) |
67 | 67 |
68 def Run(self, test): | 68 def RunTest(self, test): |
69 """Calls subclass functions to set up test, run it and tear it down. | 69 """Runs a test. Needs to be overridden. |
70 | 70 |
71 Args: | 71 Args: |
72 test: A Test to run. | 72 test: A test to run. |
73 | 73 |
74 Returns: | 74 Returns: |
75 Test results returned from RunTest(test). | 75 Tuple containing: (test_result.TestResults, tests to rerun or None) |
76 """ | 76 """ |
77 self.SetUp() | 77 raise NotImplementedError |
78 try: | |
79 return self.RunTest(test) | |
80 finally: | |
81 self.TearDown() | |
82 | 78 |
83 def SetUp(self): | 79 def SetUp(self): |
84 """Called before tests run.""" | 80 """Run once before all tests are run.""" |
85 Forwarder.KillDevice(self.adb, self.tool) | 81 Forwarder.KillDevice(self.adb, self.tool) |
86 | 82 |
87 def RunTest(self, test): | |
88 """Runs the tests. Needs to be overridden.""" | |
89 raise NotImplementedError | |
90 | |
91 def TearDown(self): | 83 def TearDown(self): |
92 """Called when tests finish running.""" | 84 """Run once after all tests are run.""" |
93 self.ShutdownHelperToolsForTestSuite() | 85 self.ShutdownHelperToolsForTestSuite() |
94 | 86 |
95 def CopyTestData(self, test_data_paths, dest_dir): | 87 def CopyTestData(self, test_data_paths, dest_dir): |
96 """Copies |test_data_paths| list of files/directories to |dest_dir|. | 88 """Copies |test_data_paths| list of files/directories to |dest_dir|. |
97 | 89 |
98 Args: | 90 Args: |
99 test_data_paths: A list of files or directories relative to |dest_dir| | 91 test_data_paths: A list of files or directories relative to |dest_dir| |
100 which should be copied to the device. The paths must exist in | 92 which should be copied to the device. The paths must exist in |
101 |CHROME_DIR|. | 93 |CHROME_DIR|. |
102 dest_dir: Absolute path to copy to on the device. | 94 dest_dir: Absolute path to copy to on the device. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 # Wait for 2 seconds then restart. | 189 # Wait for 2 seconds then restart. |
198 time.sleep(2) | 190 time.sleep(2) |
199 if not server_ready: | 191 if not server_ready: |
200 logging.error(';'.join(error_msgs)) | 192 logging.error(';'.join(error_msgs)) |
201 raise Exception('Can not start the test spawner server.') | 193 raise Exception('Can not start the test spawner server.') |
202 self._PushTestServerPortInfoToDevice() | 194 self._PushTestServerPortInfoToDevice() |
203 self._spawner_forwarder = self._CreateAndRunForwarder( | 195 self._spawner_forwarder = self._CreateAndRunForwarder( |
204 self.adb, | 196 self.adb, |
205 [(self.test_server_spawner_port, self.test_server_spawner_port)], | 197 [(self.test_server_spawner_port, self.test_server_spawner_port)], |
206 self.tool, '127.0.0.1', self.build_type) | 198 self.tool, '127.0.0.1', self.build_type) |
OLD | NEW |