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=200
31        super_super_device_size=200
32        super_group_group_size=100
33        system_image_size=50
34        vendor_image_size=20
35        product_image_size=20
36        """.split("\n"))
37
38  def test_ab(self):
39    CheckPartitionSizes(self.info_dict)
40
41  def test_non_ab(self):
42    self.info_dict.update(common.LoadDictionaryFromLines("""
43        ab_update=false
44        super_partition_size=100
45        super_super_device_size=100
46        """.split("\n")))
47    CheckPartitionSizes(self.info_dict)
48
49  def test_non_dap(self):
50    self.info_dict.update(common.LoadDictionaryFromLines("""
51        use_dynamic_partitions=false
52        """.split("\n")))
53    with self.assertRaises(RuntimeError):
54      CheckPartitionSizes(self.info_dict)
55
56  def test_retrofit_dap(self):
57    self.info_dict.update(common.LoadDictionaryFromLines("""
58        dynamic_partition_retrofit=true
59        super_block_devices=system vendor
60        super_system_device_size=75
61        super_vendor_device_size=25
62        super_partition_size=100
63        """.split("\n")))
64    CheckPartitionSizes(self.info_dict)
65
66  def test_ab_partition_too_big(self):
67    self.info_dict.update(common.LoadDictionaryFromLines("""
68        system_image_size=100
69        """.split("\n")))
70    with self.assertRaises(RuntimeError):
71      CheckPartitionSizes(self.info_dict)
72
73  def test_ab_group_too_big(self):
74    self.info_dict.update(common.LoadDictionaryFromLines("""
75        super_group_group_size=110
76        """.split("\n")))
77    with self.assertRaises(RuntimeError):
78      CheckPartitionSizes(self.info_dict)
79
80  def test_no_image(self):
81    del self.info_dict["system_image_size"]
82    with self.assertRaises(KeyError):
83      CheckPartitionSizes(self.info_dict)
84
85  def test_block_devices_not_match(self):
86    self.info_dict.update(common.LoadDictionaryFromLines("""
87        dynamic_partition_retrofit=true
88        super_block_devices=system vendor
89        super_system_device_size=80
90        super_vendor_device_size=25
91        super_partition_size=100
92        """.split("\n")))
93    with self.assertRaises(RuntimeError):
94      CheckPartitionSizes(self.info_dict)
95
96  def test_retrofit_vab(self):
97    self.info_dict.update(common.LoadDictionaryFromLines("""
98        virtual_ab=true
99        virtual_ab_retrofit=true
100        """.split("\n")))
101    CheckPartitionSizes(self.info_dict)
102
103  def test_retrofit_vab_too_big(self):
104    self.info_dict.update(common.LoadDictionaryFromLines("""
105        virtual_ab=true
106        virtual_ab_retrofit=true
107        system_image_size=100
108        """.split("\n")))
109    with self.assertRaises(RuntimeError):
110      CheckPartitionSizes(self.info_dict)
111
112  def test_vab(self):
113    self.info_dict.update(common.LoadDictionaryFromLines("""
114        virtual_ab=true
115        super_partition_size=100
116        super_super_device_size=100
117        """.split("\n")))
118    CheckPartitionSizes(self.info_dict)
119
120  def test_vab_too_big(self):
121    self.info_dict.update(common.LoadDictionaryFromLines("""
122        virtual_ab=true
123        super_partition_size=100
124        super_super_device_size=100
125        system_image_size=100
126        """.split("\n")))
127    with self.assertRaises(RuntimeError):
128      CheckPartitionSizes(self.info_dict)
129