@@ -1719,6 +1719,7 @@ F: support/testing/tests/package/test_gnupg2.py
F: support/testing/tests/package/test_highway.py
F: support/testing/tests/package/test_hwloc.py
F: support/testing/tests/package/test_libjxl.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
new file mode 100644
@@ -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")
Signed-off-by: Julien Olivain <ju.o@free.fr> --- Patch tested on branch next at commit b793f3a with commands: python3 -m flake8 support/testing/tests/package/test_mtools.py [no-output] support/testing/run-tests \ -d dl -o output_folder \ tests.package.test_mtools ... OK --- DEVELOPERS | 1 + support/testing/tests/package/test_mtools.py | 72 ++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 support/testing/tests/package/test_mtools.py