OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Generates test runner factory and tests for performance tests.""" | 5 """Generates test runner factory and tests for performance tests.""" |
6 | 6 |
7 import json | 7 import json |
8 import fnmatch | 8 import fnmatch |
9 import logging | |
9 import os | 10 import os |
10 import shutil | 11 import shutil |
11 | 12 |
13 from pylib import android_commands | |
12 from pylib import constants | 14 from pylib import constants |
13 from pylib import forwarder | 15 from pylib import forwarder |
16 from pylib.device import device_list | |
14 from pylib.perf import test_runner | 17 from pylib.perf import test_runner |
15 from pylib.utils import test_environment | 18 from pylib.utils import test_environment |
16 | 19 |
17 | 20 |
21 def _GetAllDevices(): | |
22 devices_path = os.path.join(os.environ.get('CHROMIUM_OUT_DIR', 'out'), | |
23 device_list.LAST_DEVICES_FILENAME) | |
24 try: | |
25 devices = device_list.GetDeviceList(devices_path) | |
26 except IOError as e: | |
27 logging.error('Unable to find %s [%s]', devices_path, e) | |
jbudorick
2014/06/03 13:52:52
Your GetDeviceList function eats all of the IOErro
bulach
2014/06/03 14:25:52
good catch! yeah, the exception shouldn't be handl
| |
28 devices = android_commands.GetAttachedDevices() | |
29 return sorted(devices) | |
30 | |
31 | |
32 def _GetStepsDictFromSingleStep(test_options): | |
33 # Running a single command, build the tests structure. | |
34 steps_dict = { | |
35 'version': 1, | |
36 'steps': { | |
37 'single_step': { | |
38 'device_affinity': 0, | |
39 'cmd': test_options.single_step | |
40 }, | |
41 } | |
42 } | |
43 return steps_dict | |
44 | |
45 # TODO(bulach): remove once it rolls downstream, crbug.com/378862. | |
46 def _GetStepsDictFromV0(steps_v0): | |
47 steps_dict = { | |
48 'version': 1, | |
49 'steps': {}, | |
50 } | |
51 affinity = 0 | |
52 for step in steps_v0: | |
53 steps_dict['steps'][step[0]] = { | |
54 'device_affinity': affinity, | |
55 'cmd': step[1], | |
56 } | |
57 affinity += 1 | |
58 return steps_dict | |
59 | |
60 | |
61 def _GetStepsDict(test_options): | |
62 if test_options.single_step: | |
63 return _GetStepsDictFromSingleStep(test_options) | |
64 if test_options.steps: | |
65 with file(test_options.steps, 'r') as f: | |
66 steps = json.load(f) | |
67 # TODO(bulach): remove once it rolls downstream, crbug.com/378862. | |
68 if isinstance(steps, list): | |
69 return _GetStepsDictFromV0(steps) | |
70 | |
71 # Already using the new format. | |
72 assert steps['version'] == 1 | |
73 return steps | |
74 | |
75 | |
18 def Setup(test_options): | 76 def Setup(test_options): |
19 """Create and return the test runner factory and tests. | 77 """Create and return the test runner factory and tests. |
20 | 78 |
21 Args: | 79 Args: |
22 test_options: A PerformanceOptions object. | 80 test_options: A PerformanceOptions object. |
23 | 81 |
24 Returns: | 82 Returns: |
25 A tuple of (TestRunnerFactory, tests). | 83 A tuple of (TestRunnerFactory, tests, devices). |
26 """ | 84 """ |
27 # TODO(bulach): remove this once the bot side lands. BUG=318369 | 85 # TODO(bulach): remove this once the bot side lands. BUG=318369 |
28 constants.SetBuildType('Release') | 86 constants.SetBuildType('Release') |
29 if os.path.exists(constants.PERF_OUTPUT_DIR): | 87 if os.path.exists(constants.PERF_OUTPUT_DIR): |
30 shutil.rmtree(constants.PERF_OUTPUT_DIR) | 88 shutil.rmtree(constants.PERF_OUTPUT_DIR) |
31 os.makedirs(constants.PERF_OUTPUT_DIR) | 89 os.makedirs(constants.PERF_OUTPUT_DIR) |
32 | 90 |
33 # Before running the tests, kill any leftover server. | 91 # Before running the tests, kill any leftover server. |
34 test_environment.CleanupLeftoverProcesses() | 92 test_environment.CleanupLeftoverProcesses() |
35 forwarder.Forwarder.UseMultiprocessing() | 93 forwarder.Forwarder.UseMultiprocessing() |
36 | 94 |
37 if test_options.single_step: | 95 # We want to keep device affinity, so return all devices ever seen. |
38 # Running a single command, build the tests structure. | 96 all_devices = _GetAllDevices() |
39 tests = [['single_step', test_options.single_step]] | |
40 | 97 |
41 if test_options.steps: | 98 steps_dict = _GetStepsDict(test_options) |
42 with file(test_options.steps, 'r') as f: | 99 sorted_step_names = sorted(steps_dict['steps'].keys()) |
43 tests = json.load(f) | |
44 | |
45 # The list is necessary to keep the steps order, but internally | |
46 # the format is squashed from a list of lists into a single dict: | |
47 # [["A", "cmd"], ["B", "cmd"]] into {"A": "cmd", "B": "cmd"} | |
48 sorted_test_names = [i[0] for i in tests] | |
49 tests_dict = dict(tests) | |
50 | 100 |
51 if test_options.test_filter: | 101 if test_options.test_filter: |
52 sorted_test_names = fnmatch.filter(sorted_test_names, | 102 sorted_step_names = fnmatch.filter(sorted_step_names, |
53 test_options.test_filter) | 103 test_options.test_filter) |
54 tests_dict = dict((k, v) for k, v in tests_dict.iteritems() | |
55 if k in sorted_test_names) | |
56 | 104 |
57 flaky_steps = [] | 105 flaky_steps = [] |
58 if test_options.flaky_steps: | 106 if test_options.flaky_steps: |
59 with file(test_options.flaky_steps, 'r') as f: | 107 with file(test_options.flaky_steps, 'r') as f: |
60 flaky_steps = json.load(f) | 108 flaky_steps = json.load(f) |
61 | 109 |
62 def TestRunnerFactory(device, _shard_index): | 110 def TestRunnerFactory(device, shard_index): |
63 return test_runner.TestRunner( | 111 return test_runner.TestRunner( |
64 test_options, device, tests_dict, flaky_steps) | 112 test_options, device, shard_index, len(all_devices), |
113 steps_dict, flaky_steps) | |
65 | 114 |
66 return (TestRunnerFactory, sorted_test_names) | 115 return (TestRunnerFactory, sorted_step_names, all_devices) |
OLD | NEW |