Tao Bao | d4349f2 | 2017-12-07 23:01:25 -0800 | [diff] [blame^] | 1 | # |
| 2 | # Copyright (C) 2017 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 | |
| 17 | import shutil |
| 18 | import tempfile |
| 19 | import unittest |
| 20 | |
| 21 | from build_image import CheckHeadroom, RunCommand |
| 22 | |
| 23 | |
| 24 | class BuildImageTest(unittest.TestCase): |
| 25 | |
| 26 | def test_CheckHeadroom_SizeUnderLimit(self): |
| 27 | ext4fs_output = ("Created filesystem with 2777/129024 inodes and " |
| 28 | "508140/516099 blocks") |
| 29 | prop_dict = { |
| 30 | 'partition_headroom' : '4194304', |
| 31 | 'mount_point' : 'system', |
| 32 | } |
| 33 | self.assertTrue(CheckHeadroom(ext4fs_output, prop_dict)) |
| 34 | |
| 35 | def test_CheckHeadroom_InsufficientHeadroom(self): |
| 36 | ext4fs_output = ("Created filesystem with 2777/129024 inodes and " |
| 37 | "515099/516099 blocks") |
| 38 | prop_dict = { |
| 39 | 'partition_headroom' : '4100096', |
| 40 | 'mount_point' : 'system', |
| 41 | } |
| 42 | self.assertFalse(CheckHeadroom(ext4fs_output, prop_dict)) |
| 43 | |
| 44 | def test_CheckHeadroom_WithMke2fsOutput(self): |
| 45 | """Tests the result parsing from actual call to mke2fs.""" |
| 46 | input_dir = tempfile.mkdtemp() |
| 47 | output_image = tempfile.NamedTemporaryFile(suffix='.img') |
| 48 | command = ['mkuserimg_mke2fs.sh', input_dir, output_image.name, 'ext4', |
| 49 | '/system', '409600', '-j', '0'] |
| 50 | ext4fs_output, exit_code = RunCommand(command) |
| 51 | self.assertEqual(0, exit_code) |
| 52 | |
| 53 | prop_dict = { |
| 54 | 'partition_headroom' : '40960', |
| 55 | 'mount_point' : 'system', |
| 56 | } |
| 57 | self.assertTrue(CheckHeadroom(ext4fs_output, prop_dict)) |
| 58 | |
| 59 | prop_dict = { |
| 60 | 'partition_headroom' : '413696', |
| 61 | 'mount_point' : 'system', |
| 62 | } |
| 63 | self.assertFalse(CheckHeadroom(ext4fs_output, prop_dict)) |
| 64 | |
| 65 | shutil.rmtree(input_dir) |