echo "$0: $@" >&2
exit 1
}
+
+_have_module() {
+ if modprobe -n "$1"; then
+ return 0
+ else
+ SKIP_REASON="$1 module is not available"
+ return 1
+ fi
+}
+
+_have_program() {
+ if command -v "$1" >/dev/null 2>&1; then
+ return 0
+ else
+ SKIP_REASON="$1 is not available"
+ return 1
+ fi
+}
+
+_have_loop() {
+ _have_module loop && _have_program losetup
+}
--- /dev/null
+#!/bin/bash
+#
+# Test loop device paritition scanning. Regression test for commit e02898b42380
+# ("loop: fix LO_FLAGS_PARTSCAN hang").
+#
+# Copyright (C) 2017 Omar Sandoval
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+TEST_GROUPS=(loop auto)
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ truncate -s 1M "$TMPDIR/img"
+ cat <<- EOF | sfdisk "$TMPDIR/img" >>"$FULL"
+ label: dos
+ start=1, size=1000, type=83
+ start=1001, size=1000, type=83
+ EOF
+
+ loop_device="$(losetup -P -f --show "$TMPDIR/img")"
+ lsblk -ln "$loop_device" | wc -l
+
+ losetup -d "$loop_device"
+ rm "$TMPDIR/img"
+ echo "Test complete"
+}
--- /dev/null
+#!/bin/bash
+#
+# Loop device tests.
+#
+# Copyright (C) 2017 Omar Sandoval
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. common/rc
+
+prepare() {
+ _have_loop
+}
+
+prepare_device() {
+ return 0
+}