[parted-devel] [PATCH 8/9] tests: Add a test for device-mapper partition sizes

Brian C. Lane bcl at redhat.com
Fri Feb 6 01:30:47 UTC 2015


device-mapper uses 512b sector units, not device specific sector sizes.
This test ensures that the correct partition size is created, no matter
what the device's sector size is.
---
 tests/Makefile.am              |  1 +
 tests/t6006-dm-512b-sectors.sh | 68 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 tests/t6006-dm-512b-sectors.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index b726366..ce8391d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -69,6 +69,7 @@ TESTS = \
   t6003-dm-hide.sh \
   t6004-dm-many-partitions.sh \
   t6005-dm-uuid.sh \
+  t6006-dm-512b-sectors.sh \
   t6100-mdraid-partitions.sh \
   t7000-scripting.sh \
   t8000-loop.sh \
diff --git a/tests/t6006-dm-512b-sectors.sh b/tests/t6006-dm-512b-sectors.sh
new file mode 100644
index 0000000..31abba9
--- /dev/null
+++ b/tests/t6006-dm-512b-sectors.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+# device-mapper sector sizes are 512b, make sure partitions are the correct
+# size when using larger sector sizes and a linear dm table.
+
+# Copyright (C) 2015 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_
+require_scsi_debug_module_
+
+grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
+  skip_ 'this system lacks a new-enough libblkid'
+
+(dmsetup --help) > /dev/null 2>&1 || skip_test_ "No dmsetup installed"
+
+# Device maps names - should be random to not conflict with existing ones on
+# the system
+linear_=plinear-$$test
+
+cleanup_fn_() {
+    i=0
+    udevadm settle
+    while [ $i -lt 10 ] ; do
+      [ -e "/dev/mapper/${linear_}1" ] && dmsetup remove ${linear_}1
+      sleep .2
+      [ -e "/dev/mapper/$linear_" ] && dmsetup remove $linear_
+      sleep .2
+      [ -e "/dev/mapper/${linear_}1" -o -e "/dev/mapper/$linear_" ] || i=10
+      i=$((i + 1))
+    done
+    udevadm settle
+}
+
+# Create a 500M device
+ss=$sector_size_
+scsi_debug_setup_ sector_size=$ss dev_size_mb=500 > dev-name ||
+  skip_ 'failed to create scsi_debug device'
+scsi_dev=$(cat dev-name)
+
+# Size of device, in 512b units
+scsi_dev_size=$(blockdev --getsz $scsi_dev) || framework_failure
+
+dmsetup create $linear_ --table "0 $scsi_dev_size linear $scsi_dev 0" || framework_failure
+dev="/dev/mapper/$linear_"
+
+# Create msdos partition table with a partition from 1MiB to 100MiB
+parted -s $dev mklabel msdos mkpart primary ext2 1MiB 101MiB > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+# The size of the partition should be 100MiB, or 204800 512b sectors
+p1_size=$(blockdev --getsz ${dev}1) || framework_failure
+[ $p1_size == 204800 ] || fail=1
+
+Exit $fail
-- 
2.1.0




More information about the parted-devel mailing list