From: Lennart Poettering Date: Fri, 6 Feb 2026 10:16:48 +0000 (+0100) Subject: tests: don't use "dd" to allocate empty files X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd2676c1abf26f47f9374c1dcc3757f47992c6fa;p=thirdparty%2Fsystemd.git tests: don't use "dd" to allocate empty files Let's use truncate -s … to create empty files (if they can be sparse) Let's use fallocate -l … to create empty non-sparse files. This should reduce the disk footprint of our tests a bit, given that in most cases we won't use the allocate disk space in full, not even remotely. --- diff --git a/test/units/TEST-13-NSPAWN.machined.sh b/test/units/TEST-13-NSPAWN.machined.sh index dbf126f1fcf..e48a2776abc 100755 --- a/test/units/TEST-13-NSPAWN.machined.sh +++ b/test/units/TEST-13-NSPAWN.machined.sh @@ -190,7 +190,7 @@ test ! -d /var/lib/machines/.hidden1 # Prepare a simple raw container mkdir -p /tmp/mnt -dd if=/dev/zero of=/var/tmp/container.raw bs=1M count=256 +truncate -s 256M /var/tmp/container.raw mkfs.ext4 /var/tmp/container.raw mount -o loop /var/tmp/container.raw /tmp/mnt cp -r /var/lib/machines/container1/* /tmp/mnt diff --git a/test/units/TEST-13-NSPAWN.nspawn.sh b/test/units/TEST-13-NSPAWN.nspawn.sh index ae5dfdce383..d17c08c02ab 100755 --- a/test/units/TEST-13-NSPAWN.nspawn.sh +++ b/test/units/TEST-13-NSPAWN.nspawn.sh @@ -77,7 +77,7 @@ testcase_sanity() { create_dummy_container "$template" # Create a simple image from the just created container template image="$(mktemp /var/lib/machines/TEST-13-NSPAWN.image-XXX.img)" - dd if=/dev/zero of="$image" bs=1M count=256 + truncate -s 256M "$image" mkfs.ext4 "$image" mkdir -p /mnt mount -o loop "$image" /mnt @@ -810,7 +810,7 @@ testcase_rootidmap() { root="$(mktemp -d /var/lib/machines/TEST-13-NSPAWN.rootidmap-path.XXX)" # Create ext4 image, as ext4 supports idmapped-mounts. mkdir -p /tmp/rootidmap/bind - dd if=/dev/zero of=/tmp/rootidmap/ext4.img bs=4k count=2048 + truncate -s $((4096*2048)) /tmp/rootidmap/ext4.img mkfs.ext4 /tmp/rootidmap/ext4.img mount /tmp/rootidmap/ext4.img /tmp/rootidmap/bind trap "rootidmap_cleanup /tmp/rootidmap/" RETURN @@ -854,7 +854,7 @@ testcase_owneridmap() { root="$(mktemp -d /var/lib/machines/TEST-13-NSPAWN.owneridmap-path.XXX)" # Create ext4 image, as ext4 supports idmapped-mounts. mkdir -p /tmp/owneridmap/bind - dd if=/dev/zero of=/tmp/owneridmap/ext4.img bs=4k count=2048 + truncate -s $((4096*2048)) /tmp/owneridmap/ext4.img mkfs.ext4 /tmp/owneridmap/ext4.img mount /tmp/owneridmap/ext4.img /tmp/owneridmap/bind trap "owneridmap_cleanup /tmp/owneridmap/" RETURN diff --git a/test/units/TEST-17-UDEV.sanity-check.sh b/test/units/TEST-17-UDEV.sanity-check.sh index 5f1a93e78f5..6246638fc94 100755 --- a/test/units/TEST-17-UDEV.sanity-check.sh +++ b/test/units/TEST-17-UDEV.sanity-check.sh @@ -25,7 +25,7 @@ netdev=hoge ip link add $netdev type dummy blk="$(mktemp)" -dd if=/dev/zero of="$blk" bs=1M count=1 +truncate -s 1M "$blk" loopdev="$(losetup --show -f "$blk")" # Wait for devices created in the above being processed. diff --git a/test/units/TEST-50-DISSECT.sh b/test/units/TEST-50-DISSECT.sh index 972272d3a47..14ff8ad250b 100755 --- a/test/units/TEST-50-DISSECT.sh +++ b/test/units/TEST-50-DISSECT.sh @@ -153,7 +153,7 @@ root_size="$(du --apparent-size -k "$MINIMAL_IMAGE.raw" | cut -f1)" verity_size="$(du --apparent-size -k "$MINIMAL_IMAGE.verity" | cut -f1)" signature_size=4 # 4MB seems to be the minimum size blkid will accept, below that probing fails -dd if=/dev/zero of="$MINIMAL_IMAGE.gpt" bs=512 count=$((8192+root_size*2+verity_size*2+signature_size*2)) +truncate -s $(((8192+root_size*2+verity_size*2+signature_size*2)*512)) "$MINIMAL_IMAGE.gpt" # sfdisk seems unhappy if the size overflows into the next unit, eg: 1580KiB will be interpreted as 1MiB # so do some basic rounding up if the minimal image is more than 1 MB if [[ "$root_size" -ge 1024 ]]; then diff --git a/test/units/TEST-55-OOMD.sh b/test/units/TEST-55-OOMD.sh index 19197309041..56a32926a04 100755 --- a/test/units/TEST-55-OOMD.sh +++ b/test/units/TEST-55-OOMD.sh @@ -26,7 +26,7 @@ if systemd-detect-virt --vm --quiet; then if [[ "$(findmnt -n -o FSTYPE /)" == btrfs ]]; then btrfs filesystem mkswapfile -s 64M /swapfile else - dd if=/dev/zero of=/swapfile bs=1M count=64 + fallocate -l 64M /swapfile chmod 0600 /swapfile mkswap /swapfile fi diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index 4ac4f2ee4b6..f25cf42c4b3 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -1708,7 +1708,7 @@ testcase_btrfs_compression() { # Must not be in tmpfs due to exclusions. It also must be large and # compressible so that the compression check succeeds later. src=/etc/test-source-file - dd if=/dev/zero of="$src" bs=1M count=1 2>/dev/null + fallocate -l 1M "$src" tee "$defs/btrfs-compressed.conf" < consisting of 4 LUNs, each # backed by a file diff --git a/test/units/TEST-67-INTEGRITY.sh b/test/units/TEST-67-INTEGRITY.sh index 0919f202487..667fa563434 100755 --- a/test/units/TEST-67-INTEGRITY.sh +++ b/test/units/TEST-67-INTEGRITY.sh @@ -48,8 +48,8 @@ EOF udevadm control --reload TMP_DIR="$(mktemp -d -t -p / integrity.tmp.XXXXXX)" -dd if=/dev/zero of="${TMP_DIR}/image" bs=1048576 count=64 -dd if=/dev/zero of="${TMP_DIR}/data" bs=1048576 count=64 +truncate -s 64M "${TMP_DIR}/image" +truncate -s 64M "${TMP_DIR}/data" LOOP="$(losetup --show -f "${TMP_DIR}/image")" udevadm wait --timeout=30 --settle "${LOOP}" diff --git a/test/units/TEST-87-AUX-UTILS-VM.mount.sh b/test/units/TEST-87-AUX-UTILS-VM.mount.sh index 92fa2eb9dce..5eba8e6bbc8 100755 --- a/test/units/TEST-87-AUX-UTILS-VM.mount.sh +++ b/test/units/TEST-87-AUX-UTILS-VM.mount.sh @@ -43,7 +43,7 @@ test -e "$WORK_DIR/upper/foo" systemd-umount "$WORK_DIR/overlay" # Set up a simple block device for further tests -dd if=/dev/zero of="$WORK_DIR/simple.img" bs=1M count=16 +truncate -s 16M "$WORK_DIR/simple.img" mkfs.ext4 -L sd-mount-test "$WORK_DIR/simple.img" LOOP="$(losetup --show --find "$WORK_DIR/simple.img")" udevadm wait --timeout=60 --settle "$LOOP"