Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: build/android/pylib/android_commands.py

Issue 32163002: Relands Android perf tests: kill adbd on the device after running a test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | build/android/pylib/perf/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 """Provides an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 9
10 import collections 10 import collections
11 import datetime 11 import datetime
12 import logging 12 import logging
13 import os 13 import os
14 import re 14 import re
15 import shlex 15 import shlex
16 import signal
16 import subprocess 17 import subprocess
17 import sys 18 import sys
18 import tempfile 19 import tempfile
19 import time 20 import time
20 21
21 import cmd_helper 22 import cmd_helper
22 import constants 23 import constants
23 try: 24 try:
24 from pylib import pexpect 25 from pylib import pexpect
25 except: 26 except:
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 # Force a hard reboot on last attempt 452 # Force a hard reboot on last attempt
452 self.Reboot(full_reboot=(reboots_left == 1)) 453 self.Reboot(full_reboot=(reboots_left == 1))
453 reboots_left -= 1 454 reboots_left -= 1
454 455
455 def MakeSystemFolderWritable(self): 456 def MakeSystemFolderWritable(self):
456 """Remounts the /system folder rw.""" 457 """Remounts the /system folder rw."""
457 out = self._adb.SendCommand('remount') 458 out = self._adb.SendCommand('remount')
458 if out.strip() != 'remount succeeded': 459 if out.strip() != 'remount succeeded':
459 raise errors.MsgException('Remount failed: %s' % out) 460 raise errors.MsgException('Remount failed: %s' % out)
460 461
462 def RestartAdbdOnDevice(self):
463 logging.info('Killing adbd on the device...')
464 adb_pids = self.KillAll('adbd', signal=signal.SIGTERM, with_su=True)
465 assert adb_pids, 'Unable to obtain adbd pid'
466 logging.info('Waiting for device to settle...')
467 self._adb.SendCommand('wait-for-device')
468
461 def RestartAdbServer(self): 469 def RestartAdbServer(self):
462 """Restart the adb server.""" 470 """Restart the adb server."""
463 ret = self.KillAdbServer() 471 ret = self.KillAdbServer()
464 if ret != 0: 472 if ret != 0:
465 raise errors.MsgException('KillAdbServer: %d' % ret) 473 raise errors.MsgException('KillAdbServer: %d' % ret)
466 474
467 ret = self.StartAdbServer() 475 ret = self.StartAdbServer()
468 if ret != 0: 476 if ret != 0:
469 raise errors.MsgException('StartAdbServer: %d' % ret) 477 raise errors.MsgException('StartAdbServer: %d' % ret)
470 478
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 last_line = lines[-1] 597 last_line = lines[-1]
590 status_pos = last_line.rfind('%') 598 status_pos = last_line.rfind('%')
591 assert status_pos >= 0 599 assert status_pos >= 0
592 status = int(last_line[status_pos + 1:]) 600 status = int(last_line[status_pos + 1:])
593 if status_pos == 0: 601 if status_pos == 0:
594 lines = lines[:-1] 602 lines = lines[:-1]
595 else: 603 else:
596 lines = lines[:-1] + [last_line[:status_pos]] 604 lines = lines[:-1] + [last_line[:status_pos]]
597 return (status, lines) 605 return (status, lines)
598 606
599 def KillAll(self, process): 607 def KillAll(self, process, signal=9, with_su=False):
600 """Android version of killall, connected via adb. 608 """Android version of killall, connected via adb.
601 609
602 Args: 610 Args:
603 process: name of the process to kill off 611 process: name of the process to kill off.
612 signal: signal to use, 9 (SIGKILL) by default.
613 with_su: wether or not to use su to kill the processes.
604 614
605 Returns: 615 Returns:
606 the number of processes killed 616 the number of processes killed
607 """ 617 """
608 pids = self.ExtractPid(process) 618 pids = self.ExtractPid(process)
609 if pids: 619 if pids:
610 self.RunShellCommand('kill -9 ' + ' '.join(pids)) 620 cmd = 'kill -%d %s' % (signal, ' '.join(pids))
621 if with_su:
622 self.RunShellCommandWithSU(cmd)
623 else:
624 self.RunShellCommand(cmd)
611 return len(pids) 625 return len(pids)
612 626
613 def KillAllBlocking(self, process, timeout_sec): 627 def KillAllBlocking(self, process, timeout_sec):
614 """Blocking version of killall, connected via adb. 628 """Blocking version of killall, connected via adb.
615 629
616 This waits until no process matching the corresponding name appears in ps' 630 This waits until no process matching the corresponding name appears in ps'
617 output anymore. 631 output anymore.
618 632
619 Args: 633 Args:
620 process: name of the process to kill off 634 process: name of the process to kill off
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 """ 1655 """
1642 def __init__(self, output): 1656 def __init__(self, output):
1643 self._output = output 1657 self._output = output
1644 1658
1645 def write(self, data): 1659 def write(self, data):
1646 data = data.replace('\r\r\n', '\n') 1660 data = data.replace('\r\r\n', '\n')
1647 self._output.write(data) 1661 self._output.write(data)
1648 1662
1649 def flush(self): 1663 def flush(self):
1650 self._output.flush() 1664 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/perf/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698