]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
loop: test direct I/O mode + custom block size
authorOmar Sandoval <osandov@fb.com>
Fri, 18 Aug 2017 19:22:58 +0000 (12:22 -0700)
committerOmar Sandoval <osandov@fb.com>
Tue, 22 Aug 2017 17:59:34 +0000 (10:59 -0700)
Signed-off-by: Omar Sandoval <osandov@fb.com>
common/loop [new file with mode: 0644]
tests/loop/002
tests/loop/004 [new file with mode: 0755]
tests/loop/004.out [new file with mode: 0644]

diff --git a/common/loop b/common/loop
new file mode 100644 (file)
index 0000000..eb8027c
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/bash
+#
+# Loop device helper functions.
+#
+# 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/>.
+
+
+_have_lo_flags_blocksize() {
+       local tmpfile loop_dev
+
+       # XXX: $TMPDIR isn't set up for requires(), should it be?
+       if ! tmpfile="$(mktemp "blktests.${TEST_NAME//\//.}.XXX")" ||
+          ! truncate -s 1M "$tmpfile"; then
+               SKIP_REASON="could not create temporary file"
+               return 1
+       fi
+
+       if ! loop_dev="$(losetup -f --show "$tmpfile" 2>/dev/null)"; then
+               SKIP_REASON="could not get loop device"
+               rm -f "$tmpfile"
+               return 1
+       fi
+
+       if ! src/loblksize "$loop_dev" >/dev/null 2>&1; then
+               SKIP_REASON="kernel does not support LO_FLAGS_BLOCKSIZE"
+               losetup -d "$loop_dev"
+               rm -f "$tmpfile"
+               return 1
+       fi
+
+       losetup -d "$loop_dev"
+       rm -f "$tmpfile"
+       return 0
+}
index 533e9932408910fa074c317468021e2b68f0c720..8f03070ae5030d55ad0efcea45b5d22e9d371495 100755 (executable)
 # 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/loop
+
 DESCRIPTION="try various loop device block sizes"
 QUICK=1
 
 requires() {
-       local tmpfile loop_dev
-
-       if ! _have_src_program loblksize; then
-               return 1
-       fi
-
-       # XXX: $TMPDIR isn't set up for requires(), should it be?
-       if ! tmpfile="$(mktemp "blktests.${TEST_NAME//\//.}.XXX")" ||
-          ! truncate -s 1M "$tmpfile"; then
-               SKIP_REASON="could not create temporary file"
-               return 1
-       fi
-
-       if ! loop_dev="$(losetup -f --show "$tmpfile" 2>/dev/null)"; then
-               SKIP_REASON="could not get loop device"
-               rm -f "$tmpfile"
-               return 1
-       fi
-
-       if ! src/loblksize "$loop_dev" >/dev/null 2>&1; then
-               SKIP_REASON="kernel does not support LO_FLAGS_BLOCKSIZE"
-               losetup -d "$loop_dev"
-               rm -f "$tmpfile"
-               return 1
-       fi
-
-       losetup -d "$loop_dev"
-       rm -f "$tmpfile"
-       return 0
+       _have_program xfs_io && _have_src_program loblksize && _have_lo_flags_blocksize
 }
 
 test() {
diff --git a/tests/loop/004 b/tests/loop/004
new file mode 100755 (executable)
index 0000000..c5c96e4
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# Tests LO_FLAGS_BLOCKSIZE together with LO_FLAGS_DIRECT_IO.
+#
+# 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/loop
+. common/scsi_debug
+
+DESCRIPTION="combine loop direct I/O mode and a custom block size"
+QUICK=1
+
+requires() {
+       _have_program xfs_io && _have_scsi_debug && _have_src_program loblksize && _have_lo_flags_blocksize
+}
+
+test() {
+       local loop_dev
+
+       echo "Running ${TEST_NAME}"
+
+       if ! _init_scsi_debug sector_size=4096; then
+               return 1
+       fi
+
+       if ! loop_dev="$(losetup -f --show "/dev/${SCSI_DEBUG_DEVICES[0]}")"; then
+               _exit_scsi_debug
+               return 1
+       fi
+
+       src/loblksize "$loop_dev" 4096
+       losetup --direct-io=on "$loop_dev"
+       cat "/sys/block/${loop_dev#/dev/}/loop/dio"
+       xfs_io -f -d -c 'pwrite 0 4096' "$loop_dev" >/dev/null
+       dd if="$loop_dev" bs=4096 count=1 iflag=direct status=none | sha256sum
+
+       losetup -d "$loop_dev"
+       udevadm settle
+       _exit_scsi_debug
+
+       echo "Test complete"
+}
diff --git a/tests/loop/004.out b/tests/loop/004.out
new file mode 100644 (file)
index 0000000..787e80f
--- /dev/null
@@ -0,0 +1,4 @@
+Running loop/004
+1
+769bd186841c10e5b1106b55986206c0e87fc05a7f565fdee01b5abcaff6ae78  -
+Test complete