test_zerofree.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. import infra.basetest
  3. import subprocess
  4. class TestZerofree(infra.basetest.BRTest):
  5. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  6. """
  7. BR2_PACKAGE_ZEROFREE=y
  8. BR2_TARGET_ROOTFS_CPIO=y
  9. # BR2_TARGET_ROOTFS_TAR is not set
  10. """
  11. def test_run(self):
  12. # Prepare disk image.
  13. # We keep it small (8 MB) for the sake of test time.
  14. disk_file = os.path.join(self.outputdir, "disk.img")
  15. subprocess.check_call(
  16. ["dd", "if=/dev/zero", f"of={disk_file}", "bs=1M", "count=8"],
  17. stdout=self.emulator.logfile,
  18. stderr=self.emulator.logfile)
  19. # Run the emulator with a drive.
  20. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  21. self.emulator.boot(arch="armv5",
  22. kernel="builtin",
  23. options=[
  24. "-initrd", cpio_file,
  25. "-drive", f"file={disk_file},format=raw"])
  26. self.emulator.login()
  27. # Prepare filesystem.
  28. output, exit_code = self.emulator.run("mkfs.ext4 /dev/sda")
  29. self.assertEqual(exit_code, 0)
  30. self.assertIn('Creating filesystem', output[2])
  31. # Run zerofree on newly created filesystem.
  32. cmd = "zerofree -v /dev/sda"
  33. output, exit_code = self.emulator.run(cmd, timeout=60)
  34. self.assertEqual(exit_code, 0)
  35. self.assertIn('/8192', output[-1]) # total number of blocks