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 psutil |
| 11 import signal |
| 12 import time |
| 13 |
| 14 from pylib import android_commands |
| 15 from pylib import cmd_helper |
| 16 from pylib import forwarder |
| 17 from pylib import ports |
| 18 |
| 19 import test_runner |
| 20 |
| 21 |
| 22 def _KillPendingServers(): |
| 23 for retry in range(5): |
| 24 for server in ['lighttpd', 'web-page-replay']: |
| 25 pids = [p.pid for p in psutil.process_iter() if server in p.name] |
| 26 for pid in pids: |
| 27 try: |
| 28 logging.warning('Killing %s %s', server, pid) |
| 29 os.kill(pid, signal.SIGQUIT) |
| 30 except Exception as e: |
| 31 logging.warning('Failed killing %s %s %s', server, pid, e) |
| 32 # Restart the adb server with taskset to set a single CPU affinity. |
| 33 cmd_helper.RunCmd(['adb', 'kill-server']) |
| 34 cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'start-server']) |
| 35 cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'root']) |
| 36 i = 1 |
| 37 while not android_commands.GetAttachedDevices(): |
| 38 time.sleep(i) |
| 39 i *= 2 |
| 40 if i > 10: |
| 41 break |
| 42 # Reset the test port allocation. It's important to do it before starting |
| 43 # to dispatch any step. |
| 44 if not ports.ResetTestServerPortAllocation(): |
| 45 raise Exception('Failed to reset test server port.') |
| 46 |
| 47 forwarder.Forwarder.UseMultiprocessing() |
| 48 |
| 49 |
| 50 def Setup(test_options): |
| 51 """Create and return the test runner factory and tests. |
| 52 |
| 53 Args: |
| 54 test_options: A PerformanceOptions object. |
| 55 |
| 56 Returns: |
| 57 A tuple of (TestRunnerFactory, tests). |
| 58 """ |
| 59 # Before running the tests, kill any leftover server. |
| 60 _KillPendingServers() |
| 61 |
| 62 with file(test_options.steps, 'r') as f: |
| 63 tests = json.load(f) |
| 64 |
| 65 flaky_steps = [] |
| 66 if test_options.flaky_steps: |
| 67 with file(test_options.flaky_steps, 'r') as f: |
| 68 flaky_steps = json.load(f) |
| 69 |
| 70 def TestRunnerFactory(device, shard_index): |
| 71 return test_runner.TestRunner( |
| 72 test_options, device, tests, flaky_steps) |
| 73 |
| 74 return (TestRunnerFactory, sorted(tests.keys())) |
OLD | NEW |