blob: 161faff8c8cc2c3e3554e1a6a37c24426da477cd [file] [log] [blame]
Tao Baod4349f22017-12-07 23:01:25 -08001#
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
Tao Baod4349f22017-12-07 23:01:25 -080017import unittest
18
Tao Baod8a953d2018-01-02 21:19:27 -080019import common
Tao Baod4349f22017-12-07 23:01:25 -080020from build_image import CheckHeadroom, RunCommand
21
22
23class BuildImageTest(unittest.TestCase):
24
Tao Baod8a953d2018-01-02 21:19:27 -080025 # Available: 1000 blocks.
26 EXT4FS_OUTPUT = (
27 "Created filesystem with 2777/129024 inodes and 515099/516099 blocks")
28
Tao Baod4349f22017-12-07 23:01:25 -080029 def test_CheckHeadroom_SizeUnderLimit(self):
Tao Baod8a953d2018-01-02 21:19:27 -080030 # Required headroom: 1000 blocks.
Tao Baod4349f22017-12-07 23:01:25 -080031 prop_dict = {
Tao Baod8a953d2018-01-02 21:19:27 -080032 'fs_type' : 'ext4',
33 'partition_headroom' : '4096000',
Tao Baod4349f22017-12-07 23:01:25 -080034 'mount_point' : 'system',
35 }
Tao Baod8a953d2018-01-02 21:19:27 -080036 self.assertTrue(CheckHeadroom(self.EXT4FS_OUTPUT, prop_dict))
Tao Baod4349f22017-12-07 23:01:25 -080037
38 def test_CheckHeadroom_InsufficientHeadroom(self):
Tao Baod8a953d2018-01-02 21:19:27 -080039 # Required headroom: 1001 blocks.
Tao Baod4349f22017-12-07 23:01:25 -080040 prop_dict = {
Tao Baod8a953d2018-01-02 21:19:27 -080041 'fs_type' : 'ext4',
Tao Baod4349f22017-12-07 23:01:25 -080042 'partition_headroom' : '4100096',
43 'mount_point' : 'system',
44 }
Tao Baod8a953d2018-01-02 21:19:27 -080045 self.assertFalse(CheckHeadroom(self.EXT4FS_OUTPUT, prop_dict))
46
47 def test_CheckHeadroom_WrongFsType(self):
48 prop_dict = {
49 'fs_type' : 'f2fs',
50 'partition_headroom' : '4100096',
51 'mount_point' : 'system',
52 }
53 self.assertRaises(
54 AssertionError, CheckHeadroom, self.EXT4FS_OUTPUT, prop_dict)
55
56 def test_CheckHeadroom_MissingProperties(self):
57 prop_dict = {
58 'fs_type' : 'ext4',
59 'partition_headroom' : '4100096',
60 }
61 self.assertRaises(
62 AssertionError, CheckHeadroom, self.EXT4FS_OUTPUT, prop_dict)
63
64 prop_dict = {
65 'fs_type' : 'ext4',
66 'mount_point' : 'system',
67 }
68 self.assertRaises(
69 AssertionError, CheckHeadroom, self.EXT4FS_OUTPUT, prop_dict)
Tao Baod4349f22017-12-07 23:01:25 -080070
71 def test_CheckHeadroom_WithMke2fsOutput(self):
72 """Tests the result parsing from actual call to mke2fs."""
Tao Baod8a953d2018-01-02 21:19:27 -080073 input_dir = common.MakeTempDir()
74 output_image = common.MakeTempFile(suffix='.img')
75 command = ['mkuserimg_mke2fs.sh', input_dir, output_image, 'ext4',
Tao Baod4349f22017-12-07 23:01:25 -080076 '/system', '409600', '-j', '0']
77 ext4fs_output, exit_code = RunCommand(command)
78 self.assertEqual(0, exit_code)
79
80 prop_dict = {
Tao Baod8a953d2018-01-02 21:19:27 -080081 'fs_type' : 'ext4',
Tao Baod4349f22017-12-07 23:01:25 -080082 'partition_headroom' : '40960',
83 'mount_point' : 'system',
84 }
85 self.assertTrue(CheckHeadroom(ext4fs_output, prop_dict))
86
87 prop_dict = {
Tao Baod8a953d2018-01-02 21:19:27 -080088 'fs_type' : 'ext4',
Tao Baod4349f22017-12-07 23:01:25 -080089 'partition_headroom' : '413696',
90 'mount_point' : 'system',
91 }
92 self.assertFalse(CheckHeadroom(ext4fs_output, prop_dict))
93
Tao Baod8a953d2018-01-02 21:19:27 -080094 common.Cleanup()