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 14 matching lines...) Expand all Loading... |
25 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' | 25 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' |
26 | 26 |
27 | 27 |
28 class BaseTestRunner(object): | 28 class BaseTestRunner(object): |
29 """Base class for running tests on a single device. | 29 """Base class for running tests on a single device. |
30 | 30 |
31 A subclass should implement RunTests() with no parameter, so that calling | 31 A subclass should implement RunTests() with no parameter, so that calling |
32 the Run() method will set up tests, run them and tear them down. | 32 the Run() method will set up tests, run them and tear them down. |
33 """ | 33 """ |
34 | 34 |
35 def __init__(self, device, tool, shard_index, build_type): | 35 def __init__(self, device, tool, build_type): |
36 """ | 36 """ |
37 Args: | 37 Args: |
38 device: Tests will run on the device of this ID. | 38 device: Tests will run on the device of this ID. |
39 shard_index: Index number of the shard on which the test suite will run. | 39 shard_index: Index number of the shard on which the test suite will run. |
40 build_type: 'Release' or 'Debug'. | 40 build_type: 'Release' or 'Debug'. |
41 """ | 41 """ |
42 self.device = device | 42 self.device = device |
43 self.adb = android_commands.AndroidCommands(device=device) | 43 self.adb = android_commands.AndroidCommands(device=device) |
44 self.tool = CreateTool(tool, self.adb) | 44 self.tool = CreateTool(tool, self.adb) |
45 self._http_server = None | 45 self._http_server = None |
46 self._forwarder = None | 46 self._forwarder = None |
47 self._forwarder_device_port = 8000 | 47 self._forwarder_device_port = 8000 |
48 self.forwarder_base_url = ('http://localhost:%d' % | 48 self.forwarder_base_url = ('http://localhost:%d' % |
49 self._forwarder_device_port) | 49 self._forwarder_device_port) |
50 self.flags = FlagChanger(self.adb) | 50 self.flags = FlagChanger(self.adb) |
51 self.shard_index = shard_index | |
52 self.flags.AddFlags(['--disable-fre']) | 51 self.flags.AddFlags(['--disable-fre']) |
53 self._spawning_server = None | 52 self._spawning_server = None |
54 self._spawner_forwarder = None | 53 self._spawner_forwarder = None |
55 # We will allocate port for test server spawner when calling method | 54 # We will allocate port for test server spawner when calling method |
56 # LaunchChromeTestServerSpawner and allocate port for test server when | 55 # LaunchChromeTestServerSpawner and allocate port for test server when |
57 # starting it in TestServerThread. | 56 # starting it in TestServerThread. |
58 self.test_server_spawner_port = 0 | 57 self.test_server_spawner_port = 0 |
59 self.test_server_port = 0 | 58 self.test_server_port = 0 |
60 self.build_type = build_type | 59 self.build_type = build_type |
61 | 60 |
62 def _PushTestServerPortInfoToDevice(self): | 61 def _PushTestServerPortInfoToDevice(self): |
63 """Pushes the latest port information to device.""" | 62 """Pushes the latest port information to device.""" |
64 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + | 63 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + |
65 NET_TEST_SERVER_PORT_INFO_FILE, | 64 NET_TEST_SERVER_PORT_INFO_FILE, |
66 '%d:%d' % (self.test_server_spawner_port, | 65 '%d:%d' % (self.test_server_spawner_port, |
67 self.test_server_port)) | 66 self.test_server_port)) |
68 | 67 |
69 def Run(self): | 68 def Run(self, test): |
70 """Calls subclass functions to set up tests, run them and tear them down. | 69 """Calls subclass functions to set up test, run it and tear it down. |
| 70 |
| 71 Args: |
| 72 test: A Test to run. |
71 | 73 |
72 Returns: | 74 Returns: |
73 Test results returned from RunTests(). | 75 Test results returned from RunTest(test). |
74 """ | 76 """ |
75 if not self.HasTests(): | |
76 return True | |
77 self.SetUp() | 77 self.SetUp() |
78 try: | 78 try: |
79 return self.RunTests() | 79 return self.RunTest(test) |
80 finally: | 80 finally: |
81 self.TearDown() | 81 self.TearDown() |
82 | 82 |
83 def SetUp(self): | 83 def SetUp(self): |
84 """Called before tests run.""" | 84 """Called before tests run.""" |
85 Forwarder.KillDevice(self.adb, self.tool) | 85 Forwarder.KillDevice(self.adb, self.tool) |
86 | 86 |
87 def HasTests(self): | 87 def RunTest(self, test): |
88 """Whether the test suite has tests to run.""" | 88 """Runs the tests. Needs to be overridden.""" |
89 return True | |
90 | |
91 def RunTests(self): | |
92 """Runs the tests. Need to be overridden.""" | |
93 raise NotImplementedError | 89 raise NotImplementedError |
94 | 90 |
95 def TearDown(self): | 91 def TearDown(self): |
96 """Called when tests finish running.""" | 92 """Called when tests finish running.""" |
97 self.ShutdownHelperToolsForTestSuite() | 93 self.ShutdownHelperToolsForTestSuite() |
98 | 94 |
99 def CopyTestData(self, test_data_paths, dest_dir): | 95 def CopyTestData(self, test_data_paths, dest_dir): |
100 """Copies |test_data_paths| list of files/directories to |dest_dir|. | 96 """Copies |test_data_paths| list of files/directories to |dest_dir|. |
101 | 97 |
102 Args: | 98 Args: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 # Wait for 2 seconds then restart. | 197 # Wait for 2 seconds then restart. |
202 time.sleep(2) | 198 time.sleep(2) |
203 if not server_ready: | 199 if not server_ready: |
204 logging.error(';'.join(error_msgs)) | 200 logging.error(';'.join(error_msgs)) |
205 raise Exception('Can not start the test spawner server.') | 201 raise Exception('Can not start the test spawner server.') |
206 self._PushTestServerPortInfoToDevice() | 202 self._PushTestServerPortInfoToDevice() |
207 self._spawner_forwarder = self._CreateAndRunForwarder( | 203 self._spawner_forwarder = self._CreateAndRunForwarder( |
208 self.adb, | 204 self.adb, |
209 [(self.test_server_spawner_port, self.test_server_spawner_port)], | 205 [(self.test_server_spawner_port, self.test_server_spawner_port)], |
210 self.tool, '127.0.0.1', self.build_type) | 206 self.tool, '127.0.0.1', self.build_type) |
OLD | NEW |