Check that sum of DAP groups is smaller than super

The maximum size of all dynamic partition groups should not exceed
the super size - DAP metadata size. Today the configuration of
some devices don't take the metadata into acount. So turn the CheckLe
into CheckLt.

Also, display a warning if the reserved size for DAP metadata is less
than 1M.

Bug: 182431975
Test: mm -j32 check-all-partition-sizes
Change-Id: Ie278f224321083e457d68da000c2b22ec8a54085
This commit is contained in:
Tianjie 2021-03-16 17:34:22 -07:00
parent 3296b3136e
commit 8ba4270e24
2 changed files with 35 additions and 10 deletions

View File

@ -40,6 +40,7 @@ if sys.hexversion < 0x02070000:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Expression(object): class Expression(object):
def __init__(self, desc, expr, value=None): def __init__(self, desc, expr, value=None):
# Human-readable description # Human-readable description
@ -62,6 +63,20 @@ class Expression(object):
else: else:
logger.log(level, msg) logger.log(level, msg)
def CheckLt(self, other, level=logging.ERROR):
format_args = (self.desc, other.desc, self.expr, self.value,
other.expr, other.value)
if self.value < other.value:
logger.info("%s is less than %s:\n%s == %d < %s == %d",
*format_args)
else:
msg = "{} is greater than or equal to {}:\n{} == {} >= {} == {}".format(
*format_args)
if level == logging.ERROR:
raise RuntimeError(msg)
else:
logger.log(level, msg)
def CheckEq(self, other): def CheckEq(self, other):
format_args = (self.desc, other.desc, self.expr, self.value, format_args = (self.desc, other.desc, self.expr, self.value,
other.expr, other.value) other.expr, other.value)
@ -116,7 +131,6 @@ class DynamicPartitionSizeChecker(object):
int(info_dict["super_partition_size"]) int(info_dict["super_partition_size"])
self.info_dict = info_dict self.info_dict = info_dict
def _ReadSizeOfPartition(self, name): def _ReadSizeOfPartition(self, name):
# Tests uses *_image_size instead (to avoid creating empty sparse images # Tests uses *_image_size instead (to avoid creating empty sparse images
# on disk) # on disk)
@ -124,7 +138,6 @@ class DynamicPartitionSizeChecker(object):
return int(self.info_dict[name + "_image_size"]) return int(self.info_dict[name + "_image_size"])
return sparse_img.GetImagePartitionSize(self.info_dict[name + "_image"]) return sparse_img.GetImagePartitionSize(self.info_dict[name + "_image"])
# Round result to BOARD_SUPER_PARTITION_ALIGNMENT # Round result to BOARD_SUPER_PARTITION_ALIGNMENT
def _RoundPartitionSize(self, size): def _RoundPartitionSize(self, size):
alignment = self.info_dict.get("super_partition_alignment") alignment = self.info_dict.get("super_partition_alignment")
@ -132,7 +145,6 @@ class DynamicPartitionSizeChecker(object):
return size return size
return (size + alignment - 1) // alignment * alignment return (size + alignment - 1) // alignment * alignment
def _CheckSuperPartitionSize(self): def _CheckSuperPartitionSize(self):
info_dict = self.info_dict info_dict = self.info_dict
super_block_devices = \ super_block_devices = \
@ -239,7 +251,20 @@ class DynamicPartitionSizeChecker(object):
max_size = Expression( max_size = Expression(
"BOARD_SUPER_PARTITION_SIZE{}".format(size_limit_suffix), "BOARD_SUPER_PARTITION_SIZE{}".format(size_limit_suffix),
int(info_dict["super_partition_size"]) // num_slots) int(info_dict["super_partition_size"]) // num_slots)
# Retrofit DAP will build metadata as part of super image.
if Dap.Get(info_dict) == Dap.RDAP:
sum_size.CheckLe(max_size) sum_size.CheckLe(max_size)
return
sum_size.CheckLt(max_size)
# Display a warning if group size + 1M >= super size
minimal_metadata_size = 1024 * 1024 # 1MiB
sum_size_plus_metadata = Expression(
"sum of sizes of {} plus 1M metadata".format(groups),
"+".join(str(size) for size in
group_size_list + [minimal_metadata_size]),
sum(group_size_list) + minimal_metadata_size)
sum_size_plus_metadata.CheckLe(max_size, level=logging.WARNING)
def Run(self): def Run(self):
self._CheckAllPartitionSizes() self._CheckAllPartitionSizes()

View File

@ -27,8 +27,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase):
dynamic_partition_list=system vendor product dynamic_partition_list=system vendor product
super_partition_groups=group super_partition_groups=group
super_group_partition_list=system vendor product super_group_partition_list=system vendor product
super_partition_size=200 super_partition_size=202
super_super_device_size=200 super_super_device_size=202
super_group_group_size=100 super_group_group_size=100
system_image_size=50 system_image_size=50
vendor_image_size=20 vendor_image_size=20
@ -41,8 +41,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase):
def test_non_ab(self): def test_non_ab(self):
self.info_dict.update(common.LoadDictionaryFromLines(""" self.info_dict.update(common.LoadDictionaryFromLines("""
ab_update=false ab_update=false
super_partition_size=100 super_partition_size=101
super_super_device_size=100 super_super_device_size=101
""".split("\n"))) """.split("\n")))
CheckPartitionSizes(self.info_dict) CheckPartitionSizes(self.info_dict)
@ -112,8 +112,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase):
def test_vab(self): def test_vab(self):
self.info_dict.update(common.LoadDictionaryFromLines(""" self.info_dict.update(common.LoadDictionaryFromLines("""
virtual_ab=true virtual_ab=true
super_partition_size=100 super_partition_size=101
super_super_device_size=100 super_super_device_size=101
""".split("\n"))) """.split("\n")))
CheckPartitionSizes(self.info_dict) CheckPartitionSizes(self.info_dict)