コード例 #1
0
  def _test_AddCareMapForAbOta():
    """Helper function to set up the test for test_AddCareMapForAbOta()."""
    OPTIONS.info_dict = {
        'extfs_sparse_flag' : '-s',
        'system_image_size' : 65536,
        'vendor_image_size' : 40960,
        'system_verity_block_device': '/dev/block/system',
        'vendor_verity_block_device': '/dev/block/vendor',
        'system.build.prop': {
            'ro.system.build.fingerprint':
                'google/sailfish/12345:user/dev-keys',
        },
        'vendor.build.prop': {
            'ro.vendor.build.fingerprint': 'google/sailfish/678:user/dev-keys',
        },
    }

    # Prepare the META/ folder.
    meta_path = os.path.join(OPTIONS.input_tmp, 'META')
    if not os.path.exists(meta_path):
      os.mkdir(meta_path)

    system_image = test_utils.construct_sparse_image([
        (0xCAC1, 6),
        (0xCAC3, 4),
        (0xCAC1, 8)])
    vendor_image = test_utils.construct_sparse_image([
        (0xCAC2, 12)])

    image_paths = {
        'system' : system_image,
        'vendor' : vendor_image,
    }
    return image_paths
コード例 #2
0
    def _test_AddCareMapForAbOta():
        """Helper function to set up the test for test_AddCareMapForAbOta()."""
        OPTIONS.info_dict = {
            'system_verity_block_device': '/dev/block/system',
            'vendor_verity_block_device': '/dev/block/vendor',
            'system.build.prop': {
                'ro.system.build.fingerprint':
                'google/sailfish/12345:user/dev-keys',
            },
            'vendor.build.prop': {
                'ro.vendor.build.fingerprint':
                'google/sailfish/678:user/dev-keys',
            }
        }

        # Prepare the META/ folder.
        meta_path = os.path.join(OPTIONS.input_tmp, 'META')
        if not os.path.exists(meta_path):
            os.mkdir(meta_path)

        system_image = test_utils.construct_sparse_image([(0xCAC1, 6),
                                                          (0xCAC3, 4),
                                                          (0xCAC1, 6)])
        vendor_image = test_utils.construct_sparse_image([(0xCAC2, 10)])

        image_paths = {
            'system': system_image,
            'vendor': vendor_image,
        }
        return image_paths
コード例 #3
0
ファイル: test_common.py プロジェクト: vchong/platform_build
  def test_GetSparseImage_systemRootImage_filenameWithExtraLeadingSlash(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      target_files_zip.write(
          test_utils.construct_sparse_image([(0xCAC2, 16)]),
          arcname='IMAGES/system.img')
      target_files_zip.writestr(
          'IMAGES/system.map',
          '\n'.join([
              '//system/file1 1-5 9-10',
              '//system/file2 11-12',
              '/system/app/file3 13-15']))
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))
      # '/system/file2' has less blocks listed (2) than actual (3).
      target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))
      # '/system/app/file3' has less blocks listed (3) than actual (4).
      target_files_zip.writestr('SYSTEM/app/file3', os.urandom(4096 * 4))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      sparse_image = common.GetSparseImage('system', tempdir, input_zip, False)

    self.assertFalse(sparse_image.file_map['//system/file1'].extra)
    self.assertTrue(sparse_image.file_map['//system/file2'].extra['incomplete'])
    self.assertTrue(
        sparse_image.file_map['/system/app/file3'].extra['incomplete'])
コード例 #4
0
 def test_GetCareMap_invalidAdjustedPartitionSize(self):
     sparse_image = test_utils.construct_sparse_image([(0xCAC1, 6),
                                                       (0xCAC3, 4),
                                                       (0xCAC1, 6)])
     OPTIONS.info_dict = {
         'system_adjusted_partition_size': -12,
     }
     self.assertRaises(AssertionError, GetCareMap, 'system', sparse_image)
コード例 #5
0
 def test_GetCareMap_invalidAdjustedPartitionSize(self):
   sparse_image = test_utils.construct_sparse_image([
       (0xCAC1, 6),
       (0xCAC3, 4),
       (0xCAC1, 6)])
   OPTIONS.info_dict = {
       'system_adjusted_partition_size' : -12,
   }
   self.assertRaises(AssertionError, GetCareMap, 'system', sparse_image)
コード例 #6
0
 def test_GetCareMap(self):
     sparse_image = test_utils.construct_sparse_image([(0xCAC1, 6),
                                                       (0xCAC3, 4),
                                                       (0xCAC1, 6)])
     OPTIONS.info_dict = {
         'system_adjusted_partition_size': 12,
     }
     name, care_map = GetCareMap('system', sparse_image)
     self.assertEqual('system', name)
     self.assertEqual(RangeSet("0-5 10-12").to_string_raw(), care_map)
コード例 #7
0
 def test_GetCareMap(self):
   sparse_image = test_utils.construct_sparse_image([
       (0xCAC1, 6),
       (0xCAC3, 4),
       (0xCAC1, 6)])
   OPTIONS.info_dict = {
       'system_adjusted_partition_size' : 12,
   }
   name, care_map = GetCareMap('system', sparse_image)
   self.assertEqual('system', name)
   self.assertEqual(RangeSet("0-5 10-12").to_string_raw(), care_map)
コード例 #8
0
 def test_GetCareMap(self):
     sparse_image = test_utils.construct_sparse_image([(0xCAC1, 6),
                                                       (0xCAC3, 4),
                                                       (0xCAC1, 6)])
     OPTIONS.info_dict = {
         'extfs_sparse_flag': '-s',
         'system_image_size': 53248,
     }
     name, care_map = GetCareMap('system', sparse_image)
     self.assertEqual('system', name)
     self.assertEqual(RangeSet("0-5 10-12").to_string_raw(), care_map)
コード例 #9
0
    def _test_AddCareMapForAbOta():
        """Helper function to set up the test for test_AddCareMapForAbOta()."""
        OPTIONS.info_dict = {
            'extfs_sparse_flag':
            '-s',
            'system_image_size':
            65536,
            'vendor_image_size':
            40960,
            'system_verity_block_device':
            '/dev/block/system',
            'vendor_verity_block_device':
            '/dev/block/vendor',
            'system.build.prop':
            common.PartitionBuildProps.FromDictionary(
                'system', {
                    'ro.system.build.fingerprint':
                    'google/sailfish/12345:user/dev-keys'
                }),
            'vendor.build.prop':
            common.PartitionBuildProps.FromDictionary('vendor', {
                'ro.vendor.build.fingerprint':
                'google/sailfish/678:user/dev-keys'
            }),
        }

        # Prepare the META/ folder.
        meta_path = os.path.join(OPTIONS.input_tmp, 'META')
        if not os.path.exists(meta_path):
            os.mkdir(meta_path)

        system_image = test_utils.construct_sparse_image([(0xCAC1, 6),
                                                          (0xCAC3, 4),
                                                          (0xCAC1, 8)])
        vendor_image = test_utils.construct_sparse_image([(0xCAC2, 12)])

        image_paths = {
            'system': system_image,
            'vendor': vendor_image,
        }
        return image_paths
コード例 #10
0
 def test_GetCareMap(self):
   sparse_image = test_utils.construct_sparse_image([
       (0xCAC1, 6),
       (0xCAC3, 4),
       (0xCAC1, 6)])
   OPTIONS.info_dict = {
       'extfs_sparse_flag' : '-s',
       'system_image_size' : 53248,
   }
   name, care_map = GetCareMap('system', sparse_image)
   self.assertEqual('system', name)
   self.assertEqual(RangeSet("0-5 10-12").to_string_raw(), care_map)
コード例 #11
0
    def _test_AddCareMapTxtForAbOta():
        """Helper function to set up the test for test_AddCareMapTxtForAbOta()."""
        OPTIONS.info_dict = {
            'system_verity_block_device': '/dev/block/system',
            'vendor_verity_block_device': '/dev/block/vendor',
        }

        # Prepare the META/ folder.
        meta_path = os.path.join(OPTIONS.input_tmp, 'META')
        if not os.path.exists(meta_path):
            os.mkdir(meta_path)

        system_image = test_utils.construct_sparse_image([(0xCAC1, 6),
                                                          (0xCAC3, 4),
                                                          (0xCAC1, 6)])
        vendor_image = test_utils.construct_sparse_image([(0xCAC2, 10)])

        image_paths = {
            'system': system_image,
            'vendor': vendor_image,
        }
        return image_paths
コード例 #12
0
ファイル: test_common.py プロジェクト: BEAOSP/build
    def test_GetSparseImage_missingBlockMapFile(self):
        target_files = common.MakeTempFile(prefix='target_files-',
                                           suffix='.zip')
        with zipfile.ZipFile(target_files, 'w') as target_files_zip:
            target_files_zip.write(test_utils.construct_sparse_image([
                (0xCAC1, 6), (0xCAC3, 3), (0xCAC1, 4)
            ]),
                                   arcname='IMAGES/system.img')
            target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 8))
            target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

        tempdir = common.UnzipTemp(target_files)
        with zipfile.ZipFile(target_files, 'r') as input_zip:
            self.assertRaises(AssertionError, common.GetSparseImage, 'system',
                              tempdir, input_zip, False)
コード例 #13
0
  def _test_AddCareMapTxtForAbOta():
    """Helper function to set up the test for test_AddCareMapTxtForAbOta()."""
    OPTIONS.info_dict = {
        'system_verity_block_device' : '/dev/block/system',
        'vendor_verity_block_device' : '/dev/block/vendor',
    }

    # Prepare the META/ folder.
    meta_path = os.path.join(OPTIONS.input_tmp, 'META')
    if not os.path.exists(meta_path):
      os.mkdir(meta_path)

    system_image = test_utils.construct_sparse_image([
        (0xCAC1, 6),
        (0xCAC3, 4),
        (0xCAC1, 6)])
    vendor_image = test_utils.construct_sparse_image([
        (0xCAC2, 10)])

    image_paths = {
        'system' : system_image,
        'vendor' : vendor_image,
    }
    return image_paths
コード例 #14
0
ファイル: test_common.py プロジェクト: BEAOSP/build
    def test_GetSparseImage_fileNotFound(self):
        target_files = common.MakeTempFile(prefix='target_files-',
                                           suffix='.zip')
        with zipfile.ZipFile(target_files, 'w') as target_files_zip:
            target_files_zip.write(test_utils.construct_sparse_image([(0xCAC2,
                                                                       16)]),
                                   arcname='IMAGES/system.img')
            target_files_zip.writestr(
                'IMAGES/system.map',
                '\n'.join(['//system/file1 1-5 9-10', '//system/file2 11-12']))
            target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))

        tempdir = common.UnzipTemp(target_files)
        with zipfile.ZipFile(target_files, 'r') as input_zip:
            self.assertRaises(AssertionError, common.GetSparseImage, 'system',
                              tempdir, input_zip, False)
コード例 #15
0
  def test_GetSparseImage_missingBlockMapFile(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      target_files_zip.write(
          test_utils.construct_sparse_image([
              (0xCAC1, 6),
              (0xCAC3, 3),
              (0xCAC1, 4)]),
          arcname='IMAGES/system.img')
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 8))
      target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      self.assertRaises(
          AssertionError, common.GetSparseImage, 'system', tempdir, input_zip,
          False)
コード例 #16
0
  def test_GetSparseImage_fileNotFound(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      target_files_zip.write(
          test_utils.construct_sparse_image([(0xCAC2, 16)]),
          arcname='IMAGES/system.img')
      target_files_zip.writestr(
          'IMAGES/system.map',
          '\n'.join([
              '//system/file1 1-5 9-10',
              '//system/file2 11-12']))
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      self.assertRaises(
          AssertionError, common.GetSparseImage, 'system', tempdir, input_zip,
          False)
コード例 #17
0
ファイル: test_common.py プロジェクト: BEAOSP/build
    def test_GetSparseImage_sharedBlocks_notAllowed(self):
        """Tests the case of having overlapping blocks but disallowed."""
        target_files = common.MakeTempFile(prefix='target_files-',
                                           suffix='.zip')
        with zipfile.ZipFile(target_files, 'w') as target_files_zip:
            target_files_zip.write(test_utils.construct_sparse_image([(0xCAC2,
                                                                       16)]),
                                   arcname='IMAGES/system.img')
            # Block 10 is shared between two files.
            target_files_zip.writestr(
                'IMAGES/system.map',
                '\n'.join(['/system/file1 1-5 9-10', '/system/file2 10-12']))
            target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))
            target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

        tempdir = common.UnzipTemp(target_files)
        with zipfile.ZipFile(target_files, 'r') as input_zip:
            self.assertRaises(AssertionError, common.GetSparseImage, 'system',
                              tempdir, input_zip, False)
コード例 #18
0
ファイル: test_common.py プロジェクト: vchong/platform_build
  def test_GetSparseImage_sharedBlocks_allowed(self):
    """Tests the case for target using BOARD_EXT4_SHARE_DUP_BLOCKS := true."""
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      # Construct an image with a care_map of "0-5 9-12".
      target_files_zip.write(
          test_utils.construct_sparse_image([(0xCAC2, 16)]),
          arcname='IMAGES/system.img')
      # Block 10 is shared between two files.
      target_files_zip.writestr(
          'IMAGES/system.map',
          '\n'.join([
              '/system/file1 1-5 9-10',
              '/system/file2 10-12']))
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))
      target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      sparse_image = common.GetSparseImage('system', tempdir, input_zip, True)

    self.assertDictEqual(
        {
            '__COPY': RangeSet("0"),
            '__NONZERO-0': RangeSet("6-8 13-15"),
            '/system/file1': RangeSet("1-5 9-10"),
            '/system/file2': RangeSet("11-12"),
        },
        sparse_image.file_map)

    # '/system/file2' should be marked with 'uses_shared_blocks', but not with
    # 'incomplete'.
    self.assertTrue(
        sparse_image.file_map['/system/file2'].extra['uses_shared_blocks'])
    self.assertNotIn(
        'incomplete', sparse_image.file_map['/system/file2'].extra)

    # All other entries should look normal without any tags.
    self.assertFalse(sparse_image.file_map['__COPY'].extra)
    self.assertFalse(sparse_image.file_map['__NONZERO-0'].extra)
    self.assertFalse(sparse_image.file_map['/system/file1'].extra)
コード例 #19
0
  def test_GetSparseImage_sharedBlocks_notAllowed(self):
    """Tests the case of having overlapping blocks but disallowed."""
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      target_files_zip.write(
          test_utils.construct_sparse_image([(0xCAC2, 16)]),
          arcname='IMAGES/system.img')
      # Block 10 is shared between two files.
      target_files_zip.writestr(
          'IMAGES/system.map',
          '\n'.join([
              '/system/file1 1-5 9-10',
              '/system/file2 10-12']))
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))
      target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      self.assertRaises(
          AssertionError, common.GetSparseImage, 'system', tempdir, input_zip,
          False)
コード例 #20
0
ファイル: test_common.py プロジェクト: BEAOSP/build
    def test_GetSparseImage_emptyBlockMapFile(self):
        target_files = common.MakeTempFile(prefix='target_files-',
                                           suffix='.zip')
        with zipfile.ZipFile(target_files, 'w') as target_files_zip:
            target_files_zip.write(test_utils.construct_sparse_image([
                (0xCAC1, 6), (0xCAC3, 3), (0xCAC1, 4)
            ]),
                                   arcname='IMAGES/system.img')
            target_files_zip.writestr('IMAGES/system.map', '')
            target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 8))
            target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

        tempdir = common.UnzipTemp(target_files)
        with zipfile.ZipFile(target_files, 'r') as input_zip:
            sparse_image = common.GetSparseImage('system', tempdir, input_zip,
                                                 False)

        self.assertDictEqual(
            {
                '__COPY': RangeSet("0"),
                '__NONZERO-0': RangeSet("1-5 9-12"),
            }, sparse_image.file_map)
コード例 #21
0
ファイル: test_common.py プロジェクト: vchong/platform_build
  def test_GetSparseImage_incompleteRanges(self):
    """Tests the case of ext4 images with holes."""
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      target_files_zip.write(
          test_utils.construct_sparse_image([(0xCAC2, 16)]),
          arcname='IMAGES/system.img')
      target_files_zip.writestr(
          'IMAGES/system.map',
          '\n'.join([
              '/system/file1 1-5 9-10',
              '/system/file2 11-12']))
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 7))
      # '/system/file2' has less blocks listed (2) than actual (3).
      target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      sparse_image = common.GetSparseImage('system', tempdir, input_zip, False)

    self.assertFalse(sparse_image.file_map['/system/file1'].extra)
    self.assertTrue(sparse_image.file_map['/system/file2'].extra['incomplete'])
コード例 #22
0
  def test_GetSparseImage_emptyBlockMapFile(self):
    target_files = common.MakeTempFile(prefix='target_files-', suffix='.zip')
    with zipfile.ZipFile(target_files, 'w') as target_files_zip:
      target_files_zip.write(
          test_utils.construct_sparse_image([
              (0xCAC1, 6),
              (0xCAC3, 3),
              (0xCAC1, 4)]),
          arcname='IMAGES/system.img')
      target_files_zip.writestr('IMAGES/system.map', '')
      target_files_zip.writestr('SYSTEM/file1', os.urandom(4096 * 8))
      target_files_zip.writestr('SYSTEM/file2', os.urandom(4096 * 3))

    tempdir = common.UnzipTemp(target_files)
    with zipfile.ZipFile(target_files, 'r') as input_zip:
      sparse_image = common.GetSparseImage('system', tempdir, input_zip, False)

    self.assertDictEqual(
        {
            '__COPY': RangeSet("0"),
            '__NONZERO-0': RangeSet("1-5 9-12"),
        },
        sparse_image.file_map)