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 logging |
10 import os | 10 import os |
11 import shutil | 11 import shutil |
12 | 12 |
13 from pylib import constants | 13 from pylib import constants |
14 from pylib import forwarder | 14 from pylib import forwarder |
15 from pylib.device import device_list | 15 from pylib.device import device_list |
16 from pylib.device import device_utils | 16 from pylib.device import device_utils |
17 from pylib.perf import test_runner | 17 from pylib.perf import test_runner |
18 from pylib.utils import test_environment | 18 from pylib.utils import test_environment |
19 | 19 |
20 | 20 |
21 def _GetAllDevices(): | 21 def _GetAllDevices(active_devices): |
22 devices_path = os.path.join(os.environ.get('CHROMIUM_OUT_DIR', 'out'), | 22 devices_path = os.path.join(os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
23 device_list.LAST_DEVICES_FILENAME) | 23 device_list.LAST_DEVICES_FILENAME) |
24 try: | 24 try: |
25 devices = [device_utils.DeviceUtils(s) | 25 devices = [device_utils.DeviceUtils(s) |
26 for s in device_list.GetPersistentDeviceList(devices_path)] | 26 for s in device_list.GetPersistentDeviceList(devices_path)] |
27 except IOError as e: | 27 except IOError as e: |
28 logging.error('Unable to find %s [%s]', devices_path, e) | 28 logging.error('Unable to find %s [%s]', devices_path, e) |
29 devices = device_utils.DeviceUtils.HealthyDevices() | 29 devices = active_devices |
30 return sorted(devices) | 30 return sorted(devices) |
31 | 31 |
32 | 32 |
33 def _GetStepsDictFromSingleStep(test_options): | 33 def _GetStepsDictFromSingleStep(test_options): |
34 # Running a single command, build the tests structure. | 34 # Running a single command, build the tests structure. |
35 steps_dict = { | 35 steps_dict = { |
36 'version': 1, | 36 'version': 1, |
37 'steps': { | 37 'steps': { |
38 'single_step': { | 38 'single_step': { |
39 'device_affinity': 0, | 39 'device_affinity': 0, |
40 'cmd': test_options.single_step | 40 'cmd': test_options.single_step |
41 }, | 41 }, |
42 } | 42 } |
43 } | 43 } |
44 return steps_dict | 44 return steps_dict |
45 | 45 |
46 | 46 |
47 def _GetStepsDict(test_options): | 47 def _GetStepsDict(test_options): |
48 if test_options.single_step: | 48 if test_options.single_step: |
49 return _GetStepsDictFromSingleStep(test_options) | 49 return _GetStepsDictFromSingleStep(test_options) |
50 if test_options.steps: | 50 if test_options.steps: |
51 with file(test_options.steps, 'r') as f: | 51 with file(test_options.steps, 'r') as f: |
52 steps = json.load(f) | 52 steps = json.load(f) |
53 | 53 |
54 # Already using the new format. | 54 # Already using the new format. |
55 assert steps['version'] == 1 | 55 assert steps['version'] == 1 |
56 return steps | 56 return steps |
57 | 57 |
58 | 58 |
59 def Setup(test_options): | 59 def Setup(test_options, active_devices): |
60 """Create and return the test runner factory and tests. | 60 """Create and return the test runner factory and tests. |
61 | 61 |
62 Args: | 62 Args: |
63 test_options: A PerformanceOptions object. | 63 test_options: A PerformanceOptions object. |
64 | 64 |
65 Returns: | 65 Returns: |
66 A tuple of (TestRunnerFactory, tests, devices). | 66 A tuple of (TestRunnerFactory, tests, devices). |
67 """ | 67 """ |
68 # TODO(bulach): remove this once the bot side lands. BUG=318369 | 68 # TODO(bulach): remove this once the bot side lands. BUG=318369 |
69 constants.SetBuildType('Release') | 69 constants.SetBuildType('Release') |
70 if os.path.exists(constants.PERF_OUTPUT_DIR): | 70 if os.path.exists(constants.PERF_OUTPUT_DIR): |
71 shutil.rmtree(constants.PERF_OUTPUT_DIR) | 71 shutil.rmtree(constants.PERF_OUTPUT_DIR) |
72 os.makedirs(constants.PERF_OUTPUT_DIR) | 72 os.makedirs(constants.PERF_OUTPUT_DIR) |
73 | 73 |
74 # Before running the tests, kill any leftover server. | 74 # Before running the tests, kill any leftover server. |
75 test_environment.CleanupLeftoverProcesses() | 75 test_environment.CleanupLeftoverProcesses(active_devices) |
76 | 76 |
77 # We want to keep device affinity, so return all devices ever seen. | 77 # We want to keep device affinity, so return all devices ever seen. |
78 all_devices = _GetAllDevices() | 78 all_devices = _GetAllDevices(active_devices) |
79 | 79 |
80 steps_dict = _GetStepsDict(test_options) | 80 steps_dict = _GetStepsDict(test_options) |
81 sorted_step_names = sorted(steps_dict['steps'].keys()) | 81 sorted_step_names = sorted(steps_dict['steps'].keys()) |
82 | 82 |
83 if test_options.test_filter: | 83 if test_options.test_filter: |
84 sorted_step_names = fnmatch.filter(sorted_step_names, | 84 sorted_step_names = fnmatch.filter(sorted_step_names, |
85 test_options.test_filter) | 85 test_options.test_filter) |
86 | 86 |
87 flaky_steps = [] | 87 flaky_steps = [] |
88 if test_options.flaky_steps: | 88 if test_options.flaky_steps: |
89 with file(test_options.flaky_steps, 'r') as f: | 89 with file(test_options.flaky_steps, 'r') as f: |
90 flaky_steps = json.load(f) | 90 flaky_steps = json.load(f) |
91 | 91 |
92 def TestRunnerFactory(device, shard_index): | 92 def TestRunnerFactory(device, shard_index): |
93 return test_runner.TestRunner( | 93 return test_runner.TestRunner( |
94 test_options, device, shard_index, len(all_devices), | 94 test_options, device, shard_index, len(all_devices), |
95 steps_dict, flaky_steps) | 95 steps_dict, flaky_steps) |
96 | 96 |
97 return (TestRunnerFactory, sorted_step_names, all_devices) | 97 return (TestRunnerFactory, sorted_step_names, all_devices) |
OLD | NEW |