[Buildroot] [git commit] support/testing/tests/package/test_mtools.py: new runtime test

Thomas Petazzoni thomas.petazzoni at bootlin.com
Sun Mar 12 22:12:06 UTC 2023


commit: https://git.buildroot.net/buildroot/commit/?id=655b18053a344927b9372ff88302b082b1dba2f0
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master

Signed-off-by: Julien Olivain <ju.o at free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
---
 DEVELOPERS                                   |  1 +
 support/testing/tests/package/test_mtools.py | 72 ++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/DEVELOPERS b/DEVELOPERS
index 6c3498484f..592c0e6b9c 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1739,6 +1739,7 @@ F:	support/testing/tests/package/test_kexec.py
 F:	support/testing/tests/package/test_kexec/
 F:	support/testing/tests/package/test_libjxl.py
 F:	support/testing/tests/package/test_lsof.py
+F:	support/testing/tests/package/test_mtools.py
 F:	support/testing/tests/package/test_ncdu.py
 F:	support/testing/tests/package/test_octave.py
 F:	support/testing/tests/package/test_ola.py
diff --git a/support/testing/tests/package/test_mtools.py b/support/testing/tests/package/test_mtools.py
new file mode 100644
index 0000000000..51e5138481
--- /dev/null
+++ b/support/testing/tests/package/test_mtools.py
@@ -0,0 +1,72 @@
+import os
+
+import infra.basetest
+
+
+class TestMtools(infra.basetest.BRTest):
+    # We use a glibc toolchain to have iconv conversion working for
+    # codepage 850.
+    config = \
+        """
+        BR2_arm=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
+        BR2_PACKAGE_MTOOLS=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv5",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
+
+        dos_img = "dos-fat.img"
+        mtools_opts = f"-i {dos_img}"
+
+        self.assertRunOk("mtools --version")
+
+        # Create an empty image file to hold the FAT partition
+        self.assertRunOk(f"dd if=/dev/zero of={dos_img} bs=1M count=1")
+
+        # Any Mtools command is expected to fail on an unformated
+        # partition.
+        cmd = f"minfo {mtools_opts} ::"
+        _, exit_code = self.emulator.run(cmd)
+        self.assertNotEqual(exit_code, 0)
+
+        # Now, let's format the partition file to FAT
+        self.assertRunOk(f"mformat {mtools_opts} ::")
+
+        # Run some Mtools commands on this empty partition
+        self.assertRunOk(f"minfo {mtools_opts} ::")
+        self.assertRunOk(f"mdir {mtools_opts} ::")
+        self.assertRunOk(f"mlabel {mtools_opts} -N 12345678 ::BUILDROOT")
+
+        # Create a reference file on our Linux filesystem
+        self.assertRunOk("echo 'Hello Buildroot!' > file1.txt")
+
+        # Copy the reference file into the DOS image, then perform
+        # various file manipulations
+        self.assertRunOk(f"mcopy {mtools_opts} file1.txt ::file2.txt")
+        self.assertRunOk(f"mcopy {mtools_opts} ::file2.txt ::file3.txt")
+        self.assertRunOk(f"mdel {mtools_opts} ::file2.txt")
+        self.assertRunOk(f"mren {mtools_opts} ::file3.txt ::file4.txt")
+        self.assertRunOk(f"mmd {mtools_opts} ::dir1")
+        self.assertRunOk(f"mmove {mtools_opts} ::file4.txt ::dir1")
+        self.assertRunOk(f"mdir {mtools_opts} ::dir1")
+        self.assertRunOk(f"mdu {mtools_opts} -a ::")
+
+        # Copy back the file from the DOS image to the Linux
+        # filesystem
+        self.assertRunOk(f"mcopy {mtools_opts} ::dir1/file4.txt file5.txt")
+
+        # We expect this last copied file to have the same content as
+        # the reference one created at the beginning
+        self.assertRunOk("cmp file1.txt file5.txt")
+
+        # Delete a directory tree containing a file
+        self.assertRunOk(f"mdeltree {mtools_opts} ::dir1")



More information about the buildroot mailing list