diff options
author | Guido Günther <agx@sigxcpu.org> | 2008-06-05 09:55:53 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-06-06 09:24:53 +0200 |
commit | 0e7e76c9ffcfd53633bed26c2f033830220af709 (patch) | |
tree | bb9a0c9a13f45848314f26939c21cf79ebed8edb /tests | |
parent | 119c5ac6bc4529bd94cc3284b419c4bacd6afd15 (diff) | |
download | parted-0e7e76c9ffcfd53633bed26c2f033830220af709.tar.gz |
add basic device mapper tests
* 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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/dm-utils.sh | 94 | ||||
-rwxr-xr-x | tests/t6000-dm.sh | 122 | ||||
-rw-r--r-- | tests/test-lib.sh | 4 |
4 files changed, 222 insertions, 1 deletions
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 = \ 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 = \ $(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=1 + +ME=$(basename "$0") +warn() { echo >&2 "$ME: $@"; } + +unsafe_losetup_() +{ + f=$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=$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=$1 + dd if=/dev/zero of="$file" bs=1M count=1 seek=1000 > /dev/null 2>&1 \ + || { warn "loop_setup_ failed: Unable to create tmp file $file"; return 1; } + + # NOTE: this requires a new enough version of losetup + dev=$(unsafe_losetup_ "$file" 2>/dev/null) \ + || { warn "loop_setup_ failed: Unable to create loopback device"; return 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=$(DM_DEV_DIR=j dmsetup version 2>&1) + test "$?:$out" = "1:Invalid DM_DEV_DIR envvar value." -o \ + "$?:$out" = "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_=$test_dir_/root + G_dev_=$G_root_/dev + + export LVM_SYSTEM_DIR=$G_root_/etc + export DM_DEV_DIR=$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 = "$G_dev_" + scan = "$G_dev_" + filter = [ "a/loop/", "a/mirror/", "a/mapper/", "r/.*/" ] + cache_dir = "$G_root_/etc" + sysfs_scan = 0 + } +EOF +} + +if test $(this_test_) = 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='determine type of devicemaps.' + +privileges_required_=1 +device_mapper_required_=1 + +. ./init.sh + +# Device maps names - should be random to not conflict with existing ones on +# the system +linear_=plinear +mpath_=mpath + +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=$(pwd)/1 && d1=$(loop_setup_ "$f1") && \ + f2=$(pwd)/2 && d2=$(loop_setup_ "$f2") && \ + f3=$(pwd)/3 && d3=$(loop_setup_ "$f3")' + +# +# Linear Map +# + +test_expect_success \ + "setup: create a linear mapping" \ + 'echo 0 1024 linear "$d1" 0 | dmsetup create "$linear_" && + dev="$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=0 +{ emit_superuser_warning > exp; } || fail=1 +cat <<EOF >> exp || fail=1 +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 = 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="$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=0 +{ emit_superuser_warning > exp; } || fail=1 +cat <<EOF >> exp || fail=1 +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 = 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_ = 0 && test "$erasable_device_required_" != ''; then fi fi +if test $skip_ = 0 && test "$device_mapper_required_" != ''; 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. |