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 psutil | 11 import psutil |
12 import signal | 12 import signal |
13 import shutil | 13 import shutil |
14 import time | 14 import time |
15 | 15 |
16 from pylib import android_commands | |
17 from pylib import cmd_helper | |
18 from pylib import constants | 16 from pylib import constants |
19 from pylib import forwarder | 17 from pylib import forwarder |
20 from pylib import ports | 18 from pylib.utils import test_environment |
21 | 19 |
22 import test_runner | 20 import test_runner |
23 | 21 |
24 | 22 |
25 def _KillPendingServers(): | |
26 for retry in range(5): | |
27 for server in ['lighttpd', 'web-page-replay']: | |
28 pids = [p.pid for p in psutil.process_iter() if server in p.name] | |
29 for pid in pids: | |
30 try: | |
31 logging.warning('Killing %s %s', server, pid) | |
32 os.kill(pid, signal.SIGQUIT) | |
33 except Exception as e: | |
34 logging.warning('Failed killing %s %s %s', server, pid, e) | |
35 # Restart the adb server with taskset to set a single CPU affinity. | |
36 cmd_helper.RunCmd([constants.ADB_PATH, 'kill-server']) | |
37 cmd_helper.RunCmd(['taskset', '-c', '0', constants.ADB_PATH, 'start-server']) | |
38 cmd_helper.RunCmd(['taskset', '-c', '0', constants.ADB_PATH, 'root']) | |
39 i = 1 | |
40 while not android_commands.GetAttachedDevices(): | |
41 time.sleep(i) | |
42 i *= 2 | |
43 if i > 10: | |
44 break | |
45 # Reset the test port allocation. It's important to do it before starting | |
46 # to dispatch any step. | |
47 if not ports.ResetTestServerPortAllocation(): | |
48 raise Exception('Failed to reset test server port.') | |
49 | |
50 forwarder.Forwarder.UseMultiprocessing() | |
51 | |
52 | |
53 def Setup(test_options): | 23 def Setup(test_options): |
54 """Create and return the test runner factory and tests. | 24 """Create and return the test runner factory and tests. |
55 | 25 |
56 Args: | 26 Args: |
57 test_options: A PerformanceOptions object. | 27 test_options: A PerformanceOptions object. |
58 | 28 |
59 Returns: | 29 Returns: |
60 A tuple of (TestRunnerFactory, tests). | 30 A tuple of (TestRunnerFactory, tests). |
61 """ | 31 """ |
62 # TODO(bulach): remove this once the bot side lands. BUG=318369 | 32 # TODO(bulach): remove this once the bot side lands. BUG=318369 |
63 constants.SetBuildType('Release') | 33 constants.SetBuildType('Release') |
64 if os.path.exists(constants.PERF_OUTPUT_DIR): | 34 if os.path.exists(constants.PERF_OUTPUT_DIR): |
65 shutil.rmtree(constants.PERF_OUTPUT_DIR) | 35 shutil.rmtree(constants.PERF_OUTPUT_DIR) |
66 os.makedirs(constants.PERF_OUTPUT_DIR) | 36 os.makedirs(constants.PERF_OUTPUT_DIR) |
67 | 37 |
68 # Before running the tests, kill any leftover server. | 38 # Before running the tests, kill any leftover server. |
69 _KillPendingServers() | 39 logging.info('Restarting adb and waiting for device.') |
| 40 test_environment.CleanupPendingProcesses(restart_adb_as_root=True) |
| 41 forwarder.Forwarder.UseMultiprocessing() |
70 | 42 |
71 if test_options.single_step: | 43 if test_options.single_step: |
72 # Running a single command, build the tests structure. | 44 # Running a single command, build the tests structure. |
73 tests = [['single_step', test_options.single_step]] | 45 tests = [['single_step', test_options.single_step]] |
74 | 46 |
75 if test_options.steps: | 47 if test_options.steps: |
76 with file(test_options.steps, 'r') as f: | 48 with file(test_options.steps, 'r') as f: |
77 tests = json.load(f) | 49 tests = json.load(f) |
78 | 50 |
79 # The list is necessary to keep the steps order, but internally | 51 # The list is necessary to keep the steps order, but internally |
(...skipping 11 matching lines...) Expand all Loading... |
91 flaky_steps = [] | 63 flaky_steps = [] |
92 if test_options.flaky_steps: | 64 if test_options.flaky_steps: |
93 with file(test_options.flaky_steps, 'r') as f: | 65 with file(test_options.flaky_steps, 'r') as f: |
94 flaky_steps = json.load(f) | 66 flaky_steps = json.load(f) |
95 | 67 |
96 def TestRunnerFactory(device, shard_index): | 68 def TestRunnerFactory(device, shard_index): |
97 return test_runner.TestRunner( | 69 return test_runner.TestRunner( |
98 test_options, device, tests_dict, flaky_steps) | 70 test_options, device, tests_dict, flaky_steps) |
99 | 71 |
100 return (TestRunnerFactory, sorted_test_names) | 72 return (TestRunnerFactory, sorted_test_names) |
OLD | NEW |