[Telemetry] Refactor common Android test harness functions.
This is a reland of crrev.com/62953024 which was reverted because it broke other platforms. Refactoring common cleanup code required by both android_browser_finder.py and perf/setup.py and moving it into pyblib/utils/test_environment.py. Also, this change avoids killing twice the adb server when running in a bot environment, where the adb restart is already invoked by the bot steps. BUG=268450 R=bulach@chromium.org,tonyg@chromium.org Review URL: https://codereview.chromium.org/94683002 git-svn-id: http://src.chromium.org/svn/trunk/src/build@237815 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
25702cbdfb
Коммит
a00b91d193
|
@ -510,7 +510,9 @@ class AndroidCommands(object):
|
|||
while retry < 3:
|
||||
ret = cmd_helper.RunCmd(['pgrep', 'adb'])
|
||||
if ret == 0:
|
||||
# pgrep fonud adb, start-server succeeded.
|
||||
# pgrep found adb, start-server succeeded.
|
||||
# Waiting for device to reconnect before returning success.
|
||||
self._adb.SendCommand('wait-for-device')
|
||||
return 0
|
||||
retry += 1
|
||||
time.sleep(retry)
|
||||
|
|
|
@ -13,39 +13,13 @@ import signal
|
|||
import shutil
|
||||
import time
|
||||
|
||||
from pylib import android_commands
|
||||
from pylib import cmd_helper
|
||||
from pylib import constants
|
||||
from pylib import forwarder
|
||||
from pylib import ports
|
||||
from pylib.utils import test_environment
|
||||
|
||||
import test_runner
|
||||
|
||||
|
||||
def _KillPendingServers():
|
||||
for retry in range(5):
|
||||
for server in ['lighttpd', 'web-page-replay']:
|
||||
pids = [p.pid for p in psutil.process_iter() if server in p.name]
|
||||
for pid in pids:
|
||||
try:
|
||||
logging.warning('Killing %s %s', server, pid)
|
||||
os.kill(pid, signal.SIGQUIT)
|
||||
except Exception as e:
|
||||
logging.warning('Failed killing %s %s %s', server, pid, e)
|
||||
# Restart the adb server with taskset to set a single CPU affinity.
|
||||
cmd_helper.RunCmd([constants.ADB_PATH, 'kill-server'])
|
||||
cmd_helper.RunCmd(['taskset', '-c', '0', constants.ADB_PATH, 'start-server'])
|
||||
cmd_helper.RunCmd(['taskset', '-c', '0', constants.ADB_PATH, 'root'])
|
||||
i = 1
|
||||
while not android_commands.GetAttachedDevices():
|
||||
time.sleep(i)
|
||||
i *= 2
|
||||
if i > 10:
|
||||
break
|
||||
|
||||
forwarder.Forwarder.UseMultiprocessing()
|
||||
|
||||
|
||||
def Setup(test_options):
|
||||
"""Create and return the test runner factory and tests.
|
||||
|
||||
|
@ -62,7 +36,8 @@ def Setup(test_options):
|
|||
os.makedirs(constants.PERF_OUTPUT_DIR)
|
||||
|
||||
# Before running the tests, kill any leftover server.
|
||||
_KillPendingServers()
|
||||
test_environment.CleanupLeftoverProcesses()
|
||||
forwarder.Forwarder.UseMultiprocessing()
|
||||
|
||||
if test_options.single_step:
|
||||
# Running a single command, build the tests structure.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright 2013 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import psutil
|
||||
|
||||
from pylib import android_commands
|
||||
|
||||
def _KillWebServers():
|
||||
for retry in xrange(5):
|
||||
for server in ['lighttpd', 'web-page-replay']:
|
||||
pids = [p.pid for p in psutil.process_iter() if server in p.name]
|
||||
for pid in pids:
|
||||
try:
|
||||
logging.warning('Killing %s %s', server, pid)
|
||||
os.kill(pid, signal.SIGQUIT)
|
||||
except Exception as e:
|
||||
logging.warning('Failed killing %s %s %s', server, pid, e)
|
||||
|
||||
|
||||
def CleanupLeftoverProcesses():
|
||||
"""Clean up the test environment, restarting fresh adb and HTTP daemons."""
|
||||
_KillWebServers()
|
||||
did_restart_host_adb = False
|
||||
for device in android_commands.GetAttachedDevices():
|
||||
adb = android_commands.AndroidCommands(device)
|
||||
# Make sure we restart the host adb server only once.
|
||||
if not did_restart_host_adb:
|
||||
adb.RestartAdbServer()
|
||||
did_restart_host_adb = True
|
||||
adb.RestartAdbdOnDevice()
|
||||
adb.EnableAdbRoot()
|
||||
adb.WaitForDevicePm()
|
Загрузка…
Ссылка в новой задаче