]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: Add losetup-loop test suite
authorStanislav Brabec <sbrabec@suse.cz>
Tue, 2 Aug 2016 18:00:46 +0000 (20:00 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Aug 2016 11:02:35 +0000 (13:02 +0200)
Add losetup loop test suite that tests proper behavior of conflicting and
re-used loop devices.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
12 files changed:
tests/expected/losetup/losetup-loop [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-conflict [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-conflict-no-sizelimit [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-conflict-readonly [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-no-re-use [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-ok-no-sizelimit [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-race-condition [new file with mode: 0644]
tests/expected/losetup/losetup-loop-find-re-use [new file with mode: 0644]
tests/expected/losetup/losetup-loop-plain-conflict [new file with mode: 0644]
tests/expected/losetup/losetup-loop-plain-re-use [new file with mode: 0644]
tests/expected/losetup/losetup-loop-plain-readonly [new file with mode: 0644]
tests/ts/losetup/losetup-loop [new file with mode: 0755]

diff --git a/tests/expected/losetup/losetup-loop b/tests/expected/losetup/losetup-loop
new file mode 100644 (file)
index 0000000..3582111
--- /dev/null
@@ -0,0 +1 @@
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-conflict b/tests/expected/losetup/losetup-loop-find-conflict
new file mode 100644 (file)
index 0000000..6fd668b
--- /dev/null
@@ -0,0 +1,3 @@
+Failed to create loop device
+different
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-conflict-no-sizelimit b/tests/expected/losetup/losetup-loop-find-conflict-no-sizelimit
new file mode 100644 (file)
index 0000000..6fd668b
--- /dev/null
@@ -0,0 +1,3 @@
+Failed to create loop device
+different
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-conflict-readonly b/tests/expected/losetup/losetup-loop-find-conflict-readonly
new file mode 100644 (file)
index 0000000..6fd668b
--- /dev/null
@@ -0,0 +1,3 @@
+Failed to create loop device
+different
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-no-re-use b/tests/expected/losetup/losetup-loop-find-no-re-use
new file mode 100644 (file)
index 0000000..3acb7f8
--- /dev/null
@@ -0,0 +1,2 @@
+different
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-ok-no-sizelimit b/tests/expected/losetup/losetup-loop-find-ok-no-sizelimit
new file mode 100644 (file)
index 0000000..3acb7f8
--- /dev/null
@@ -0,0 +1,2 @@
+different
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-race-condition b/tests/expected/losetup/losetup-loop-find-race-condition
new file mode 100644 (file)
index 0000000..6533079
--- /dev/null
@@ -0,0 +1,2 @@
+0
+Success
diff --git a/tests/expected/losetup/losetup-loop-find-re-use b/tests/expected/losetup/losetup-loop-find-re-use
new file mode 100644 (file)
index 0000000..f58a43c
--- /dev/null
@@ -0,0 +1,2 @@
+equal
+Success
diff --git a/tests/expected/losetup/losetup-loop-plain-conflict b/tests/expected/losetup/losetup-loop-plain-conflict
new file mode 100644 (file)
index 0000000..3c8cd8f
--- /dev/null
@@ -0,0 +1,2 @@
+1
+Success
diff --git a/tests/expected/losetup/losetup-loop-plain-re-use b/tests/expected/losetup/losetup-loop-plain-re-use
new file mode 100644 (file)
index 0000000..6533079
--- /dev/null
@@ -0,0 +1,2 @@
+0
+Success
diff --git a/tests/expected/losetup/losetup-loop-plain-readonly b/tests/expected/losetup/losetup-loop-plain-readonly
new file mode 100644 (file)
index 0000000..3c8cd8f
--- /dev/null
@@ -0,0 +1,2 @@
+1
+Success
diff --git a/tests/ts/losetup/losetup-loop b/tests/ts/losetup/losetup-loop
new file mode 100755 (executable)
index 0000000..45403cb
--- /dev/null
@@ -0,0 +1,228 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2016 Stanislav Brabec <sbrabec@suse.cz>
+#
+# This file is part of util-linux.
+#
+# This file 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 2 of the License, or
+# (at your option) any later version.
+#
+# This file 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.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="losetup-loop"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LOSETUP"
+ts_check_test_command "$TS_CMD_LSBLK"
+
+ts_skip_nonroot
+ts_check_losetup
+
+. "$TS_SELF/losetup_functions.sh"
+
+#
+# Backing file is a block device
+#
+ts_scsi_debug_init dev_size_mb=11
+BACKFILE="$TS_DEVICE"
+
+# All tests are separated by sleep 3, because loop device exists some time after
+# "losetup -d". This device confuses some tests. And find-race-condition, tests,
+# whether re-use of this device works.
+
+ts_init_subtest "find-race-condition"
+LODEV=$( $TS_CMD_LOSETUP --find --show $BACKFILE )
+$TS_CMD_LOSETUP -d $LODEV
+LODEV=$( $TS_CMD_LOSETUP --find --show $BACKFILE )
+sleep 3
+dd if=/dev/zero of=$LODEV count=1 bs=1 >/dev/null 2>&1
+sleep 3
+$TS_CMD_LOSETUP --list | grep -q $LODEV
+ts_log $?
+$TS_CMD_LOSETUP -d $LODEV >/dev/null 2>&1
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "find-re-use"
+LODEV=$( $TS_CMD_LOSETUP --find --show $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find --show $BACKFILE )
+if [ -z "$LODEVR" ]; then
+       ts_log "Failed to create loop device"
+fi
+if test "$LODEV" = "$LODEVR" ; then
+       echo "equal" >>$TS_OUTPUT
+else
+       echo "different" >>$TS_OUTPUT
+       if test -n "$LODEVR" ; then
+               $TS_CMD_LOSETUP -d $LODEVR
+       fi
+fi
+$TS_CMD_LOSETUP -d $LODEV
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "find-no-re-use"
+LODEV=$( $TS_CMD_LOSETUP --find --show --offset=0 --sizelimit=1MiB $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find --show --offset=1MiB --sizelimit=1MiB $BACKFILE )
+if [ -z "$LODEVR" ]; then
+       ts_log "Failed to create loop device"
+fi
+if test "$LODEV" = "$LODEVR" ; then
+       echo "equal" >>$TS_OUTPUT
+else
+       echo "different" >>$TS_OUTPUT
+       if test -n "$LODEVR" ; then
+               $TS_CMD_LOSETUP -d $LODEVR
+       fi
+fi
+$TS_CMD_LOSETUP -d $LODEV
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "find-conflict"
+LODEV=$( $TS_CMD_LOSETUP --find --show --offset=1MiB --sizelimit=2MiB $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find --show --offset=2MiB --sizelimit=2MiB $BACKFILE >/dev/null 2>&1 )
+if [ -z "$LODEVR" ]; then
+       ts_log "Failed to create loop device"
+fi
+if test "$LODEV" = "$LODEVR" ; then
+       echo "equal" >>$TS_OUTPUT
+else
+       echo "different" >>$TS_OUTPUT
+       if test -n "$LODEVR" ; then
+               $TS_CMD_LOSETUP -d $LODEVR
+       fi
+fi
+$TS_CMD_LOSETUP -d $LODEV
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "find-conflict-no-sizelimit"
+LODEV=$( $TS_CMD_LOSETUP --find --show --offset=1MiB $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find --show --offset=2MiB --sizelimit=2MiB $BACKFILE >/dev/null 2>&1 )
+if [ -z "$LODEVR" ]; then
+       ts_log "Failed to create loop device"
+fi
+if test "$LODEV" = "$LODEVR" ; then
+       echo "equal" >>$TS_OUTPUT
+else
+       echo "different" >>$TS_OUTPUT
+       if test -n "$LODEVR" ; then
+               $TS_CMD_LOSETUP -d $LODEVR
+       fi
+fi
+$TS_CMD_LOSETUP -d $LODEV
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "find-conflict-readonly"
+LODEV=$( $TS_CMD_LOSETUP --find --show --read-only $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find --show --offset=2MiB --sizelimit=2MiB $BACKFILE >/dev/null 2>&1 )
+if [ -z "$LODEVR" ]; then
+       ts_log "Failed to create loop device"
+fi
+if test "$LODEV" = "$LODEVR" ; then
+       echo "equal" >>$TS_OUTPUT
+else
+       echo "different" >>$TS_OUTPUT
+       if test -n "$LODEVR" ; then
+               $TS_CMD_LOSETUP -d $LODEVR
+       fi
+fi
+$TS_CMD_LOSETUP -d $LODEV
+$TS_CMD_LOSETUP -d $LODEVR >/dev/null 2>&1
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "find-ok-no-sizelimit"
+LODEV=$( $TS_CMD_LOSETUP --find --show --offset=1MiB --sizelimit=1MiB $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find --show --offset=2MiB $BACKFILE )
+if [ -z "$LODEVR" ]; then
+       ts_log "Failed to create loop device"
+fi
+if test "$LODEV" = "$LODEVR" ; then
+       echo "equal" >>$TS_OUTPUT
+else
+       echo "different" >>$TS_OUTPUT
+       if test -n "$LODEVR" ; then
+               $TS_CMD_LOSETUP -d $LODEVR
+       fi
+fi
+$TS_CMD_LOSETUP -d $LODEV
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "plain-conflict"
+LODEV=$( $TS_CMD_LOSETUP --find --show $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find )
+$TS_CMD_LOSETUP $LODEVR $BACKFILE >/dev/null 2>&1
+ts_log $?
+$TS_CMD_LOSETUP -d $LODEV
+$TS_CMD_LOSETUP -d $LODEVR >/dev/null 2>&1
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_init_subtest "plain-readonly"
+LODEV=$( $TS_CMD_LOSETUP --find --show --read-only $BACKFILE )
+if [ -z "$LODEV" ]; then
+       ts_log "Failed to create loop device"
+fi
+LODEVR=$( $TS_CMD_LOSETUP --find )
+$TS_CMD_LOSETUP $LODEVR $BACKFILE >/dev/null 2>&1
+ts_log $?
+$TS_CMD_LOSETUP -d $LODEV
+$TS_CMD_LOSETUP -d $LODEVR >/dev/null 2>&1
+ts_log "Success"
+ts_finalize_subtest
+
+sleep 3
+
+ts_log "Success"
+ts_finalize