test_exfatprogs.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import os
  2. import subprocess
  3. import infra.basetest
  4. class TestExfatProgs(infra.basetest.BRTest):
  5. # This test needs a Kernel with exfat support.
  6. kern_frag = \
  7. infra.filepath("tests/package/test_exfatprogs/linux-exfat.fragment")
  8. config = \
  9. f"""
  10. BR2_aarch64=y
  11. BR2_TOOLCHAIN_EXTERNAL=y
  12. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  13. BR2_LINUX_KERNEL=y
  14. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  15. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.6.47"
  16. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  17. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  18. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kern_frag}"
  19. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  20. BR2_PACKAGE_EXFATPROGS=y
  21. BR2_TARGET_ROOTFS_CPIO=y
  22. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  23. # BR2_TARGET_ROOTFS_TAR is not set
  24. """
  25. def test_run(self):
  26. # Prepare the disk image.
  27. disk_file = os.path.join(self.builddir, "images", "disk.img")
  28. self.emulator.logfile.write(f"Creating disk image: {disk_file}")
  29. self.emulator.logfile.flush()
  30. subprocess.check_call(
  31. ["dd", "if=/dev/zero", f"of={disk_file}", "bs=1M", "count=256"],
  32. stdout=self.emulator.logfile,
  33. stderr=self.emulator.logfile)
  34. # Run the emulator with a blank drive.
  35. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  36. kern = os.path.join(self.builddir, "images", "Image")
  37. bootargs = ["console=ttyAMA0"]
  38. qemu_opts = ["-M", "virt", "-cpu", "cortex-a57", "-m", "256M",
  39. "-initrd", img,
  40. "-drive", f"file={disk_file},if=virtio,format=raw"]
  41. self.emulator.boot(arch="aarch64",
  42. kernel=kern,
  43. kernel_cmdline=bootargs,
  44. options=qemu_opts)
  45. self.emulator.login()
  46. # Variables for this test.
  47. dev = "/dev/vda"
  48. label = "BR_TEST"
  49. mnt_pt = "/tmp/exfat"
  50. data_file = f"{mnt_pt}/data.bin"
  51. # We create the exfat filesystem on our device.
  52. self.assertRunOk(f"mkfs.exfat {dev}")
  53. # We set a label on this filesystem.
  54. self.assertRunOk(f"exfatlabel {dev} '{label}'")
  55. # We create a mount point and mount this filesystem.
  56. self.assertRunOk(f"mkdir -p {mnt_pt}")
  57. self.assertRunOk(f"mount {dev} {mnt_pt}")
  58. # We create a file with random data, to use this new
  59. # filesystem a bit.
  60. self.assertRunOk(f"dd if=/dev/urandom of={data_file} bs=1M count=10")
  61. # We compute the sha256 hash and save it for later.
  62. hash_cmd = f"sha256sum {data_file}"
  63. out, ret = self.emulator.run(hash_cmd)
  64. self.assertEqual(ret, 0)
  65. data_sha256 = out[0]
  66. # We unmount the filesystem.
  67. self.assertRunOk(f"umount {mnt_pt}")
  68. # We run a filesystem check. Since we cleanly unmounted the
  69. # filesystem, we are not expecting any repair. This is just to
  70. # test the program works correctly.
  71. self.assertRunOk(f"fsck.exfat -v {dev}")
  72. # We query the label and check it is the one we set at the
  73. # beginning.
  74. out, ret = self.emulator.run(f"exfatlabel {dev}")
  75. self.assertEqual(ret, 0)
  76. self.assertEqual(out[1], f"label: {label}")
  77. # We remount our filesystem.
  78. self.assertRunOk(f"mount {dev} {mnt_pt}")
  79. # We should recompute the same sha256 hash as before, on the
  80. # first data file we created at the beginning.
  81. out, ret = self.emulator.run(hash_cmd)
  82. self.assertEqual(ret, 0)
  83. self.assertEqual(out[0], data_sha256)