OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 logging | 5 import logging |
6 import os | 6 import os |
7 | 7 |
8 import android_commands | 8 import android_commands |
9 from chrome_test_server_spawner import SpawningServer | 9 from chrome_test_server_spawner import SpawningServer |
10 from flag_changer import FlagChanger | 10 from flag_changer import FlagChanger |
11 import lighttpd_server | 11 import lighttpd_server |
12 import run_tests_helper | 12 import run_tests_helper |
13 | 13 |
14 FORWARDER_PATH = '/data/local/tmp/forwarder' | 14 FORWARDER_PATH = '/data/local/tmp/forwarder' |
15 # These ports must match up with the constants in net/test/test_server.cc | 15 # These ports must match up with the constants in net/test/test_server.cc |
16 TEST_SERVER_SPAWNER_PORT = 8001 | 16 TEST_SERVER_SPAWNER_PORT = 8001 |
17 TEST_SERVER_PORT = 8002 | 17 TEST_SERVER_PORT = 8002 |
18 TEST_SYNC_SERVER_PORT = 8003 | 18 TEST_SYNC_SERVER_PORT = 8003 |
19 | 19 |
20 | 20 |
21 class BaseTestRunner(object): | 21 class BaseTestRunner(object): |
22 """Base class for running tests on a single device.""" | 22 """Base class for running tests on a single device. |
23 | 23 |
24 def __init__(self, device): | 24 A subclass should implement RunTests() with no parameter, so that calling |
| 25 the Run() method will set up tests, run them and tear them down. |
| 26 """ |
| 27 |
| 28 def __init__(self, device, shard_index): |
25 """ | 29 """ |
26 Args: | 30 Args: |
27 device: Tests will run on the device of this ID. | 31 device: Tests will run on the device of this ID. |
| 32 shard_index: Index number of the shard on which the test suite will run. |
28 """ | 33 """ |
29 self.device = device | 34 self.device = device |
30 self.adb = android_commands.AndroidCommands(device=device) | 35 self.adb = android_commands.AndroidCommands(device=device) |
31 # Synchronize date/time between host and device. Otherwise same file on | 36 # Synchronize date/time between host and device. Otherwise same file on |
32 # host and device may have different timestamp which may cause | 37 # host and device may have different timestamp which may cause |
33 # AndroidCommands.PushIfNeeded failed, or a test which may compare timestamp | 38 # AndroidCommands.PushIfNeeded failed, or a test which may compare timestamp |
34 # got from http head and local time could be failed. | 39 # got from http head and local time could be failed. |
35 self.adb.SynchronizeDateTime() | 40 self.adb.SynchronizeDateTime() |
36 self._http_server = None | 41 self._http_server = None |
37 self._forwarder = None | 42 self._forwarder = None |
38 self._spawning_server = None | 43 self._spawning_server = None |
39 self._spawner_forwarder = None | 44 self._spawner_forwarder = None |
40 self._forwarder_device_port = 8000 | 45 self._forwarder_device_port = 8000 |
41 self.forwarder_base_url = ('http://localhost:%d' % | 46 self.forwarder_base_url = ('http://localhost:%d' % |
42 self._forwarder_device_port) | 47 self._forwarder_device_port) |
43 self.flags = FlagChanger(self.adb) | 48 self.flags = FlagChanger(self.adb) |
| 49 self.shard_index = shard_index |
44 | 50 |
45 def RunTests(self): | 51 def Run(self): |
46 # TODO(bulach): this should actually do SetUp / RunTestsInternal / TearDown. | 52 """Calls subclass functions to set up tests, run them and tear them down. |
47 # Refactor the various subclasses to expose a RunTestsInternal without | 53 |
48 # any params. | 54 Returns: |
49 raise NotImplementedError | 55 Test results returned from RunTests(). |
| 56 """ |
| 57 self.SetUp() |
| 58 try: |
| 59 return self.RunTests() |
| 60 finally: |
| 61 self.TearDown() |
50 | 62 |
51 def SetUp(self): | 63 def SetUp(self): |
52 """Called before tests run.""" | 64 """Called before tests run.""" |
53 pass | 65 pass |
54 | 66 |
| 67 def RunTests(self): |
| 68 """Runs the tests. Need to be overridden.""" |
| 69 raise NotImplementedError |
| 70 |
55 def TearDown(self): | 71 def TearDown(self): |
56 """Called when tests finish running.""" | 72 """Called when tests finish running.""" |
57 self.ShutdownHelperToolsForTestSuite() | 73 self.ShutdownHelperToolsForTestSuite() |
58 | 74 |
59 def CopyTestData(self, test_data_paths, dest_dir): | 75 def CopyTestData(self, test_data_paths, dest_dir): |
60 """Copies |test_data_paths| list of files/directories to |dest_dir|. | 76 """Copies |test_data_paths| list of files/directories to |dest_dir|. |
61 | 77 |
62 Args: | 78 Args: |
63 test_data_paths: A list of files or directories relative to |dest_dir| | 79 test_data_paths: A list of files or directories relative to |dest_dir| |
64 which should be copied to the device. The paths must exist in | 80 which should be copied to the device. The paths must exist in |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 """Launches test server spawner.""" | 153 """Launches test server spawner.""" |
138 self._spawning_server = SpawningServer(TEST_SERVER_SPAWNER_PORT, | 154 self._spawning_server = SpawningServer(TEST_SERVER_SPAWNER_PORT, |
139 TEST_SERVER_PORT) | 155 TEST_SERVER_PORT) |
140 self._spawning_server.Start() | 156 self._spawning_server.Start() |
141 # TODO(yfriedman): Ideally we'll only try to start up a port forwarder if | 157 # TODO(yfriedman): Ideally we'll only try to start up a port forwarder if |
142 # there isn't one already running but for now we just get an error message | 158 # there isn't one already running but for now we just get an error message |
143 # and the existing forwarder still works. | 159 # and the existing forwarder still works. |
144 self._spawner_forwarder = run_tests_helper.ForwardDevicePorts( | 160 self._spawner_forwarder = run_tests_helper.ForwardDevicePorts( |
145 self.adb, [(TEST_SERVER_SPAWNER_PORT, TEST_SERVER_SPAWNER_PORT), | 161 self.adb, [(TEST_SERVER_SPAWNER_PORT, TEST_SERVER_SPAWNER_PORT), |
146 (TEST_SERVER_PORT, TEST_SERVER_PORT)]) | 162 (TEST_SERVER_PORT, TEST_SERVER_PORT)]) |
OLD | NEW |