Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: detect loop devices with deleted files as an invariant #14568

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tests/lib/tools/tests.invariant
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading