xref: /OK3568_Linux_fs/buildroot/support/testing/tests/fs/test_ext.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1import os
2
3import infra.basetest
4
5VOLNAME_PROP = "Filesystem volume name"
6REVISION_PROP = "Filesystem revision #"
7FEATURES_PROP = "Filesystem features"
8BLOCKCNT_PROP = "Block count"
9INODECNT_PROP = "Inode count"
10RESBLKCNT_PROP = "Reserved block count"
11
12CHECK_FS_TYPE_CMD = "mount | grep '/dev/root on / type {}'"
13
14
15def dumpe2fs_run(builddir, image):
16    cmd = ["host/sbin/dumpe2fs", os.path.join("images", image)]
17    ret = infra.run_cmd_on_host(builddir, cmd)
18    return ret.strip().splitlines()
19
20
21def dumpe2fs_getprop(out, prop):
22    for line in out:
23        fields = line.split(": ")
24        if fields[0] == prop:
25            return fields[1].strip()
26
27
28def boot_img_and_check_fs_type(emulator, builddir, fs_type):
29    img = os.path.join(builddir, "images", "rootfs.{}".format(fs_type))
30    emulator.boot(arch="armv7",
31                  kernel="builtin",
32                  kernel_cmdline=["root=/dev/mmcblk0",
33                                  "rootfstype={}".format(fs_type)],
34                  options=["-drive", "file={},if=sd,format=raw".format(img)])
35    emulator.login()
36    _, exit_code = emulator.run(CHECK_FS_TYPE_CMD.format(fs_type))
37    return exit_code
38
39
40class TestExt2(infra.basetest.BRTest):
41    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
42        """
43        BR2_TARGET_ROOTFS_EXT2=y
44        BR2_TARGET_ROOTFS_EXT2_2r0=y
45        BR2_TARGET_ROOTFS_EXT2_LABEL="foobaz"
46        BR2_TARGET_ROOTFS_EXT2_SIZE="16384"
47        # BR2_TARGET_ROOTFS_TAR is not set
48        """
49
50    def test_run(self):
51        out = dumpe2fs_run(self.builddir, "rootfs.ext2")
52        self.assertEqual(dumpe2fs_getprop(out, VOLNAME_PROP), "foobaz")
53        self.assertEqual(dumpe2fs_getprop(out, REVISION_PROP), "0 (original)")
54
55        exit_code = boot_img_and_check_fs_type(self.emulator,
56                                               self.builddir, "ext2")
57        self.assertEqual(exit_code, 0)
58
59
60class TestExt2r1(infra.basetest.BRTest):
61    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
62        """
63        BR2_TARGET_ROOTFS_EXT2=y
64        BR2_TARGET_ROOTFS_EXT2_2r1=y
65        BR2_TARGET_ROOTFS_EXT2_LABEL="foobar"
66        BR2_TARGET_ROOTFS_EXT2_SIZE="16384"
67        # BR2_TARGET_ROOTFS_TAR is not set
68        """
69
70    def test_run(self):
71        out = dumpe2fs_run(self.builddir, "rootfs.ext2")
72        self.assertEqual(dumpe2fs_getprop(out, VOLNAME_PROP), "foobar")
73        self.assertEqual(dumpe2fs_getprop(out, REVISION_PROP), "1 (dynamic)")
74        self.assertNotIn("has_journal", dumpe2fs_getprop(out, FEATURES_PROP))
75
76        exit_code = boot_img_and_check_fs_type(self.emulator,
77                                               self.builddir, "ext2")
78        self.assertEqual(exit_code, 0)
79
80
81class TestExt3(infra.basetest.BRTest):
82    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
83        """
84        BR2_TARGET_ROOTFS_EXT2=y
85        BR2_TARGET_ROOTFS_EXT2_3=y
86        BR2_TARGET_ROOTFS_EXT2_SIZE="16384"
87        # BR2_TARGET_ROOTFS_TAR is not set
88        """
89
90    def test_run(self):
91        out = dumpe2fs_run(self.builddir, "rootfs.ext3")
92        self.assertEqual(dumpe2fs_getprop(out, REVISION_PROP), "1 (dynamic)")
93        self.assertIn("has_journal", dumpe2fs_getprop(out, FEATURES_PROP))
94        self.assertNotIn("extent", dumpe2fs_getprop(out, FEATURES_PROP))
95
96        exit_code = boot_img_and_check_fs_type(self.emulator,
97                                               self.builddir, "ext3")
98        self.assertEqual(exit_code, 0)
99
100
101class TestExt4(infra.basetest.BRTest):
102    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
103        """
104        BR2_TARGET_ROOTFS_EXT2=y
105        BR2_TARGET_ROOTFS_EXT2_4=y
106        BR2_TARGET_ROOTFS_EXT2_SIZE="16384"
107        BR2_TARGET_ROOTFS_EXT2_INODES=3000
108        BR2_TARGET_ROOTFS_EXT2_RESBLKS=10
109        # BR2_TARGET_ROOTFS_TAR is not set
110        """
111
112    def test_run(self):
113        out = dumpe2fs_run(self.builddir, "rootfs.ext4")
114        self.assertEqual(dumpe2fs_getprop(out, REVISION_PROP), "1 (dynamic)")
115        self.assertEqual(dumpe2fs_getprop(out, BLOCKCNT_PROP), "16384")
116        # Yes there are 8 fewer inodes than requested
117        self.assertEqual(dumpe2fs_getprop(out, INODECNT_PROP), "2992")
118        self.assertEqual(dumpe2fs_getprop(out, RESBLKCNT_PROP), "1638")
119        self.assertIn("has_journal", dumpe2fs_getprop(out, FEATURES_PROP))
120        self.assertIn("extent", dumpe2fs_getprop(out, FEATURES_PROP))
121
122        exit_code = boot_img_and_check_fs_type(self.emulator,
123                                               self.builddir, "ext4")
124        self.assertEqual(exit_code, 0)
125