summaryrefslogtreecommitdiffstats
path: root/tests/ts/losetup
diff options
context:
space:
mode:
authorStanislav Brabec2016-08-02 20:00:46 +0200
committerKarel Zak2016-08-17 13:02:35 +0200
commit912d50b3bec755d8b4f08aec69d255dbb5fe5e31 (patch)
treee507a646b21a50332b40e9195ed8f79f88da6e29 /tests/ts/losetup
parentlosetup: Prevent AUTOCLEAR detach race (diff)
downloadkernel-qcow2-util-linux-912d50b3bec755d8b4f08aec69d255dbb5fe5e31.tar.gz
kernel-qcow2-util-linux-912d50b3bec755d8b4f08aec69d255dbb5fe5e31.tar.xz
kernel-qcow2-util-linux-912d50b3bec755d8b4f08aec69d255dbb5fe5e31.zip
tests: Add losetup-loop test suite
Add losetup loop test suite that tests proper behavior of conflicting and re-used loop devices. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Diffstat (limited to 'tests/ts/losetup')
-rwxr-xr-xtests/ts/losetup/losetup-loop228
1 files changed, 228 insertions, 0 deletions
diff --git a/tests/ts/losetup/losetup-loop b/tests/ts/losetup/losetup-loop
new file mode 100755
index 000000000..45403cbd6
--- /dev/null
+++ b/tests/ts/losetup/losetup-loop
@@ -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