kumquat-buildroot/support/testing/tests/package/test_zerofree.py
Vincent Stehlé 98ecdd1d11 package/zerofree: new package
zerofree is a utility which scans the free blocks in an ext2 filesystem
and fills any non-zero blocks with zeroes.

https://frippery.org/uml/

The ext2fs/ext2fs.h header guards the inclusion of <sys/types.h> behind
HAVE_SYS_TYPES_H, which is an autotools-defined macro that is only
supposed to be defined by the package itself, i.e. e2fsprogs, and that
should not leak into installed headers. However, e2fsprogs does leak it,
so we work it around, liek gentoo does.

Tested-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
[yann.morin.1998@free.fr:
  - fix MMU dependency for comment; reword comment
  - fix multi-line assignment of ZEROFREE_CFLAGS
  - do not add comment trailing after assignment
  - extend commit log to explain why we need the workaround
  - use TARGET_CONFIGURE_OPTS, drop explicit CC=
  - install to explicit destination file
]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
2022-07-17 14:05:54 +02:00

42 lines
1.5 KiB
Python

import os
import infra.basetest
import subprocess
class TestZerofree(infra.basetest.BRTest):
config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
"""
BR2_PACKAGE_ZEROFREE=y
BR2_TARGET_ROOTFS_CPIO=y
# BR2_TARGET_ROOTFS_TAR is not set
"""
def test_run(self):
# Prepare disk image.
# We keep it small (8 MB) for the sake of test time.
disk_file = os.path.join(self.outputdir, "disk.img")
subprocess.check_call(
["dd", "if=/dev/zero", f"of={disk_file}", "bs=1M", "count=8"],
stdout=self.emulator.logfile,
stderr=self.emulator.logfile)
# Run the emulator with a drive.
cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
self.emulator.boot(arch="armv5",
kernel="builtin",
options=[
"-initrd", cpio_file,
"-drive", f"file={disk_file},format=raw"])
self.emulator.login()
# Prepare filesystem.
output, exit_code = self.emulator.run("mkfs.ext4 /dev/sda")
self.assertEqual(exit_code, 0)
self.assertIn('Creating filesystem', output[2])
# Run zerofree on newly created filesystem.
cmd = "zerofree -v /dev/sda"
output, exit_code = self.emulator.run(cmd, timeout=60)
self.assertEqual(exit_code, 0)
self.assertIn('/8192', output[-1]) # total number of blocks