コード例 #1
0
    def testCalculateDeviceMd5Sums_singlePath(self):
        test_path = '/storage/emulated/legacy/test/file.dat'

        device = mock.NonCallableMock()
        device.adb = mock.NonCallableMock()
        device.adb.Push = mock.Mock()
        device_md5sum_output = [
            '0123456789abcdeffedcba9876543210 '
            '/storage/emulated/legacy/test/file.dat',
        ]
        device.RunShellCommand = mock.Mock(return_value=device_md5sum_output)

        mock_temp_file = mock.mock_open()
        mock_temp_file.return_value.name = '/tmp/test/script/file.sh'

        mock_device_temp_file = mock.mock_open()
        mock_device_temp_file.return_value.name = (
            '/data/local/tmp/test/script/file.sh')

        with mock.patch('tempfile.NamedTemporaryFile',
                        new=mock_temp_file), (mock.patch(
                            'pylib.utils.device_temp_file.DeviceTempFile',
                            new=mock_device_temp_file)):
            out = md5sum.CalculateDeviceMd5Sums(test_path, device)
            self.assertEquals(1, len(out))
            self.assertTrue('/storage/emulated/legacy/test/file.dat' in out)
            self.assertEquals('0123456789abcdeffedcba9876543210',
                              out['/storage/emulated/legacy/test/file.dat'])
            device.adb.Push.assert_called_once_with(
                '/tmp/test/script/file.sh',
                '/data/local/tmp/test/script/file.sh')
            device.RunShellCommand.assert_called_once_with(
                ['sh', '/data/local/tmp/test/script/file.sh'])
コード例 #2
0
    def testCalculateDeviceMd5Sums_requiresBinary(self):
        test_path = '/storage/emulated/legacy/test/file.dat'

        device = mock.NonCallableMock()
        device.adb = mock.NonCallableMock()
        device.adb.Push = mock.Mock()
        device_md5sum_output = [
            'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: '
            'unused DT entry: type 0x1d arg 0x15db',
            'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text',
            '0123456789abcdeffedcba9876543210 '
            '/storage/emulated/legacy/test/file.dat',
        ]
        error = device_errors.AdbShellCommandFailedError('cmd', 'out', 2)
        device.RunShellCommand = mock.Mock(side_effect=(error, '',
                                                        device_md5sum_output))

        with mock.patch('os.path.getsize', return_value=1337):
            out = md5sum.CalculateDeviceMd5Sums(test_path, device)
            self.assertEquals(1, len(out))
            self.assertTrue('/storage/emulated/legacy/test/file.dat' in out)
            self.assertEquals('0123456789abcdeffedcba9876543210',
                              out['/storage/emulated/legacy/test/file.dat'])
            self.assertEquals(3, len(device.RunShellCommand.call_args_list))
            device.adb.Push.assert_called_once_with(
                'test/out/directory/md5sum_dist', '/data/local/tmp/md5sum/')
コード例 #3
0
  def _GetChangedFilesImpl(self, host_path, device_path):
    real_host_path = os.path.realpath(host_path)
    try:
      real_device_path = self.RunShellCommand(
          ['realpath', device_path], single_line=True, check_return=True)
    except device_errors.CommandFailedError:
      real_device_path = None
    if not real_device_path:
      return [(host_path, device_path)]

    host_hash_tuples = md5sum.CalculateHostMd5Sums([real_host_path])
    device_paths_to_md5 = (
        real_device_path if os.path.isfile(real_host_path)
        else ('%s/%s' % (real_device_path, os.path.relpath(p, real_host_path))
              for _, p in host_hash_tuples))
    device_hash_tuples = md5sum.CalculateDeviceMd5Sums(
        device_paths_to_md5, self)

    if os.path.isfile(host_path):
      if (not device_hash_tuples
          or device_hash_tuples[0].hash != host_hash_tuples[0].hash):
        return [(host_path, device_path)]
      else:
        return []
    else:
      device_tuple_dict = dict((d.path, d.hash) for d in device_hash_tuples)
      to_push = []
      for host_hash, host_abs_path in (
          (h.hash, h.path) for h in host_hash_tuples):
        device_abs_path = '%s/%s' % (
            real_device_path, os.path.relpath(host_abs_path, real_host_path))
        if (device_abs_path not in device_tuple_dict
            or device_tuple_dict[device_abs_path] != host_hash):
          to_push.append((host_abs_path, device_abs_path))
      return to_push
コード例 #4
0
    def testCalculateDeviceMd5Sums_singlePath(self):
        test_path = '/storage/emulated/legacy/test/file.dat'

        device = mock.NonCallableMock()
        device_md5sum_output = [
            '0123456789abcdeffedcba9876543210 '
            '/storage/emulated/legacy/test/file.dat',
        ]
        device.RunShellCommand = mock.Mock(return_value=device_md5sum_output)

        with mock.patch('os.path.getsize', return_value=1337):
            out = md5sum.CalculateDeviceMd5Sums(test_path, device)
            self.assertEquals(1, len(out))
            self.assertTrue('/storage/emulated/legacy/test/file.dat' in out)
            self.assertEquals('0123456789abcdeffedcba9876543210',
                              out['/storage/emulated/legacy/test/file.dat'])
            self.assertEquals(1, len(device.RunShellCommand.call_args_list))
コード例 #5
0
    def testCalculateDeviceMd5Sums_list_fileMissing(self):
        test_path = [
            '/storage/emulated/legacy/test/file0.dat',
            '/storage/emulated/legacy/test/file1.dat'
        ]
        device = mock.NonCallableMock()
        device_md5sum_output = [
            '0123456789abcdeffedcba9876543210 '
            '/storage/emulated/legacy/test/file0.dat',
            '[0819/203513:ERROR:md5sum.cc(25)] Could not open file asdf',
            '',
        ]
        device.RunShellCommand = mock.Mock(return_value=device_md5sum_output)

        with mock.patch('os.path.getsize', return_value=1337):
            out = md5sum.CalculateDeviceMd5Sums(test_path, device)
            self.assertEquals(1, len(out))
            self.assertTrue('/storage/emulated/legacy/test/file0.dat' in out)
            self.assertEquals('0123456789abcdeffedcba9876543210',
                              out['/storage/emulated/legacy/test/file0.dat'])
            self.assertEquals(1, len(device.RunShellCommand.call_args_list))
コード例 #6
0
    def testCalculateDeviceMd5Sums_singlePath_linkerWarning(self):
        # See crbug/479966
        test_path = '/storage/emulated/legacy/test/file.dat'

        device = mock.NonCallableMock()
        device_md5sum_output = [
            'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: '
            'unused DT entry: type 0x1d arg 0x15db',
            'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text',
            '0123456789abcdeffedcba9876543210 '
            '/storage/emulated/legacy/test/file.dat',
        ]
        device.RunShellCommand = mock.Mock(return_value=device_md5sum_output)

        with mock.patch('os.path.getsize', return_value=1337):
            out = md5sum.CalculateDeviceMd5Sums(test_path, device)
            self.assertEquals(1, len(out))
            self.assertTrue('/storage/emulated/legacy/test/file.dat' in out)
            self.assertEquals('0123456789abcdeffedcba9876543210',
                              out['/storage/emulated/legacy/test/file.dat'])
            self.assertEquals(1, len(device.RunShellCommand.call_args_list))
コード例 #7
0
    def testCalculateDeviceMd5Sums_singlePath_linkerWarning(self):
        # See crbug/479966
        test_path = '/storage/emulated/legacy/test/file.dat'

        device = mock.NonCallableMock()
        device.adb = mock.NonCallableMock()
        device.adb.Push = mock.Mock()
        device_md5sum_output = [
            'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: '
            'unused DT entry: type 0x1d arg 0x15db',
            'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text',
            '0123456789abcdeffedcba9876543210 '
            '/storage/emulated/legacy/test/file.dat',
        ]
        device.RunShellCommand = mock.Mock(return_value=device_md5sum_output)

        mock_temp_file = mock.mock_open()
        mock_temp_file.return_value.name = '/tmp/test/script/file.sh'

        mock_device_temp_file = mock.mock_open()
        mock_device_temp_file.return_value.name = (
            '/data/local/tmp/test/script/file.sh')

        with mock.patch('tempfile.NamedTemporaryFile',
                        new=mock_temp_file), (mock.patch(
                            'pylib.utils.device_temp_file.DeviceTempFile',
                            new=mock_device_temp_file)):
            out = md5sum.CalculateDeviceMd5Sums(test_path, device)
            self.assertEquals(1, len(out))
            self.assertTrue('/storage/emulated/legacy/test/file.dat' in out)
            self.assertEquals('0123456789abcdeffedcba9876543210',
                              out['/storage/emulated/legacy/test/file.dat'])
            device.adb.Push.assert_called_once_with(
                '/tmp/test/script/file.sh',
                '/data/local/tmp/test/script/file.sh')
            device.RunShellCommand.assert_called_once_with(
                ['sh', '/data/local/tmp/test/script/file.sh'])
コード例 #8
0
def CreateSymFs(device, symfs_dir, libraries, use_symlinks=True):
  """Creates a symfs directory to be used for symbolizing profiles.

  Prepares a set of files ("symfs") to be used with profilers such as perf for
  converting binary addresses into human readable function names.

  Args:
    device: DeviceUtils instance identifying the target device.
    symfs_dir: Path where the symfs should be created.
    libraries: Set of library file names that should be included in the symfs.
    use_symlinks: If True, link instead of copy unstripped libraries into the
      symfs. This will speed up the operation, but the resulting symfs will no
      longer be valid if the linked files are modified, e.g., by rebuilding.

  Returns:
    The absolute path to the kernel symbols within the created symfs.
  """
  logging.info('Building symfs into %s.' % symfs_dir)

  for lib in libraries:
    device_dir = os.path.dirname(lib)
    output_dir = os.path.join(symfs_dir, device_dir[1:])
    if not os.path.exists(output_dir):
      os.makedirs(output_dir)
    output_lib = os.path.join(output_dir, os.path.basename(lib))

    if lib.startswith('/data/app/'):
      # If this is our own library instead of a system one, look for a matching
      # unstripped library under the out directory.
      unstripped_host_lib = _FindMatchingUnstrippedLibraryOnHost(device, lib)
      if not unstripped_host_lib:
        logging.warning('Could not find symbols for %s.' % lib)
        logging.warning('Is the correct output directory selected '
                        '(CHROMIUM_OUT_DIR)? Did you install the APK after '
                        'building?')
        continue
      if use_symlinks:
        if os.path.lexists(output_lib):
          os.remove(output_lib)
        os.symlink(os.path.abspath(unstripped_host_lib), output_lib)
      # Copy the unstripped library only if it has been changed to avoid the
      # delay. Add one second to the modification time to guard against file
      # systems with poor timestamp resolution.
      elif not os.path.exists(output_lib) or \
          (os.stat(unstripped_host_lib).st_mtime >
           os.stat(output_lib).st_mtime + 1):
        logging.info('Copying %s to %s' % (unstripped_host_lib, output_lib))
        shutil.copy2(unstripped_host_lib, output_lib)
    else:
      # Otherwise save a copy of the stripped system library under the symfs so
      # the profiler can at least use the public symbols of that library. To
      # speed things up, only pull files that don't match copies we already
      # have in the symfs.
      if not os.path.exists(output_lib):
        pull = True
      else:
        host_md5sums = md5sum.CalculateHostMd5Sums([output_lib])
        device_md5sums = md5sum.CalculateDeviceMd5Sums([lib], device)
        pull = (not host_md5sums or not device_md5sums
                or host_md5sums[0] != device_md5sums[0])

      if pull:
        logging.info('Pulling %s to %s', lib, output_lib)
        device.PullFile(lib, output_lib)

  # Also pull a copy of the kernel symbols.
  output_kallsyms = os.path.join(symfs_dir, 'kallsyms')
  if not os.path.exists(output_kallsyms):
    device.PullFile('/proc/kallsyms', output_kallsyms)
  return output_kallsyms
コード例 #9
0
    def testCalculateDeviceMd5Sums_noPaths(self):
        device = mock.NonCallableMock()
        device.RunShellCommand = mock.Mock(side_effect=Exception())

        out = md5sum.CalculateDeviceMd5Sums([], device)
        self.assertEquals(0, len(out))