1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#!/usr/bin/env python
#
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import mkuserimg_mke2fs
class MkuserimgMke2fsTest(unittest.TestCase):
def setUp(self):
self.optional_arguments = {
"-j": "10", "-T": "1230768000.0", "-C": "fs_config",
"-D": "product_out", "-B": "block_list_file",
"-d": "base_alloc_file_in", "-A": "base_alloc_file_out",
"-L": "label", "-i": "20", "-M": "30", "-e": "8192",
"-o": "16384", "-U": "mke2fs_uuid", "-S": "mke2fs_hash_seed",
}
def test_parse_arguments_smoke(self):
args_list = ["source_directory", "output_file", "ext4", "data", "8192"]
for key, value in self.optional_arguments.items():
args_list += [key, value]
args_list.append("-c")
args = mkuserimg_mke2fs.ParseArguments(args_list)
self.assertEqual("source_directory", args.src_dir)
self.assertEqual("output_file", args.output_file)
self.assertEqual("ext4", args.ext_variant)
self.assertEqual("data", args.mount_point)
self.assertEqual("8192", args.fs_size)
self.assertFalse(args.android_sparse)
self.assertEqual("10", args.journal_size)
self.assertEqual("1230768000.0", args.timestamp)
self.assertEqual("fs_config", args.fs_config)
self.assertEqual("product_out", args.product_out)
self.assertEqual("block_list_file", args.block_list_file)
self.assertEqual("base_alloc_file_in", args.base_alloc_file_in)
self.assertEqual("base_alloc_file_out", args.base_alloc_file_out)
self.assertEqual("label", args.label)
self.assertEqual("20", args.inodes)
self.assertEqual("30", args.reserved_percent)
self.assertEqual("8192", args.flash_erase_block_size)
self.assertEqual("16384", args.flash_logical_block_size)
self.assertEqual("mke2fs_uuid", args.mke2fs_uuid)
self.assertEqual("mke2fs_hash_seed", args.mke2fs_hash_seed)
self.assertTrue(args.share_dup_blocks)
def test_parse_arguments_with_filecontext(self):
args_list = ["-s", "source_directory", "output_file", "ext4", "data",
"8192"]
for key, value in self.optional_arguments.items():
args_list += [key, value]
args_list += ["-c", "file_contexts.bin"]
args = mkuserimg_mke2fs.ParseArguments(args_list)
self.assertEqual("file_contexts.bin", args.file_contexts)
self.assertEqual("source_directory", args.src_dir)
self.assertEqual("output_file", args.output_file)
self.assertEqual("ext4", args.ext_variant)
self.assertEqual("data", args.mount_point)
self.assertEqual("8192", args.fs_size)
self.assertTrue(args.android_sparse)
self.assertEqual("10", args.journal_size)
self.assertEqual("1230768000.0", args.timestamp)
self.assertEqual("fs_config", args.fs_config)
self.assertEqual("product_out", args.product_out)
self.assertEqual("block_list_file", args.block_list_file)
self.assertEqual("base_alloc_file_in", args.base_alloc_file_in)
self.assertEqual("base_alloc_file_out", args.base_alloc_file_out)
self.assertEqual("label", args.label)
self.assertEqual("20", args.inodes)
self.assertEqual("30", args.reserved_percent)
self.assertEqual("8192", args.flash_erase_block_size)
self.assertEqual("16384", args.flash_logical_block_size)
self.assertEqual("mke2fs_uuid", args.mke2fs_uuid)
self.assertEqual("mke2fs_hash_seed", args.mke2fs_hash_seed)
self.assertTrue(args.share_dup_blocks)
def test_parse_arguments_not_enough_arguments(self):
args_list = ["-s", "source_directory", "output_file", "ext4", "data",]
for key, value in self.optional_arguments.items():
args_list += [key, value]
with self.assertRaises(SystemExit):
mkuserimg_mke2fs.ParseArguments(args_list)
def test_construct_e2fs_opts_smoke(self):
args_list = ["-s", "source_directory", "output_file", "ext4", "data",
"8192"]
for key, value in self.optional_arguments.items():
args_list += [key, value]
args_list += ["-c", "file_contexts.bin"]
args = mkuserimg_mke2fs.ParseArguments(args_list)
mke2fs_cmd, e2fsdroid_cmd = mkuserimg_mke2fs.ConstructE2fsCommands(
args)
expected_mke2fs_extended_opts = (
"android_sparse,stripe_width=2,stride=4,hash_seed={}".format(
args.mke2fs_hash_seed))
expected_mke2fs_cmd = [
"mke2fs", "-J", "size=10", "-L", args.label, "-N", args.inodes, "-m",
args.reserved_percent, "-U", args.mke2fs_uuid, "-E",
expected_mke2fs_extended_opts, "-t", args.ext_variant, "-b", "4096",
args.output_file, str(int(args.fs_size) / 4096)]
expected_e2fsdroid_cmd = [
"e2fsdroid", "-T", args.timestamp, "-C", args.fs_config, "-p",
args.product_out, "-B", args.block_list_file, "-d",
args.base_alloc_file_in, "-D", args.base_alloc_file_out, "-s", "-S",
args.file_contexts, "-f", args.src_dir, "-a", args.mount_point,
args.output_file]
self.assertEqual(' '.join(mke2fs_cmd), ' '.join(expected_mke2fs_cmd))
self.assertEqual(' '.join(e2fsdroid_cmd),
' '.join(expected_e2fsdroid_cmd))
|