diff --git a/tests/lib/tools/tests.invariant b/tests/lib/tools/tests.invariant index 4651cfd19f0..843b0934a1c 100755 --- a/tests/lib/tools/tests.invariant +++ b/tests/lib/tools/tests.invariant @@ -11,6 +11,7 @@ show_help() { echo " leftover-defer-sh: defer.sh must not be left over by tests" echo " broken-snaps: snaps must not be left around that are in a broken state" echo " segmentation-violations: snapd must not have segmentation-violation errors in journal logs" + echo " deleted-loop-devices: no loop devices associated with deleted files must exist" } if [ $# -eq 0 ]; then @@ -207,6 +208,17 @@ check_fakestore_cleaned() { fi } +check_deleted_loop_devices() { + n="$1" # invariant name + + losetup -l | grep -F ' (deleted)' > "$TESTSTMP/tests.invariant.$n" + if [ -s "$TESTSTMP/tests.invariant.$n" ]; then + echo "tests.invariant: detected loopback devices associated with deleted files" >&2 + cat "$TESTSTMP/tests.invariant.$n" >&2 + return 1 + fi +} + check_invariant() { case "$1" in root-files-in-home) @@ -236,6 +248,9 @@ check_invariant() { check-fakestore-cleaned) check_fakestore_cleaned ;; + deleted-loop-devices) + check_deleted_loop_devices "$1" + ;; *) echo "tests.invariant: unknown invariant $1" >&2 exit 1 @@ -244,7 +259,7 @@ check_invariant() { } main() { - ALL_INVARIANTS="root-files-in-home crashed-snap-confine lxcfs-mounted stray-dbus-daemon leftover-defer-sh broken-snaps cgroup-scopes segmentation-violations check-fakestore-cleaned" + ALL_INVARIANTS="root-files-in-home crashed-snap-confine lxcfs-mounted stray-dbus-daemon leftover-defer-sh broken-snaps cgroup-scopes segmentation-violations check-fakestore-cleaned deleted-loop-devices" case "$action" in check)