2
1

test_mtools.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import os
  2. import infra.basetest
  3. class TestMtools(infra.basetest.BRTest):
  4. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  5. """
  6. BR2_PACKAGE_MTOOLS=y
  7. BR2_TARGET_ROOTFS_CPIO=y
  8. # BR2_TARGET_ROOTFS_TAR is not set
  9. """
  10. def test_run(self):
  11. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  12. self.emulator.boot(arch="armv5",
  13. kernel="builtin",
  14. options=["-initrd", cpio_file])
  15. self.emulator.login()
  16. dos_img = "dos-fat.img"
  17. mtools_opts = f"-i {dos_img}"
  18. self.assertRunOk("mtools --version")
  19. # Create an empty image file to hold the FAT partition
  20. self.assertRunOk(f"dd if=/dev/zero of={dos_img} bs=1M count=1")
  21. # Any Mtools command is expected to fail on an unformatted
  22. # partition.
  23. cmd = f"minfo {mtools_opts} ::"
  24. _, exit_code = self.emulator.run(cmd)
  25. self.assertNotEqual(exit_code, 0)
  26. # Now, let's format the partition file to FAT
  27. self.assertRunOk(f"mformat {mtools_opts} ::")
  28. # Run some Mtools commands on this empty partition
  29. self.assertRunOk(f"minfo {mtools_opts} ::")
  30. self.assertRunOk(f"mdir {mtools_opts} ::")
  31. self.assertRunOk(f"mlabel {mtools_opts} -N 12345678 ::BUILDROOT")
  32. # Create a reference file on our Linux filesystem
  33. self.assertRunOk("echo 'Hello Buildroot!' > file1.txt")
  34. # Copy the reference file into the DOS image, then perform
  35. # various file manipulations
  36. self.assertRunOk(f"mcopy {mtools_opts} file1.txt ::file2.txt")
  37. self.assertRunOk(f"mcopy {mtools_opts} ::file2.txt ::file3.txt")
  38. self.assertRunOk(f"mdel {mtools_opts} ::file2.txt")
  39. self.assertRunOk(f"mren {mtools_opts} ::file3.txt ::file4.txt")
  40. self.assertRunOk(f"mmd {mtools_opts} ::dir1")
  41. self.assertRunOk(f"mmove {mtools_opts} ::file4.txt ::dir1")
  42. self.assertRunOk(f"mdir {mtools_opts} ::dir1")
  43. self.assertRunOk(f"mdu {mtools_opts} -a ::")
  44. # Copy back the file from the DOS image to the Linux
  45. # filesystem
  46. self.assertRunOk(f"mcopy {mtools_opts} ::dir1/file4.txt file5.txt")
  47. # We expect this last copied file to have the same content as
  48. # the reference one created at the beginning
  49. self.assertRunOk("cmp file1.txt file5.txt")
  50. # Delete a directory tree containing a file
  51. self.assertRunOk(f"mdeltree {mtools_opts} ::dir1")