[parted-devel] [PATCH 3/3] tests: add test for partitionable loop devices

Petr Uzel petr.uzel at suse.cz
Thu Sep 29 13:14:24 UTC 2011


* tests/t8001-loop-blkpg.sh: New file.
* tests/Makefile.am: Add test.
---
 tests/Makefile.am         |    1 +
 tests/t8001-loop-blkpg.sh |   65 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100755 tests/t8001-loop-blkpg.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index e721f88..903ca64 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,6 +43,7 @@ TESTS = \
   t6000-dm.sh \
   t7000-scripting.sh \
   t8000-loop.sh \
+  t8001-loop-blkpg.sh \
   t9010-big-sector.sh \
   t9020-alignment.sh \
   t9021-maxima.sh \
diff --git a/tests/t8001-loop-blkpg.sh b/tests/t8001-loop-blkpg.sh
new file mode 100755
index 0000000..4373d7c
--- /dev/null
+++ b/tests/t8001-loop-blkpg.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+# Test support for partitions on loop devices
+
+# Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+# 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/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+require_root_
+
+cleanup_fn_()
+{
+  test -n "$loopdev" && losetup -d "$loopdev"
+  rm -f backing_file
+}
+
+# If the loop module is loaded, unload it first
+if lsmod | grep '^loop[[:space:]]' >/dev/null 2>&1; then
+        rmmod loop || fail=1
+fi
+
+# Insert loop module with max_part > 1
+modprobe loop max_part=7 || fail=1
+
+# Create backing file
+dd if=/dev/zero of=backing_file bs=1M count=4 >/dev/null 2>&1 || fail=1
+
+# Set up loop device on top of backing file
+loopdev=`losetup -f --show backing_file`
+test -z "$loopdev" && fail=1
+
+# Expect this to succeed
+parted -s "$loopdev" mklabel msdos > err 2>&1 || fail=1
+compare err /dev/null || fail=1     # expect no output
+
+# Create a partition
+parted -s "$loopdev" mkpart primary 1M 2M > err 2>&1 || fail=1
+compare err /dev/null || fail=1     # expect no output
+udevadm settle --timeout=5 || fail=1
+
+# Verify that the partition appeared in /proc/partitions
+entry=`basename "$loopdev"p1`
+grep "$entry" /proc/partitions >/dev/null 2>&1 || fail=1
+
+# Remove the partition
+parted -s "$loopdev" rm 1 > err 2>&1 || fail=1
+compare err /dev/null || fail=1     # expect no output
+udevadm settle --timeout=5 || fail=1
+
+# Verify that the partition got removed from /proc/partitions
+grep "$entry" /proc/partitions >/dev/null 2>&1 && fail=1
+
+Exit $fail
-- 
1.7.3.4




More information about the parted-devel mailing list