OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 """Generates test runner factory and tests for performance tests.""" | |
6 | |
7 import json | |
8 import logging | |
9 import os | |
10 import signal | |
11 import test_runner | |
12 | |
13 from pylib import android_commands | |
14 from pylib import cmd_helper | |
15 from pylib import forwarder | |
16 from pylib import ports | |
17 | |
18 | |
19 def _KillPendingServers(): | |
20 for retry in range(5): | |
21 for server in ['lighttpd', 'web-page-replay']: | |
22 pids = cmd_helper.GetCmdOutput(['pgrep', '-f', server]) | |
frankf
2013/08/12 23:09:52
Can you use psutil: http://stackoverflow.com/a/423
bulach
2013/08/13 08:58:19
Done.
| |
23 pids = [pid.strip() for pid in pids.split('\n') if pid.strip()] | |
24 for pid in pids: | |
25 try: | |
26 logging.warning('Killing %s %s', server, pid) | |
27 os.kill(int(pid), signal.SIGQUIT) | |
28 except Exception as e: | |
29 logging.warning('Failed killing %s %s %s', server, pid, e) | |
30 # Restart the adb server with taskset to set a single CPU affinity. | |
31 cmd_helper.RunCmd(['adb', 'kill-server']) | |
32 cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'start-server']) | |
frankf
2013/08/12 23:09:52
Are we going to eventually do this in general for
bulach
2013/08/13 08:58:19
potentially, yes.. but maybe best to start here, t
| |
33 cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'root']) | |
34 i = 1 | |
35 while not android_commands.GetAttachedDevices(): | |
36 time.sleep(i) | |
37 i *= 2 | |
38 if i > 10: | |
39 break | |
40 # Reset the test port allocation. It's important to do it before starting | |
41 # to dispatch any step. | |
42 if not ports.ResetTestServerPortAllocation(): | |
frankf
2013/08/12 23:09:52
Currently we call this from bunch of places:
For g
bulach
2013/08/13 08:58:19
since there's already two other places, would you
| |
43 raise Exception('Failed to reset test server port.') | |
44 | |
45 forwarder.Forwarder.UseMultiprocessing() | |
frankf
2013/08/12 23:09:52
This is now multi-threading. Can we get rid of thi
bulach
2013/08/13 08:58:19
unfortunately not, it's multi-threading only on th
| |
46 | |
47 | |
48 def Setup(test_options): | |
49 """Create and return the test runner factory and tests. | |
50 | |
51 Args: | |
52 test_options: A PerformanceOptions object. | |
53 | |
54 Returns: | |
55 A tuple of (TestRunnerFactory, tests). | |
56 """ | |
57 # Just print the results from a single previously executed step. | |
58 if test_options.print_step: | |
59 def TestRunnerPrinterFactory(device, shard_index): | |
60 return test_runner.TestPrinter(test_options, device, shard_index) | |
frankf
2013/08/13 00:43:12
Also, it's really weird to have the printing logic
bulach
2013/08/13 08:58:19
yeah, I fully agree this is a bizarre shoehorning.
| |
61 return (TestRunnerPrinterFactory, [test_options.print_step]) | |
62 | |
63 # Before running the tests, kill any leftover server. | |
64 _KillPendingServers() | |
65 | |
66 with file(test_options.steps, 'r') as f: | |
67 tests = json.load(f) | |
68 | |
69 flaky_steps = [] | |
70 if test_options.flaky_steps: | |
71 with file(test_options.flaky_steps, 'r') as f: | |
72 flaky_steps = json.load(f) | |
73 | |
74 def TestRunnerFactory(device, shard_index): | |
75 return test_runner.TestRunner( | |
76 test_options, device, shard_index, tests, flaky_steps) | |
77 | |
78 return (TestRunnerFactory, sorted(tests.keys())) | |
frankf
2013/08/12 23:09:52
Any reasons to sort the tests given you don't sort
bulach
2013/08/13 08:58:19
that's actually a good point. I added "sorted" in
| |
OLD | NEW |