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