1# 2# Copyright (C) 2019 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17import common 18import test_utils 19from check_partition_sizes import CheckPartitionSizes 20 21class CheckPartitionSizesTest(test_utils.ReleaseToolsTestCase): 22 def setUp(self): 23 self.info_dict = common.LoadDictionaryFromLines(""" 24 use_dynamic_partitions=true 25 ab_update=true 26 super_block_devices=super 27 dynamic_partition_list=system vendor product 28 super_partition_groups=group 29 super_group_partition_list=system vendor product 30 super_partition_size=202 31 super_super_device_size=202 32 super_group_group_size=100 33 system_image_size=50 34 vendor_image_size=20 35 product_image_size=20 36 system_other_image_size=10 37 """.split("\n")) 38 39 def test_ab(self): 40 CheckPartitionSizes(self.info_dict) 41 42 def test_non_ab(self): 43 self.info_dict.update(common.LoadDictionaryFromLines(""" 44 ab_update=false 45 super_partition_size=101 46 super_super_device_size=101 47 """.split("\n"))) 48 CheckPartitionSizes(self.info_dict) 49 50 def test_non_dap(self): 51 self.info_dict.update(common.LoadDictionaryFromLines(""" 52 use_dynamic_partitions=false 53 """.split("\n"))) 54 with self.assertRaises(RuntimeError): 55 CheckPartitionSizes(self.info_dict) 56 57 def test_retrofit_dap(self): 58 self.info_dict.update(common.LoadDictionaryFromLines(""" 59 dynamic_partition_retrofit=true 60 super_block_devices=system vendor 61 super_system_device_size=75 62 super_vendor_device_size=25 63 super_partition_size=100 64 """.split("\n"))) 65 CheckPartitionSizes(self.info_dict) 66 67 def test_ab_partition_too_big(self): 68 self.info_dict.update(common.LoadDictionaryFromLines(""" 69 system_image_size=100 70 """.split("\n"))) 71 with self.assertRaises(RuntimeError): 72 CheckPartitionSizes(self.info_dict) 73 74 def test_ab_group_too_big(self): 75 self.info_dict.update(common.LoadDictionaryFromLines(""" 76 super_group_group_size=110 77 """.split("\n"))) 78 with self.assertRaises(RuntimeError): 79 CheckPartitionSizes(self.info_dict) 80 81 def test_no_image(self): 82 del self.info_dict["system_image_size"] 83 with self.assertRaises(KeyError): 84 CheckPartitionSizes(self.info_dict) 85 86 def test_block_devices_not_match(self): 87 self.info_dict.update(common.LoadDictionaryFromLines(""" 88 dynamic_partition_retrofit=true 89 super_block_devices=system vendor 90 super_system_device_size=80 91 super_vendor_device_size=25 92 super_partition_size=100 93 """.split("\n"))) 94 with self.assertRaises(RuntimeError): 95 CheckPartitionSizes(self.info_dict) 96 97 def test_retrofit_vab(self): 98 self.info_dict.update(common.LoadDictionaryFromLines(""" 99 virtual_ab=true 100 virtual_ab_retrofit=true 101 """.split("\n"))) 102 CheckPartitionSizes(self.info_dict) 103 104 def test_retrofit_vab_too_big(self): 105 self.info_dict.update(common.LoadDictionaryFromLines(""" 106 virtual_ab=true 107 virtual_ab_retrofit=true 108 system_image_size=100 109 """.split("\n"))) 110 with self.assertRaises(RuntimeError): 111 CheckPartitionSizes(self.info_dict) 112 113 def test_vab(self): 114 self.info_dict.update(common.LoadDictionaryFromLines(""" 115 virtual_ab=true 116 super_partition_size=101 117 super_super_device_size=101 118 """.split("\n"))) 119 CheckPartitionSizes(self.info_dict) 120 121 def test_vab_too_big(self): 122 self.info_dict.update(common.LoadDictionaryFromLines(""" 123 virtual_ab=true 124 super_partition_size=100 125 super_super_device_size=100 126 system_image_size=100 127 """.split("\n"))) 128 with self.assertRaises(RuntimeError): 129 CheckPartitionSizes(self.info_dict) 130 131 def test_vab_too_big_with_system_other(self): 132 self.info_dict.update(common.LoadDictionaryFromLines(""" 133 virtual_ab=true 134 system_other_image_size=20 135 super_partition_size=101 136 super_super_device_size=101 137 """.split("\n"))) 138 with self.assertRaises(RuntimeError): 139 CheckPartitionSizes(self.info_dict) 140