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
3 # found in the LICENSE file.
5 """Generates test runner factory and tests for performance tests."""
13 from devil
.android
import device_list
14 from devil
.android
import device_utils
15 from pylib
import constants
16 from pylib
.perf
import test_runner
17 from pylib
.utils
import test_environment
20 def _GetAllDevices(active_devices
):
21 devices_path
= os
.path
.join(os
.environ
.get('CHROMIUM_OUT_DIR', 'out'),
22 device_list
.LAST_DEVICES_FILENAME
)
24 devices
= [device_utils
.DeviceUtils(s
)
25 for s
in device_list
.GetPersistentDeviceList(devices_path
)]
27 logging
.error('Unable to find %s [%s]', devices_path
, e
)
28 devices
= active_devices
29 return sorted(devices
)
32 def _GetStepsDictFromSingleStep(test_options
):
33 # Running a single command, build the tests structure.
39 'cmd': test_options
.single_step
46 def _GetStepsDict(test_options
):
47 if test_options
.single_step
:
48 return _GetStepsDictFromSingleStep(test_options
)
49 if test_options
.steps
:
50 with
file(test_options
.steps
, 'r') as f
:
53 # Already using the new format.
54 assert steps
['version'] == 1
58 def Setup(test_options
, active_devices
):
59 """Create and return the test runner factory and tests.
62 test_options: A PerformanceOptions object.
65 A tuple of (TestRunnerFactory, tests, devices).
67 # TODO(bulach): remove this once the bot side lands. BUG=318369
68 constants
.SetBuildType('Release')
69 if os
.path
.exists(constants
.PERF_OUTPUT_DIR
):
70 shutil
.rmtree(constants
.PERF_OUTPUT_DIR
)
71 os
.makedirs(constants
.PERF_OUTPUT_DIR
)
73 # Before running the tests, kill any leftover server.
74 test_environment
.CleanupLeftoverProcesses(active_devices
)
76 # We want to keep device affinity, so return all devices ever seen.
77 all_devices
= _GetAllDevices(active_devices
)
79 steps_dict
= _GetStepsDict(test_options
)
80 sorted_step_names
= sorted(steps_dict
['steps'].keys())
82 if test_options
.test_filter
:
83 sorted_step_names
= fnmatch
.filter(sorted_step_names
,
84 test_options
.test_filter
)
87 if test_options
.flaky_steps
:
88 with
file(test_options
.flaky_steps
, 'r') as f
:
89 flaky_steps
= json
.load(f
)
91 def TestRunnerFactory(device
, shard_index
):
92 return test_runner
.TestRunner(
93 test_options
, device
, shard_index
, len(all_devices
),
94 steps_dict
, flaky_steps
)
96 return (TestRunnerFactory
, sorted_step_names
, all_devices
)