test_xfsprogs.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import os
  2. import subprocess
  3. import infra.basetest
  4. class TestXfsProgs(infra.basetest.BRTest):
  5. # This test needs a Kernel with XFS support.
  6. kern_frag = \
  7. infra.filepath("tests/package/test_xfsprogs/linux-xfs.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.37"
  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_XFSPROGS=y
  21. BR2_PACKAGE_OPENSSL=y
  22. BR2_TARGET_ROOTFS_CPIO=y
  23. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  24. # BR2_TARGET_ROOTFS_TAR is not set
  25. """
  26. def test_run(self):
  27. # Prepare the disk image. XFS requires at least 300MB of
  28. # storage to work.
  29. disk_file = os.path.join(self.builddir, "images", "disk.img")
  30. self.emulator.logfile.write(f"Creating disk image: {disk_file}")
  31. self.emulator.logfile.flush()
  32. subprocess.check_call(
  33. ["dd", "if=/dev/zero", f"of={disk_file}", "bs=1M", "count=512"],
  34. stdout=self.emulator.logfile,
  35. stderr=self.emulator.logfile)
  36. # Run the emulator with a blank drive.
  37. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  38. kern = os.path.join(self.builddir, "images", "Image")
  39. bootargs = ["console=ttyAMA0"]
  40. qemu_opts = ["-M", "virt", "-cpu", "cortex-a57", "-m", "256M",
  41. "-initrd", img,
  42. "-drive", f"file={disk_file},if=virtio,format=raw"]
  43. self.emulator.boot(arch="aarch64",
  44. kernel=kern,
  45. kernel_cmdline=bootargs,
  46. options=qemu_opts)
  47. self.emulator.login()
  48. # Check a program can run and show its version.
  49. self.assertRunOk("mkfs.xfs -V")
  50. # Variables for this test.
  51. dev = "/dev/vda"
  52. label = "BR_TEST"
  53. mnt_pt = "/tmp/xfs"
  54. data_file = f"{mnt_pt}/data.bin"
  55. # We create the XFS filesystem on our device.
  56. self.assertRunOk(f"mkfs.xfs {dev}")
  57. # We set a label on this filesystem.
  58. self.assertRunOk(f"xfs_admin -L '{label}' {dev}")
  59. # We create a mount point.
  60. self.assertRunOk(f"mkdir -p {mnt_pt}")
  61. # We mount the XFS filesystem.
  62. self.assertRunOk(f"mount {dev} {mnt_pt}")
  63. # We create a file with random data, to use this new
  64. # filesystem a bit.
  65. self.assertRunOk(f"dd if=/dev/urandom of={data_file} bs=1M count=10")
  66. # We compute the sha256 hash and save it for later.
  67. hash_cmd = f"sha256sum {data_file}"
  68. out, ret = self.emulator.run(hash_cmd)
  69. self.assertEqual(ret, 0)
  70. data_sha256 = out[0]
  71. # We unmount the filesystem.
  72. self.assertRunOk(f"umount {mnt_pt}")
  73. # We query the fragmentation level. Since it's a new
  74. # filesystem, we don't expect any filesystem
  75. # fragmentation. This invocation is just to test the "xfs_db"
  76. # program can run and read the filesystem.
  77. self.assertRunOk(f"xfs_db -c frag -r {dev}")
  78. # We run a repair (this tool is the equivalent of
  79. # "fsck"). Again, since we cleanly unmounted the filesystem,
  80. # we are not expecting any repair. This is just to test the
  81. # program works correctly.
  82. self.assertRunOk(f"xfs_repair {dev}")
  83. # We query the label and check it is the one we set at the
  84. # beginning.
  85. out, ret = self.emulator.run(f"xfs_admin -l {dev}")
  86. self.assertEqual(ret, 0)
  87. self.assertEqual(out[0], f"label = \"{label}\"")
  88. # We remount our filesystem.
  89. self.assertRunOk(f"mount {dev} {mnt_pt}")
  90. # We should recompute the same sha256 hash as before.
  91. out, ret = self.emulator.run(hash_cmd)
  92. self.assertEqual(ret, 0)
  93. self.assertEqual(out[0], data_sha256)