OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Runs tests on VMs in parallel.""" | 6 """Runs tests on VMs in parallel.""" |
7 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 import tempfile | 12 import tempfile |
13 | 13 |
14 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) | 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) |
15 from cros_build_lib import Die | 15 from cros_build_lib import Die |
16 from cros_build_lib import Info | 16 from cros_build_lib import Info |
17 | 17 |
18 | 18 |
19 _DEFAULT_BASE_SSH_PORT = 9222 | 19 _DEFAULT_BASE_SSH_PORT = 9222 |
20 | 20 |
21 class ParallelTestRunner(object): | 21 class ParallelTestRunner(object): |
22 """Runs tests on VMs in parallel. | 22 """Runs tests on VMs in parallel. |
23 | 23 |
24 This class is a simple wrapper around cros_run_vm_test that provides an easy | 24 This class is a simple wrapper around cros_run_vm_test that provides an easy |
25 way to spawn several test instances in parallel and aggregate the results when | 25 way to spawn several test instances in parallel and aggregate the results when |
26 the tests complete. | 26 the tests complete. |
27 """ | 27 """ |
28 | 28 |
29 def __init__(self, tests, base_ssh_port=_DEFAULT_BASE_SSH_PORT, board=None, | 29 def __init__(self, tests, base_ssh_port=_DEFAULT_BASE_SSH_PORT, board=None, |
30 image_path=None, order_output=False, results_dir_root=None): | 30 image_path=None, order_output=False, results_dir_root=None, |
| 31 use_emerged=False): |
31 """Constructs and initializes the test runner class. | 32 """Constructs and initializes the test runner class. |
32 | 33 |
33 Args: | 34 Args: |
34 tests: A list of test names (see run_remote_tests.sh). | 35 tests: A list of test names (see run_remote_tests.sh). |
35 base_ssh_port: The base SSH port. Spawned VMs listen to localhost SSH | 36 base_ssh_port: The base SSH port. Spawned VMs listen to localhost SSH |
36 ports incrementally allocated starting from the base one. | 37 ports incrementally allocated starting from the base one. |
37 board: The target board. If none, cros_run_vm_tests will use the default | 38 board: The target board. If none, cros_run_vm_tests will use the default |
38 board. | 39 board. |
39 image_path: Full path to the VM image. If none, cros_run_vm_tests will use | 40 image_path: Full path to the VM image. If none, cros_run_vm_tests will use |
40 the latest image. | 41 the latest image. |
41 order_output: If True, output of individual VMs will be piped to | 42 order_output: If True, output of individual VMs will be piped to |
42 temporary files and emitted at the end. | 43 temporary files and emitted at the end. |
43 results_dir_root: The results directory root. If provided, the results | 44 results_dir_root: The results directory root. If provided, the results |
44 directory root for each test will be created under it with the SSH port | 45 directory root for each test will be created under it with the SSH port |
45 appended to the test name. | 46 appended to the test name. |
46 """ | 47 """ |
47 self._tests = tests | 48 self._tests = tests |
48 self._base_ssh_port = base_ssh_port | 49 self._base_ssh_port = base_ssh_port |
49 self._board = board | 50 self._board = board |
50 self._image_path = image_path | 51 self._image_path = image_path |
51 self._order_output = order_output | 52 self._order_output = order_output |
52 self._results_dir_root = results_dir_root | 53 self._results_dir_root = results_dir_root |
| 54 self._use_emerged = use_emerged |
53 | 55 |
54 def _SpawnTests(self): | 56 def _SpawnTests(self): |
55 """Spawns VMs and starts the test runs on them. | 57 """Spawns VMs and starts the test runs on them. |
56 | 58 |
57 Runs all tests in |self._tests|. Each test is executed on a separate VM. | 59 Runs all tests in |self._tests|. Each test is executed on a separate VM. |
58 | 60 |
59 Returns: | 61 Returns: |
60 A list of test process info objects containing the following dictionary | 62 A list of test process info objects containing the following dictionary |
61 entries: | 63 entries: |
62 'test': the test name; | 64 'test': the test name; |
63 'proc': the Popen process instance for this test run. | 65 'proc': the Popen process instance for this test run. |
64 """ | 66 """ |
65 ssh_port = self._base_ssh_port | 67 ssh_port = self._base_ssh_port |
66 spawned_tests = [] | 68 spawned_tests = [] |
67 for test in self._tests: | 69 for test in self._tests: |
68 args = [ os.path.join(os.path.dirname(__file__), 'cros_run_vm_test'), | 70 args = [ os.path.join(os.path.dirname(__file__), 'cros_run_vm_test'), |
69 '--snapshot', # The image is shared so don't modify it. | 71 '--snapshot', # The image is shared so don't modify it. |
70 '--no_graphics', | 72 '--no_graphics', |
71 '--ssh_port=%d' % ssh_port, | 73 '--ssh_port=%d' % ssh_port, |
72 '--test_case=%s' % test ] | 74 '--test_case=%s' % test ] |
73 if self._board: args.append('--board=%s' % self._board) | 75 if self._board: args.append('--board=%s' % self._board) |
74 if self._image_path: args.append('--image_path=%s' % self._image_path) | 76 if self._image_path: args.append('--image_path=%s' % self._image_path) |
75 if self._results_dir_root: | 77 if self._results_dir_root: |
76 args.append('--results_dir_root=%s/%s.%d' % | 78 args.append('--results_dir_root=%s/%s.%d' % |
77 (self._results_dir_root, test, ssh_port)) | 79 (self._results_dir_root, test, ssh_port)) |
| 80 if self._use_emerged: args.append('--use_emerged') |
78 Info('Running %r...' % args) | 81 Info('Running %r...' % args) |
79 output = None | 82 output = None |
80 if self._order_output: | 83 if self._order_output: |
81 output = tempfile.NamedTemporaryFile(prefix='parallel_vm_test_') | 84 output = tempfile.NamedTemporaryFile(prefix='parallel_vm_test_') |
82 Info('Piping output to %s.' % output.name) | 85 Info('Piping output to %s.' % output.name) |
83 proc = subprocess.Popen(args, stdout=output, stderr=output) | 86 proc = subprocess.Popen(args, stdout=output, stderr=output) |
84 test_info = { 'test': test, | 87 test_info = { 'test': test, |
85 'proc': proc, | 88 'proc': proc, |
86 'output': output } | 89 'output': output } |
87 spawned_tests.append(test_info) | 90 spawned_tests.append(test_info) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 parser.add_option('--image_path', | 138 parser.add_option('--image_path', |
136 help='Full path to the VM image. If none specified, ' | 139 help='Full path to the VM image. If none specified, ' |
137 'cros_run_vm_test will use the latest image.') | 140 'cros_run_vm_test will use the latest image.') |
138 parser.add_option('--order_output', action='store_true', default=False, | 141 parser.add_option('--order_output', action='store_true', default=False, |
139 help='Rather than emitting interleaved progress output ' | 142 help='Rather than emitting interleaved progress output ' |
140 'from the individual VMs, accumulate the outputs in ' | 143 'from the individual VMs, accumulate the outputs in ' |
141 'temporary files and dump them at the end.') | 144 'temporary files and dump them at the end.') |
142 parser.add_option('--results_dir_root', | 145 parser.add_option('--results_dir_root', |
143 help='Root results directory. If none specified, each test ' | 146 help='Root results directory. If none specified, each test ' |
144 'will store its results in a separate /tmp directory.') | 147 'will store its results in a separate /tmp directory.') |
| 148 parser.add_option('--use_emerged', action='store_true', default=False, |
| 149 help='Force use of emerged autotest packages') |
145 (options, args) = parser.parse_args() | 150 (options, args) = parser.parse_args() |
146 | 151 |
147 if not args: | 152 if not args: |
148 parser.print_help() | 153 parser.print_help() |
149 Die('no tests provided') | 154 Die('no tests provided') |
150 | 155 |
151 runner = ParallelTestRunner(args, options.base_ssh_port, options.board, | 156 runner = ParallelTestRunner(args, options.base_ssh_port, options.board, |
152 options.image_path, options.order_output, | 157 options.image_path, options.order_output, |
153 options.results_dir_root) | 158 options.results_dir_root, options.use_emerged) |
154 runner.Run() | 159 runner.Run() |
155 | 160 |
156 | 161 |
157 if __name__ == '__main__': | 162 if __name__ == '__main__': |
158 main() | 163 main() |
OLD | NEW |