datalad-core/tools/eval_under_testloopfs
Michael Hanke ccd62f6c21
test: (also) run test battery on a crippled filesystem
This triggers git-annex's adjusted-mode branches.

This changeset also readys the tests.

A CI workflow is not added, because presently there are no "rootful"
runners that would allow for creating the necessary loopback device.
2026-07-21 03:59:06 +02:00

35 lines
802 B
Shell
Executable file

#!/bin/bash
# Evaluate given command while running with DATALAD_TESTS_TEMP_DIR pointing to
# that temporary filesystem mounted using loop device
set -e
fs=${DATALAD_TESTS_TEMP_FS:-vfat}
size=${DATALAD_TESTS_TEMP_FSSIZE:-200}
set -u
tmp=$(mktemp -u "${TMPDIR:-/tmp}/datalad-fs-XXXXX")
echo "I: $fs of $size: $tmp"
uid=$(id -u)
mntimage="$tmp.img"
mntpoint="$tmp"
dd if=/dev/zero "of=$mntimage" bs=1032192c "count=$size"
loop=$(sudo losetup --find --show "$mntimage")
sudo "mkfs.$fs" "$loop"
mkdir -p "$mntpoint"
sudo mount -o "uid=$uid" "$loop" "$mntpoint"
# Run the actual command
echo "I: running $*"
set +e
TMPDIR="$mntpoint" DATALAD_TESTS_TEMP_DIR="$mntpoint" "$@"
ret=$?
echo "I: done, unmounting"
sudo umount "$mntpoint"
sudo losetup -d "$loop"
rm -rf "$mntpoint" "$mntimage"
exit "$ret"