]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
loop: test partition scanning
authorOmar Sandoval <osandov@fb.com>
Fri, 28 Apr 2017 23:15:21 +0000 (16:15 -0700)
committerOmar Sandoval <osandov@fb.com>
Fri, 28 Apr 2017 23:19:29 +0000 (16:19 -0700)
First real test case.

Signed-off-by: Omar Sandoval <osandov@fb.com>
common/rc
tests/loop/001 [new file with mode: 0755]
tests/loop/001.out [new file with mode: 0644]
tests/loop/category [new file with mode: 0644]

index 4df6af1015c45d415a0dee54a1570efa996ba7ff..5593993456c337cc0fef28877003d7086c350d5a 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -25,3 +25,25 @@ _error() {
        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
+}
diff --git a/tests/loop/001 b/tests/loop/001
new file mode 100755 (executable)
index 0000000..0b58608
--- /dev/null
@@ -0,0 +1,39 @@
+#!/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"
+}
diff --git a/tests/loop/001.out b/tests/loop/001.out
new file mode 100644 (file)
index 0000000..75979f0
--- /dev/null
@@ -0,0 +1,3 @@
+Running loop/001
+3
+Test complete
diff --git a/tests/loop/category b/tests/loop/category
new file mode 100644 (file)
index 0000000..eb88630
--- /dev/null
@@ -0,0 +1,28 @@
+#!/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
+}