OLD | NEW |
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 |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 self.RunShellCommand('pm clear ' + package) | 665 self.RunShellCommand('pm clear ' + package) |
666 | 666 |
667 def SendKeyEvent(self, keycode): | 667 def SendKeyEvent(self, keycode): |
668 """Sends keycode to the device. | 668 """Sends keycode to the device. |
669 | 669 |
670 Args: | 670 Args: |
671 keycode: Numeric keycode to send (see "enum" at top of file). | 671 keycode: Numeric keycode to send (see "enum" at top of file). |
672 """ | 672 """ |
673 self.RunShellCommand('input keyevent %d' % keycode) | 673 self.RunShellCommand('input keyevent %d' % keycode) |
674 | 674 |
675 def CheckMd5Sum(self, local_path, device_path): | 675 def CheckMd5Sum(self, local_path, device_path, ignore_paths=False): |
| 676 """Compares the md5sum of a local path against a device path. |
| 677 |
| 678 Args: |
| 679 local_path: Path (file or directory) on the host. |
| 680 device_path: Path on the device. |
| 681 ignore_paths: If False, both the md5sum and the relative paths/names of |
| 682 files must match. If True, only the md5sum must match. |
| 683 |
| 684 Returns: |
| 685 True if the md5sums match. |
| 686 """ |
676 assert os.path.exists(local_path), 'Local path not found %s' % local_path | 687 assert os.path.exists(local_path), 'Local path not found %s' % local_path |
677 | 688 |
678 if not self._md5sum_build_dir: | 689 if not self._md5sum_build_dir: |
679 default_build_type = os.environ.get('BUILD_TYPE', 'Debug') | 690 default_build_type = os.environ.get('BUILD_TYPE', 'Debug') |
680 build_dir = '%s/%s/' % ( | 691 build_dir = '%s/%s/' % ( |
681 cmd_helper.OutDirectory().get(), default_build_type) | 692 cmd_helper.OutDirectory().get(), default_build_type) |
682 md5sum_dist_path = '%s/md5sum_dist' % build_dir | 693 md5sum_dist_path = '%s/md5sum_dist' % build_dir |
683 if not os.path.exists(md5sum_dist_path): | 694 if not os.path.exists(md5sum_dist_path): |
684 build_dir = '%s/Release/' % cmd_helper.OutDirectory().get() | 695 build_dir = '%s/Release/' % cmd_helper.OutDirectory().get() |
685 md5sum_dist_path = '%s/md5sum_dist' % build_dir | 696 md5sum_dist_path = '%s/md5sum_dist' % build_dir |
686 assert os.path.exists(md5sum_dist_path), 'Please build md5sum.' | 697 assert os.path.exists(md5sum_dist_path), 'Please build md5sum.' |
687 command = 'push %s %s' % (md5sum_dist_path, MD5SUM_DEVICE_FOLDER) | 698 command = 'push %s %s' % (md5sum_dist_path, MD5SUM_DEVICE_FOLDER) |
688 assert _HasAdbPushSucceeded(self._adb.SendCommand(command)) | 699 assert _HasAdbPushSucceeded(self._adb.SendCommand(command)) |
689 self._md5sum_build_dir = build_dir | 700 self._md5sum_build_dir = build_dir |
690 | 701 |
691 self._pushed_files.append(device_path) | 702 self._pushed_files.append(device_path) |
692 hashes_on_device = _ComputeFileListHash( | 703 hashes_on_device = _ComputeFileListHash( |
693 self.RunShellCommand(MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper + | 704 self.RunShellCommand(MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper + |
694 ' ' + MD5SUM_DEVICE_PATH + ' ' + device_path)) | 705 ' ' + MD5SUM_DEVICE_PATH + ' ' + device_path)) |
695 assert os.path.exists(local_path), 'Local path not found %s' % local_path | 706 assert os.path.exists(local_path), 'Local path not found %s' % local_path |
696 md5sum_output = cmd_helper.GetCmdOutput( | 707 md5sum_output = cmd_helper.GetCmdOutput( |
697 ['%s/md5sum_bin_host' % self._md5sum_build_dir, local_path]) | 708 ['%s/md5sum_bin_host' % self._md5sum_build_dir, local_path]) |
698 hashes_on_host = _ComputeFileListHash(md5sum_output.splitlines()) | 709 hashes_on_host = _ComputeFileListHash(md5sum_output.splitlines()) |
699 | 710 |
| 711 if ignore_paths: |
| 712 hashes_on_device = [h.split()[0] for h in hashes_on_device] |
| 713 hashes_on_host = [h.split()[0] for h in hashes_on_host] |
| 714 |
700 return hashes_on_device == hashes_on_host | 715 return hashes_on_device == hashes_on_host |
701 | 716 |
702 def PushIfNeeded(self, local_path, device_path): | 717 def PushIfNeeded(self, local_path, device_path): |
703 """Pushes |local_path| to |device_path|. | 718 """Pushes |local_path| to |device_path|. |
704 | 719 |
705 Works for files and directories. This method skips copying any paths in | 720 Works for files and directories. This method skips copying any paths in |
706 |test_data_paths| that already exist on the device with the same hash. | 721 |test_data_paths| that already exist on the device with the same hash. |
707 | 722 |
708 All pushed files can be removed by calling RemovePushedFiles(). | 723 All pushed files can be removed by calling RemovePushedFiles(). |
709 """ | 724 """ |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 """ | 1312 """ |
1298 def __init__(self, output): | 1313 def __init__(self, output): |
1299 self._output = output | 1314 self._output = output |
1300 | 1315 |
1301 def write(self, data): | 1316 def write(self, data): |
1302 data = data.replace('\r\r\n', '\n') | 1317 data = data.replace('\r\r\n', '\n') |
1303 self._output.write(data) | 1318 self._output.write(data) |
1304 | 1319 |
1305 def flush(self): | 1320 def flush(self): |
1306 self._output.flush() | 1321 self._output.flush() |
OLD | NEW |