From: Petr Uzel Date: Thu, 29 Sep 2011 13:14:24 +0000 (+0200) Subject: tests: add test for partitionable loop devices X-Git-Tag: android-x86-4.4-r1~128 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e0f8a78dd709dff5b4c4ec48593f1432a131987e;p=android-x86%2Fexternal-parted.git tests: add test for partitionable loop devices * tests/t8001-loop-blkpg.sh: New file. * tests/Makefile.am: Add test. --- 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..f6e37ce --- /dev/null +++ b/tests/t8001-loop-blkpg.sh @@ -0,0 +1,64 @@ +#!/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 . + +. "${srcdir=.}/init.sh"; path_prepend_ ../parted + +require_root_ + +cleanup_fn_() +{ + test -n "$loopdev" && losetup -d "$loopdev" +} + +# If the loop module is loaded, unload it first +if lsmod | grep '^loop[[:space:]]'; 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 /dev/null err || 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 || { cat /proc/partitions; fail=1; } + +# Remove the partition +parted -s "$loopdev" rm 1 > err 2>&1 || fail=1 +compare /dev/null err || fail=1 # expect no output +udevadm settle --timeout=5 || fail=1 + +# Verify that the partition got removed from /proc/partitions +grep "$entry" /proc/partitions && fail=1 + +Exit $fail