示例#1
0
    def test_calculate_bsdiff_fail(self):
        class PopenMocked(object):
            def wait(self):
                return -1

        with patch.object(subprocess, 'check_output', return_value=''):
            with patch.object(subprocess, 'Popen', return_value=PopenMocked()):
                with self.assertRaises(Exception) as context:
                    apk_patch_size_estimator.calculate_bsdiff(
                        '', '', None, '/tmp/patch.tmp')
        self.assertEqual(context.exception.message,
                         'Problem at the bsdiff step, returned code: -1')
  def test_calculate_bsdiff_fail(self):
    class PopenMocked(object):

      def wait(self):
        return -1

    with patch.object(subprocess, 'check_output', return_value=''):
      with patch.object(subprocess, 'Popen', return_value=PopenMocked()):
        with self.assertRaises(Exception) as context:
          apk_patch_size_estimator.calculate_bsdiff(
              '', '', None, '/tmp/patch.tmp')
    self.assertEqual(context.exception.message,
                     'Problem at the bsdiff step, returned code: -1')
示例#3
0
 def test_calculate_bsdiff_success(self):
     bsdiff_size = apk_patch_size_estimator.calculate_bsdiff(
         'tests/1.zip', 'tests/2.zip', 'mypatch', '/tmp/patch.tmp')
     self.assertRegexpMatches(apk_patch_size_estimator.bsdiff_path,
                              'bsdiff')
     self.assertRegexpMatches(apk_patch_size_estimator.gzip_path, 'gzip')
     self.assertRegexpMatches(apk_patch_size_estimator.head_path, 'head')
     self.assertRegexpMatches(apk_patch_size_estimator.tail_path, 'tail')
     self.assertRegexpMatches(apk_patch_size_estimator.bunzip2_path,
                              'bunzip2')
     ## Using a delta of 10% to compensate for
     ## different bsdiff implemantations
     self.assertAlmostEqual(bsdiff_size / float(2228571), 1, delta=0.1)
     self.assertTrue(os.path.isfile('mypatch-bsdiff-patch.gz'))
     os.remove('mypatch-bsdiff-patch.gz')
示例#4
0
def _PrintPatchSizeEstimate(new_apk, builder, bucket, report_func):
  apk_name = os.path.basename(new_apk)
  # Reference APK paths have spaces replaced by underscores.
  builder = builder.replace(' ', '_')
  old_apk = apk_downloader.MaybeDownloadApk(
      builder, apk_downloader.CURRENT_MILESTONE, apk_name,
      apk_downloader.DEFAULT_DOWNLOAD_PATH, bucket)
  if old_apk:
    # Use a temp dir in case patch size functions fail to clean up temp files.
    with build_utils.TempDir() as tmp:
      tmp_name = os.path.join(tmp, 'patch.tmp')
      bsdiff = apk_patch_size_estimator.calculate_bsdiff(
          old_apk, new_apk, None, tmp_name)
      report_func('PatchSizeEstimate', 'BSDiff (gzipped)', bsdiff, 'bytes')
      fbf = apk_patch_size_estimator.calculate_filebyfile(
          old_apk, new_apk, None, tmp_name)
      report_func('PatchSizeEstimate', 'FileByFile (gzipped)', fbf, 'bytes')
示例#5
0
def _PrintPatchSizeEstimate(new_apk, builder, bucket, chartjson=None):
  apk_name = os.path.basename(new_apk)
  title = apk_name + '_PatchSizeEstimate'
  # Reference APK paths have spaces replaced by underscores.
  builder = builder.replace(' ', '_')
  old_apk = apk_downloader.MaybeDownloadApk(
      builder, apk_downloader.CURRENT_MILESTONE, apk_name,
      apk_downloader.DEFAULT_DOWNLOAD_PATH, bucket)
  if old_apk:
    # Use a temp dir in case patch size functions fail to clean up temp files.
    with build_utils.TempDir() as tmp:
      tmp_name = os.path.join(tmp, 'patch.tmp')
      bsdiff = apk_patch_size_estimator.calculate_bsdiff(
          old_apk, new_apk, None, tmp_name)
      ReportPerfResult(chartjson, title, 'BSDiff (gzipped)', bsdiff, 'bytes')
      fbf = apk_patch_size_estimator.calculate_filebyfile(
          old_apk, new_apk, None, tmp_name)
      ReportPerfResult(chartjson, title, 'FileByFile (gzipped)', fbf, 'bytes')
 def test_calculate_bsdiff_success(self):
   bsdiff_size = apk_patch_size_estimator.calculate_bsdiff(
       'tests/1.zip',
       'tests/2.zip',
       'mypatch',
       '/tmp/patch.tmp')
   self.assertRegexpMatches(
       apk_patch_size_estimator.bsdiff_path, 'bsdiff')
   self.assertRegexpMatches(
       apk_patch_size_estimator.gzip_path, 'gzip')
   self.assertRegexpMatches(
       apk_patch_size_estimator.head_path, 'head')
   self.assertRegexpMatches(
       apk_patch_size_estimator.tail_path, 'tail')
   self.assertRegexpMatches(
       apk_patch_size_estimator.bunzip2_path, 'bunzip2')
   ## Using a delta of 10% to compensate for
   ## different bsdiff implemantations
   self.assertAlmostEqual(bsdiff_size/float(2228571), 1, delta=0.1)
   self.assertTrue(os.path.isfile('mypatch-bsdiff-patch.gz'))
   os.remove('mypatch-bsdiff-patch.gz')