Prevent AVB signing from using _RESERVED_SIZE
When AVB is enabled with PRODUCT_USE_DYNAMIC_PARTITION_SIZE, AVB metadata (e.g., hash tree, fec metadata) will consume _RESERVED_SIZE, resulting in smaller reserved size in file system (e.g., ext4). Adding additional space for AVB signing and keep the _RESERVED_SIZE only for file system. This is done by adding a function to binary search an optimal partition size for a given image size (disk usage + _RESERVED_SIZE). Bug: 112322265 Test: Build aosp_arm64-userdebug, calculate the running time of AVBCalcMinPartitionSize() is about 0.3-0.4 seconds. Test: python -m unittest test_build_image Change-Id: I8f0051b57701d6fbba6a9db3756dd194066c74b8
This commit is contained in:
@@ -15,11 +15,15 @@
|
||||
#
|
||||
|
||||
import filecmp
|
||||
import math
|
||||
import os.path
|
||||
import random
|
||||
import unittest
|
||||
|
||||
import common
|
||||
from build_image import CheckHeadroom, RunCommand, SetUpInDirAndFsConfig
|
||||
from build_image import (
|
||||
AVBCalcMinPartitionSize, BLOCK_SIZE,
|
||||
CheckHeadroom, RunCommand, SetUpInDirAndFsConfig)
|
||||
|
||||
|
||||
class BuildImageTest(unittest.TestCase):
|
||||
@@ -28,6 +32,13 @@ class BuildImageTest(unittest.TestCase):
|
||||
EXT4FS_OUTPUT = (
|
||||
"Created filesystem with 2777/129024 inodes and 515099/516099 blocks")
|
||||
|
||||
def setUp(self):
|
||||
# To test AVBCalcMinPartitionSize(), by using 200MB to 2GB image size.
|
||||
# - 51200 = 200MB * 1024 * 1024 / 4096
|
||||
# - 524288 = 2GB * 1024 * 1024 * 1024 / 4096
|
||||
self._image_sizes = [BLOCK_SIZE * random.randint(51200, 524288) + offset
|
||||
for offset in range(BLOCK_SIZE)]
|
||||
|
||||
def tearDown(self):
|
||||
common.Cleanup()
|
||||
|
||||
@@ -176,3 +187,51 @@ class BuildImageTest(unittest.TestCase):
|
||||
self.assertIn('fs-config-system\n', fs_config_data)
|
||||
self.assertIn('fs-config-root\n', fs_config_data)
|
||||
self.assertEqual('/', prop_dict['mount_point'])
|
||||
|
||||
def test_AVBCalcMinPartitionSize_LinearFooterSize(self):
|
||||
"""Tests with footer size which is linear to partition size."""
|
||||
for image_size in self._image_sizes:
|
||||
for ratio in 0.95, 0.56, 0.22:
|
||||
expected_size = common.RoundUpTo4K(int(math.ceil(image_size / ratio)))
|
||||
self.assertEqual(
|
||||
expected_size,
|
||||
AVBCalcMinPartitionSize(image_size, lambda x: int(x * ratio)))
|
||||
|
||||
def test_AVBCalcMinPartitionSize_SlowerGrowthFooterSize(self):
|
||||
"""Tests with footer size which grows slower than partition size."""
|
||||
|
||||
def _SizeCalculator(partition_size):
|
||||
"""Footer size is the power of 0.95 of partition size."""
|
||||
# Minus footer size to return max image size.
|
||||
return partition_size - int(math.pow(partition_size, 0.95))
|
||||
|
||||
for image_size in self._image_sizes:
|
||||
min_partition_size = AVBCalcMinPartitionSize(image_size, _SizeCalculator)
|
||||
# Checks min_partition_size can accommodate image_size.
|
||||
self.assertGreaterEqual(
|
||||
_SizeCalculator(min_partition_size),
|
||||
image_size)
|
||||
# Checks min_partition_size (round to BLOCK_SIZE) is the minimum.
|
||||
self.assertLess(
|
||||
_SizeCalculator(min_partition_size - BLOCK_SIZE),
|
||||
image_size)
|
||||
|
||||
def test_AVBCalcMinPartitionSize_FasterGrowthFooterSize(self):
|
||||
"""Tests with footer size which grows faster than partition size."""
|
||||
|
||||
def _SizeCalculator(partition_size):
|
||||
"""Max image size is the power of 0.95 of partition size."""
|
||||
# Max image size grows less than partition size, which means
|
||||
# footer size grows faster than partition size.
|
||||
return int(math.pow(partition_size, 0.95))
|
||||
|
||||
for image_size in self._image_sizes:
|
||||
min_partition_size = AVBCalcMinPartitionSize(image_size, _SizeCalculator)
|
||||
# Checks min_partition_size can accommodate image_size.
|
||||
self.assertGreaterEqual(
|
||||
_SizeCalculator(min_partition_size),
|
||||
image_size)
|
||||
# Checks min_partition_size (round to BLOCK_SIZE) is the minimum.
|
||||
self.assertLess(
|
||||
_SizeCalculator(min_partition_size - BLOCK_SIZE),
|
||||
image_size)
|
||||
|
Reference in New Issue
Block a user