Chromium Code Reviews| Index: build/android/pylib/perf/setup.py |
| diff --git a/build/android/pylib/perf/setup.py b/build/android/pylib/perf/setup.py |
| index cf844560f00c944a178ff4d0858e8afc436003ab..85858d674760738ada57d0675ac12322f1006792 100644 |
| --- a/build/android/pylib/perf/setup.py |
| +++ b/build/android/pylib/perf/setup.py |
| @@ -6,15 +6,74 @@ |
| import json |
| import fnmatch |
| +import logging |
| import os |
| import shutil |
| +from pylib import android_commands |
| from pylib import constants |
| from pylib import forwarder |
| from pylib.perf import test_runner |
| from pylib.utils import test_environment |
| +def _GetAllDevices(): |
| + out_dir = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
| + devices_path = os.path.join(out_dir, '.last_devices') |
|
jbudorick
2014/05/29 19:45:25
Where does the .last_devices file come from?
bulach
2014/05/30 09:21:26
good point! I did some changes in buildbot/bb_devi
|
| + devices = [] |
| + try: |
| + with open(devices_path) as f: |
| + devices = f.read().splitlines() |
|
jbudorick
2014/05/29 19:45:25
I'm concerned about how the tests will behave if t
bulach
2014/05/30 09:21:26
sorry, my bad! :) I should've given more context h
|
| + except IOError as e: |
| + logging.error('Unable to find .last_devices [%s]', e) |
| + devices = android_commands.GetAttachedDevices() |
| + return sorted(devices) |
| + |
| + |
| +def _GetStepsDictFromSingleStep(test_options): |
| + # Running a single command, build the tests structure. |
| + steps_dict = { |
| + 'version': 1, |
| + 'steps': { |
| + 'single_step': { |
| + 'device_affinity': 0, |
| + 'cmd': test_options.single_step |
| + }, |
| + } |
| + } |
| + return steps_dict |
| + |
| +# TODO(bulach): remove once it rolls downstream, crbug.com/378862. |
| +def _GetStepsDictFromV0(steps_v0): |
| + steps_dict = { |
| + 'version': 1, |
| + 'steps': {}, |
| + } |
| + affinity = 0 |
| + for step in steps_v0: |
| + steps_dict['steps'][step[0]] = { |
| + 'device_affinity': affinity, |
| + 'cmd': step[1], |
| + } |
| + affinity += 1 |
| + return steps_dict |
| + |
| + |
| +def _GetStepsDict(test_options): |
| + if test_options.single_step: |
| + return _GetStepsDictFromSingleStep(test_options) |
| + if test_options.steps: |
| + with file(test_options.steps, 'r') as f: |
| + steps = json.load(f) |
| + # TODO(bulach): remove once it rolls downstream, crbug.com/378862. |
| + if isinstance(steps, list): |
| + return _GetStepsDictFromV0(steps) |
| + |
| + # Already using the new format. |
| + assert steps['version'] == 1 |
| + return steps |
| + |
| + |
| def Setup(test_options): |
| """Create and return the test runner factory and tests. |
| @@ -22,7 +81,7 @@ def Setup(test_options): |
| test_options: A PerformanceOptions object. |
| Returns: |
| - A tuple of (TestRunnerFactory, tests). |
| + A tuple of (TestRunnerFactory, tests, devices). |
| """ |
| # TODO(bulach): remove this once the bot side lands. BUG=318369 |
| constants.SetBuildType('Release') |
| @@ -34,33 +93,24 @@ def Setup(test_options): |
| test_environment.CleanupLeftoverProcesses() |
| forwarder.Forwarder.UseMultiprocessing() |
| - if test_options.single_step: |
| - # Running a single command, build the tests structure. |
| - tests = [['single_step', test_options.single_step]] |
| - |
| - if test_options.steps: |
| - with file(test_options.steps, 'r') as f: |
| - tests = json.load(f) |
| + # We want to keep device affinity, so return all devices ever seen. |
| + all_devices = _GetAllDevices() |
| - # The list is necessary to keep the steps order, but internally |
| - # the format is squashed from a list of lists into a single dict: |
| - # [["A", "cmd"], ["B", "cmd"]] into {"A": "cmd", "B": "cmd"} |
| - sorted_test_names = [i[0] for i in tests] |
| - tests_dict = dict(tests) |
| + steps_dict = _GetStepsDict(test_options) |
| + sorted_step_names = sorted(steps_dict['steps'].keys()) |
| if test_options.test_filter: |
| - sorted_test_names = fnmatch.filter(sorted_test_names, |
| + sorted_step_names = fnmatch.filter(sorted_step_names, |
| test_options.test_filter) |
| - tests_dict = dict((k, v) for k, v in tests_dict.iteritems() |
| - if k in sorted_test_names) |
| flaky_steps = [] |
| if test_options.flaky_steps: |
| with file(test_options.flaky_steps, 'r') as f: |
| flaky_steps = json.load(f) |
| - def TestRunnerFactory(device, _shard_index): |
| + def TestRunnerFactory(device, shard_index): |
| return test_runner.TestRunner( |
| - test_options, device, tests_dict, flaky_steps) |
| + test_options, device, shard_index, len(all_devices), |
| + steps_dict, flaky_steps) |
| - return (TestRunnerFactory, sorted_test_names) |
| + return (TestRunnerFactory, sorted_step_names, all_devices) |