[PATCH] add basic device mapper tests

=3D?utf-8?q?Guido=3D20G=3DC3=3DBCnther?=3D agx at sigxcpu.org
Thu Jun 5 07:55:53 UTC 2008


* tests/dm-utils.sh: New file.  Copied from lvm's tests/lvm-utils.sh.
* tests/t6000-dm.sh: New file.
* tests/test-lib.sh: FIXME
* tests/Makefile.am: FIXME
---
 tests/Makefile.am |    3 +-
 tests/dm-utils.sh |   94 ++++++++++++++++++++++++++++++++++++++++
 tests/t6000-dm.sh |  122 +++++++++++++++++++++++++++++++++++++++++++++++++=
++++
 tests/test-lib.sh |    4 ++
 4 files changed, 222 insertions(+), 1 deletions(-)
 create mode 100644 tests/dm-utils.sh
 create mode 100755 tests/t6000-dm.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index d6b2731..2e72bbd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,7 +11,8 @@ TESTS =3D \
   t3100-resize-ext2-partion.sh \
   t4100-msdos-partition-limits.sh \
   t4100-dvh-partition-limits.sh \
-  t5000-tags.sh
+  t5000-tags.sh \
+  t6000-dm.sh

 EXTRA_DIST =3D \
   $(TESTS) test-lib.sh
diff --git a/tests/dm-utils.sh b/tests/dm-utils.sh
new file mode 100644
index 0000000..e91b8e0
--- /dev/null
+++ b/tests/dm-utils.sh
@@ -0,0 +1,94 @@
+# Put lvm-related utilities here.
+# This file is sourced from test-lib.sh.
+
+# Copyright (C) 2007, 2008 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+export LVM_SUPPRESS_FD_WARNINGS=3D1
+
+ME=3D$(basename "$0")
+warn() { echo >&2 "$ME: $@"; }
+
+unsafe_losetup_()
+{
+  f=3D$1
+
+  test -n "$G_dev_" \
+    || error "Internal error: unsafe_losetup_ called before init_root_dir_"
+
+  # Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7,8,9}
+  for slash in '' /; do
+    for i in 0 1 2 3 4 5 6 7 8 9; do
+      dev=3D$G_dev_/loop$slash$i
+      losetup $dev > /dev/null 2>&1 && continue;
+      losetup "$dev" "$f" > /dev/null && { echo "$dev"; return 0; }
+      break
+    done
+  done
+
+  return 1
+}
+
+loop_setup_()
+{
+  file=3D$1
+  dd if=3D/dev/zero of=3D"$file" bs=3D1M count=3D1 seek=3D1000 > /dev/null=
 2>&1 \
+    || { warn "loop_setup_ failed: Unable to create tmp file $file"; retur=
n 1; }
+
+  # NOTE: this requires a new enough version of losetup
+  dev=3D$(unsafe_losetup_ "$file" 2>/dev/null) \
+    || { warn "loop_setup_ failed: Unable to create loopback device"; retu=
rn 1; }
+
+  echo "$dev"
+  return 0;
+}
+
+dmsetup_has_dm_devdir_support_()
+{
+  # Detect support for the envvar.  If it's supported, the
+  # following command will fail with the expected diagnostic.
+  out=3D$(DM_DEV_DIR=3Dj dmsetup version 2>&1)
+  test "$?:$out" =3D "1:Invalid DM_DEV_DIR envvar value." -o \
+       "$?:$out" =3D "1:Invalid DM_DEV_DIR environment variable value."
+}
+
+# set up private /dev and /etc
+init_root_dir_()
+{
+  test -n "$test_dir_" \
+    || error "Internal error: called init_root_dir_ before" \
+      " defining $test_dir_"
+
+  # Define these two globals.
+  G_root_=3D$test_dir_/root
+  G_dev_=3D$G_root_/dev
+
+  export LVM_SYSTEM_DIR=3D$G_root_/etc
+  export DM_DEV_DIR=3D$G_dev_
+
+  # Only the first caller does anything.
+  mkdir -p $G_root_/etc $G_dev_ $G_dev_/mapper
+  for i in 0 1 2 3 4 5 6 7; do
+    mknod $G_root_/dev/loop$i b 7 $i
+  done
+  cat > $G_root_/etc/lvm.conf <<-EOF
+  devices {
+    dir =3D "$G_dev_"
+    scan =3D "$G_dev_"
+    filter =3D [ "a/loop/", "a/mirror/", "a/mapper/", "r/.*/" ]
+    cache_dir =3D "$G_root_/etc"
+    sysfs_scan =3D 0
+  }
+EOF
+}
+
+if test $(this_test_) =3D t6000; then
+  init_root_dir_
+fi
diff --git a/tests/t6000-dm.sh b/tests/t6000-dm.sh
new file mode 100755
index 0000000..bf7df6d
--- /dev/null
+++ b/tests/t6000-dm.sh
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+# Copyright (C) 2008 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/>.
+
+test_description=3D'determine type of devicemaps.'
+
+privileges_required_=3D1
+device_mapper_required_=3D1
+
+. ./init.sh
+
+# Device maps names - should be random to not conflict with existing ones =
on
+# the system
+linear_=3Dplinear
+mpath_=3Dmpath
+
+cleanup_() {
+    dmsetup remove $linear_
+    dmsetup remove $mpath_
+    test -n "$d1" && losetup -d "$d1"
+    test -n "$d2" && losetup -d "$d2"
+    test -n "$d3" && losetup -d "$d3"
+    rm -f "$f1" "$f2" "$f3";
+}
+
+test_expect_success \
+    "setup: create loop devices" \
+    'f1=3D$(pwd)/1 && d1=3D$(loop_setup_ "$f1") && \
+     f2=3D$(pwd)/2 && d2=3D$(loop_setup_ "$f2") && \
+     f3=3D$(pwd)/3 && d3=3D$(loop_setup_ "$f3")'
+
+#
+# Linear Map
+#
+
+test_expect_success \
+    "setup: create a linear mapping" \
+    'echo 0 1024 linear "$d1" 0 | dmsetup create "$linear_" &&
+     dev=3D"$DM_DEV_DIR"/mapper/"$linear_"'
+
+test_expect_success \
+    'run parted -s "$dev" mklabel msdos' \
+    'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    "determine the map type" \
+    'parted -s "$dev" print > out 2>&1'
+
+# Create expected output file.
+fail=3D0
+{ emit_superuser_warning > exp; } || fail=3D1
+cat <<EOF >> exp || fail=3D1
+Model: Linux device-mapper (linear) (dm)
+Disk $dev: 524kB
+Sector size (logical/physical): 512B/512B
+Partition Table: msdos
+
+Number  Start  End  Size  Type  File system  Flags
+
+EOF
+test_expect_success \
+    'create expected output file' \
+    'test $fail =3D 0'
+
+test_expect_success \
+    'check its output' \
+    '$compare out exp'
+
+#
+# Multipath Map
+#
+
+test_expect_success \
+    "setup: create a multipath mapping" \
+    'echo 0 1024 multipath 0 0 1 1 round-robin 0 2 0 "$d2" "$d3" \
+            | dmsetup create "$mpath_" &&
+     dev=3D"$DM_DEV_DIR"/mapper/"$mpath_"'
+
+test_expect_success \
+    'run parted -s "$dev" mklabel msdos' \
+    'parted -s $dev mklabel msdos > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    "determine the map type" \
+    'parted -s "$dev" print > out 2>&1'
+
+# Create expected output file.
+fail=3D0
+{ emit_superuser_warning > exp; } || fail=3D1
+cat <<EOF >> exp || fail=3D1
+Model: Linux device-mapper (multipath) (dm)
+Disk $dev: 524kB
+Sector size (logical/physical): 512B/512B
+Partition Table: msdos
+
+Number  Start  End  Size  Type  File system  Flags
+
+EOF
+test_expect_success \
+    'create expected output file' \
+    'test $fail =3D 0'
+
+test_expect_success \
+    'check its output' \
+    '$compare out exp'
+
+test_done
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 77a9ab9..21d3e51 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -258,6 +258,10 @@ if test $skip_ =3D 0 && test "$erasable_device_require=
d_" !=3D ''; then
   fi
 fi

+if test $skip_ =3D 0 && test "$device_mapper_required_" !=3D ''; then
+  . $abs_top_srcdir/tests/dm-utils.sh || exit 1
+fi
+
 # This is a stub function that is run upon trap (upon regular exit and
 # interrupt).  Override it with a per-test function, e.g., to unmount
 # a partition, or to undo any other global state changes.
--=20
1.5.6.rc0.30.g7c3f3




More information about the parted-devel mailing list