Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ba4270e authored by Tianjie's avatar Tianjie
Browse files

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
parent 3296b313
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ if sys.hexversion < 0x02070000:

logger = logging.getLogger(__name__)


class Expression(object):
  def __init__(self, desc, expr, value=None):
    # Human-readable description
@@ -62,6 +63,20 @@ class Expression(object):
      else:
        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):
    format_args = (self.desc, other.desc, self.expr, self.value,
                   other.expr, other.value)
@@ -116,7 +131,6 @@ class DynamicPartitionSizeChecker(object):
            int(info_dict["super_partition_size"])
    self.info_dict = info_dict


  def _ReadSizeOfPartition(self, name):
    # Tests uses *_image_size instead (to avoid creating empty sparse images
    # on disk)
@@ -124,7 +138,6 @@ class DynamicPartitionSizeChecker(object):
      return int(self.info_dict[name + "_image_size"])
    return sparse_img.GetImagePartitionSize(self.info_dict[name + "_image"])


  # Round result to BOARD_SUPER_PARTITION_ALIGNMENT
  def _RoundPartitionSize(self, size):
    alignment = self.info_dict.get("super_partition_alignment")
@@ -132,7 +145,6 @@ class DynamicPartitionSizeChecker(object):
      return size
    return (size + alignment - 1) // alignment * alignment


  def _CheckSuperPartitionSize(self):
    info_dict = self.info_dict
    super_block_devices = \
@@ -239,7 +251,20 @@ class DynamicPartitionSizeChecker(object):
      max_size = Expression(
          "BOARD_SUPER_PARTITION_SIZE{}".format(size_limit_suffix),
          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)
        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):
    self._CheckAllPartitionSizes()
+6 −6
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase):
        dynamic_partition_list=system vendor product
        super_partition_groups=group
        super_group_partition_list=system vendor product
        super_partition_size=200
        super_super_device_size=200
        super_partition_size=202
        super_super_device_size=202
        super_group_group_size=100
        system_image_size=50
        vendor_image_size=20
@@ -41,8 +41,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase):
  def test_non_ab(self):
    self.info_dict.update(common.LoadDictionaryFromLines("""
        ab_update=false
        super_partition_size=100
        super_super_device_size=100
        super_partition_size=101
        super_super_device_size=101
        """.split("\n")))
    CheckPartitionSizes(self.info_dict)

@@ -112,8 +112,8 @@ class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase):
  def test_vab(self):
    self.info_dict.update(common.LoadDictionaryFromLines("""
        virtual_ab=true
        super_partition_size=100
        super_super_device_size=100
        super_partition_size=101
        super_super_device_size=101
        """.split("\n")))
    CheckPartitionSizes(self.info_dict)