1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-10 17:57:54 +03:00

Substantial rework of the functional test support code. Some new features:

- somewhat neater, more consistent and more readable output
- possible to set any lvm.conf value: aux lvmconf "section/key = value"
- LVM_TEST_NODEBUG to suppress the (lengthy) "## DEBUG" output
- back-substitution on test output ($TESTDIR/$PREFIX -> @TESTDIR@/@PREFIX@)
- support code moved from test/ to test/lib/ --> less clutter
This commit is contained in:
Petr Rockai 2011-01-05 00:16:18 +00:00
parent 63bd9ec3ff
commit 1b7c4b9bce
78 changed files with 1194 additions and 537 deletions

View File

@ -34,94 +34,73 @@ RUN_BASE = $(shell echo $(RUN) | xargs -n 1 echo | sed -e s,^$(srcdir)/,,)
# Shell quote;
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
SUPPORT := $(srcdir)/test-utils.sh \
$(srcdir)/lvm-utils.sh
ifeq ("@UDEV_SYNC@", "yes")
dm_udev_synchronisation = 1
endif
all check: init.sh
all check: .tests-stamp
make -C api tests
@echo Testing with locking_type 1
VERBOSE=$(VERBOSE) ./bin/harness $(RUN_BASE)
VERBOSE=$(VERBOSE) ./lib/harness $(RUN_BASE)
@echo Testing with locking_type 3
VERBOSE=$(VERBOSE) LVM_TEST_LOCKING=3 ./bin/harness $(RUN_BASE)
VERBOSE=$(VERBOSE) LVM_TEST_LOCKING=3 ./lib/harness $(RUN_BASE)
check_cluster: init.sh
check_cluster: .tests-stamp
make -C api tests
@echo Testing with locking_type 3
VERBOSE=$(VERBOSE) LVM_TEST_LOCKING=3 ./bin/harness $(RUN_BASE)
VERBOSE=$(VERBOSE) LVM_TEST_LOCKING=3 ./lib/harness $(RUN_BASE)
check_local: init.sh
check_local: .tests-stamp
make -C api tests
@echo Testing with locking_type 1
VERBOSE=$(VERBOSE) LVM_TEST_LOCKING=1 ./bin/harness $(RUN_BASE)
VERBOSE=$(VERBOSE) LVM_TEST_LOCKING=1 ./lib/harness $(RUN_BASE)
bin/not: $(srcdir)/not.c .bin-dir-stamp
$(CC) -o bin/not $<
ln -sf not bin/should
lib/should: lib/not
ln -sf not lib/should
bin/harness: $(srcdir)/harness.c .bin-dir-stamp
$(CC) -o bin/harness $<
lib/%: $(srcdir)/lib/%.c .lib-dir-stamp
$(CC) -o $@ $<
bin/check: $(srcdir)/check.sh .bin-dir-stamp
cp $< bin/check
chmod +x bin/check
lib/%: $(srcdir)/lib/%.sh .lib-dir-stamp
cp $< $@
chmod +x $@
init.sh: $(srcdir)/Makefile.in .bin-dir-stamp bin/not bin/check bin/harness $(RUN) $(SUPPORT) $(UNIT)
rm -f $@-t $@
lib/paths: $(srcdir)/Makefile.in .lib-dir-stamp
rm -f $@-t
echo 'top_srcdir=$(top_srcdir)' >> $@-t
echo 'abs_top_builddir=$(abs_top_builddir)' >> $@-t
echo 'abs_top_srcdir=$(abs_top_builddir)' >> $@-t
echo 'PATH=$$abs_top_builddir/test/bin:$$PATH' >> $@-t
LDLPATH="\$$abs_top_builddir/libdm"; \
LDLPATH="$$LDLPATH:\$$abs_top_builddir/tools"; \
LDLPATH="$$LDLPATH:\$$abs_top_builddir/liblvm"; \
LDLPATH="$$LDLPATH:\$$abs_top_builddir/daemons/dmeventd"; \
LDLPATH="$$LDLPATH:\$$abs_top_builddir/daemons/dmeventd/plugins/lvm2"; \
LDLPATH="$$LDLPATH:\$$abs_top_builddir/daemons/dmeventd/plugins/mirror"; \
LDLPATH="$$LDLPATH:\$$abs_top_builddir/daemons/dmeventd/plugins/snapshot"; \
echo "export LD_LIBRARY_PATH=\"$$LDLPATH\"" >> $@-t
echo 'top_srcdir=$(top_srcdir)' >> $@-t
echo 'abs_srcdir=$(abs_srcdir)' >> $@-t
echo 'abs_builddir=$(abs_builddir)' >> $@-t
echo 'export PATH' >> $@-t
echo 'export DM_UDEV_SYNCHRONISATION=$(dm_udev_synchronisation)' >> $@-t
chmod a-w $@-t
mv $@-t $@
LIB = lib/not lib/should lib/harness \
lib/check lib/aux lib/test lib/utils lib/get lib/lvm-wrapper \
lib/paths
.tests-stamp: $(RUN) $(LIB)
@if test "$(srcdir)" != . ; then \
echo "Copying tests to builddir."; \
cp $(SUPPORT) .; \
for f in $(RUN); do cp $$f `echo $$f | sed -e s,^$(srcdir)/,,`; done; \
fi
touch .tests-stamp
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
.bin-dir-stamp: lvm-wrapper
rm -rf bin
mkdir bin
.lib-dir-stamp:
mkdir -p lib
for i in lvm $$(cat ../tools/.commands); do \
ln -s ../lvm-wrapper bin/$$i; \
ln -fs lvm-wrapper lib/$$i; \
done
ln -s "$(abs_top_builddir)/tools/dmsetup" bin/dmsetup
ln -s "$(abs_top_builddir)/daemons/clvmd/clvmd" bin/clvmd
ln -s "$(abs_top_builddir)/daemons/dmeventd/dmeventd" bin/dmeventd
ln -s "$(abs_top_builddir)/tools/dmsetup" lib/dmsetup
ln -s "$(abs_top_builddir)/daemons/clvmd/clvmd" lib/clvmd
ln -s "$(abs_top_builddir)/daemons/dmeventd/dmeventd" lib/dmeventd
touch $@
lvm-wrapper: Makefile
rm -f $@-t $@
echo '#!/bin/sh' > $@-t
echo 'cmd=$$(echo ./$$0|sed "s,.*/,,")' >> $@-t
echo 'test "$$cmd" = lvm &&' >> $@-t
echo 'exec "$(abs_top_builddir)/tools/lvm" "$$@"' >> $@-t
echo 'exec "$(abs_top_builddir)/tools/lvm" "$$cmd" "$$@"' >> $@-t
chmod a-w,a+x $@-t
mv $@-t $@
clean:
rm -rf init.sh lvm-wrapper bin .bin-dir-stamp
rm -rf bin .lib-dir-stamp .test-stamp
if test "$(srcdir)" != . ; then rm -f $(subst $(srcdir)/, ,$(RUN)) lvm2app.sh ; fi
distclean: clean

View File

@ -11,13 +11,14 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
aux prepare_devs 2
vgcreate -c n -s 4k $vg $devs
vgcreate -c n -s 4k $vg $(cat DEVICES)
lvcreate -n foo $vg -l 5
lvcreate -s -n snap $vg/foo -l 2 -c 4k
lvcreate -s -n snap2 $vg/foo -l 6 -c 4k
dd if=/dev/urandom of=$DM_DEV_DIR/$vg/snap2 count=1 bs=1024
lvcreate -m 1 -n mirr $vg -l 1 --mirrorlog core
lvs
apitest percent $vg
aux apitest percent $vg

View File

@ -12,7 +12,7 @@
# tests lvm2app library
#
. ./test-utils.sh
. lib/test
aux prepare_devs 2
pvcreate $dev1 $dev2
apitest vgtest $vg1 $dev1 $dev2
aux apitest vgtest $vg1 $dev1 $dev2

367
test/lib/aux.sh Normal file
View File

@ -0,0 +1,367 @@
# Copyright (C) 2011 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
. lib/utils
prepare_clvmd() {
if test -z "$LVM_TEST_LOCKING" || test "$LVM_TEST_LOCKING" -ne 3 ; then
return 0 # not needed
fi
if pgrep clvmd ; then
echo "Cannot use fake cluster locking with real clvmd ($(pgrep clvmd)) running."
touch SKIP_THIS_TEST
exit 1
fi
# skip if we don't have our own clvmd...
(which clvmd | grep $abs_builddir) || exit 200
# skip if we singlenode is not compiled in
(clvmd --help 2>&1 | grep "Available cluster managers" | grep singlenode) || exit 200
clvmd -Isinglenode -d 1 &
LOCAL_CLVMD="$!"
# check that it is really running now
sleep .1
ps $LOCAL_CLVMD || exit 200
}
prepare_dmeventd() {
if pgrep dmeventd ; then
echo "Cannot test dmeventd with real dmeventd ($(pgrep dmeventd)) running."
touch SKIP_THIS_TEST
exit 1
fi
# skip if we don't have our own dmeventd...
(which dmeventd | grep $abs_builddir) || exit 200
dmeventd -f &
echo "$!" > LOCAL_DMEVENTD
}
teardown_devs() {
test -n "$PREFIX" && {
rm -rf $TESTDIR/dev/$PREFIX*
init_udev_transaction
while dmsetup table | grep -q ^$PREFIX; do
for s in `dmsetup info -c -o name --noheading | grep ^$PREFIX`; do
umount -fl $DM_DEV_DIR/mapper/$s >& /dev/null || true
dmsetup remove $s >& /dev/null || true
done
done
finish_udev_transaction
}
# NOTE: SCSI_DEBUG_DEV test must come before the LOOP test because
# prepare_scsi_debug_dev() also sets LOOP to short-circuit prepare_loop()
if test -f SCSI_DEBUG_DEV; then
modprobe -r scsi_debug
else
test -f LOOP && losetup -d $(cat LOOP)
test -f LOOPFILE && rm -f $(cat LOOPFILE)
fi
rm -f DEVICES # devs is set in prepare_devs()
rm -f LOOP
}
teardown() {
echo -n "## teardown..."
test -n "$LOCAL_CLVMD" && {
kill "$LOCAL_CLVMD"
sleep .1
kill -9 "$LOCAL_CLVMD" || true
}
echo -n .
test -f LOCAL_DMEVENTD && kill -9 "$(cat LOCAL_DMEVENTD)"
echo -n .
teardown_devs
echo -n .
test -n "$TESTDIR" && {
cd $OLDPWD
rm -rf $TESTDIR || echo BLA
}
echo "ok"
}
make_ioerror() {
echo 0 10000000 error | dmsetup create ioerror
ln -s $DM_DEV_DIR/mapper/ioerror $DM_DEV_DIR/ioerror
}
prepare_loop() {
size=$1
test -n "$size" || size=32
echo -n "## preparing loop device..."
# skip if prepare_scsi_debug_dev() was used
if [ -f "SCSI_DEBUG_DEV" -a -f "LOOP" ]; then
echo "(skipped)"
return 0
fi
test ! -e LOOP
test -n "$DM_DEV_DIR"
for i in 0 1 2 3 4 5 6 7; do
test -e $DM_DEV_DIR/loop$i || mknod $DM_DEV_DIR/loop$i b 7 $i
done
echo -n .
LOOPFILE="$PWD/test.img"
dd if=/dev/zero of="$LOOPFILE" bs=$((1024*1024)) count=0 seek=$(($size-1)) 2> /dev/null
if LOOP=`losetup -s -f "$LOOPFILE" 2>/dev/null`; then
:
elif LOOP=`losetup -f` && losetup $LOOP "$LOOPFILE"; then
# no -s support
:
else
# no -f support
# Iterate through $DM_DEV_DIR/loop{,/}{0,1,2,3,4,5,6,7}
for slash in '' /; do
for i in 0 1 2 3 4 5 6 7; do
local dev=$DM_DEV_DIR/loop$slash$i
! losetup $dev >/dev/null 2>&1 || continue
# got a free
losetup "$dev" "$LOOPFILE"
LOOP=$dev
break
done
if [ -n "$LOOP" ]; then
break
fi
done
fi
test -n "$LOOP" # confirm or fail
echo "$LOOP" > LOOP
echo "ok ($LOOP)"
}
# A drop-in replacement for prepare_loop() that uses scsi_debug to create
# a ramdisk-based SCSI device upon which all LVM devices will be created
# - scripts must take care not to use a DEV_SIZE that will enduce OOM-killer
prepare_scsi_debug_dev()
{
local DEV_SIZE="$1"
shift
local SCSI_DEBUG_PARAMS="$@"
test -f "SCSI_DEBUG_DEV" && return 0
test -z "$LOOP"
test -n "$DM_DEV_DIR"
# Skip test if awk isn't available (required for get_sd_devs_)
which awk || exit 200
# Skip test if scsi_debug module is unavailable or is already in use
modprobe --dry-run scsi_debug || exit 200
lsmod | grep -q scsi_debug && exit 200
# Create the scsi_debug device and determine the new scsi device's name
# NOTE: it will _never_ make sense to pass num_tgts param;
# last param wins.. so num_tgts=1 is imposed
modprobe scsi_debug dev_size_mb=$DEV_SIZE $SCSI_DEBUG_PARAMS num_tgts=1 || exit 200
sleep 2 # allow for async Linux SCSI device registration
local DEBUG_DEV=/dev/$(grep -H scsi_debug /sys/block/*/device/model | cut -f4 -d /)
[ -b $DEBUG_DEV ] || exit 1 # should not happen
# Create symlink to scsi_debug device in $DM_DEV_DIR
SCSI_DEBUG_DEV="$DM_DEV_DIR/$(basename $DEBUG_DEV)"
echo "$SCSI_DEBUG_DEV" > SCSI_DEBUG_DEV
echo "$SCSI_DEBUG_DEV" > LOOP
# Setting $LOOP provides means for prepare_devs() override
ln -snf $DEBUG_DEV $SCSI_DEBUG_DEV
return 0
}
cleanup_scsi_debug_dev()
{
aux teardown_devs
rm -f SCSI_DEBUG_DEV
rm -f LOOP
}
prepare_devs() {
local n="$1"
test -z "$n" && n=3
local devsize="$2"
test -z "$devsize" && devsize=34
local pvname="$3"
test -z "$pvname" && pvname="pv"
prepare_loop $(($n*$devsize))
echo -n "## preparing $n devices..."
if ! loopsz=`blockdev --getsz $LOOP 2>/dev/null`; then
loopsz=`blockdev --getsize $LOOP 2>/dev/null`
fi
local size=$(($loopsz/$n))
init_udev_transaction
for i in `seq 1 $n`; do
local name="${PREFIX}$pvname$i"
local dev="$DM_DEV_DIR/mapper/$name"
devs="$devs $dev"
echo 0 $size linear $LOOP $((($i-1)*$size)) > $name.table
dmsetup create $name $name.table
done
finish_udev_transaction
#for i in `seq 1 $n`; do
# local name="${PREFIX}$pvname$i"
# dmsetup info -c $name
#done
#for i in `seq 1 $n`; do
# local name="${PREFIX}$pvname$i"
# dmsetup table $name
#done
echo $devs > DEVICES
echo "ok"
}
disable_dev() {
init_udev_transaction
for dev in "$@"; do
# first we make the device inaccessible
echo 0 10000000 error | dmsetup load $dev
dmsetup resume $dev
# now let's try to get rid of it if it's unused
#dmsetup remove $dev
done
finish_udev_transaction
}
enable_dev() {
init_udev_transaction
for dev in "$@"; do
local name=`echo "$dev" | sed -e 's,.*/,,'`
dmsetup create $name $name.table || dmsetup load $name $name.table
dmsetup resume $dev
done
finish_udev_transaction
}
backup_dev() {
for dev in "$@"; do
dd if=$dev of=$dev.backup bs=1024
done
}
restore_dev() {
for dev in "$@"; do
test -e $dev.backup || {
echo "Internal error: $dev not backed up, can't restore!"
exit 1
}
dd of=$dev if=$dev.backup bs=1024
done
}
prepare_pvs() {
prepare_devs "$@"
pvcreate -ff $devs
}
prepare_vg() {
vgremove -ff $vg >& /dev/null || true
teardown_devs
prepare_pvs "$@"
vgcreate -c n $vg $devs
#pvs -v
}
lvmconf() {
if test -z "$LVM_TEST_LOCKING"; then LVM_TEST_LOCKING=1; fi
test -f CONFIG_VALUES || {
cat > CONFIG_VALUES <<-EOF
devices/dir = "$DM_DEV_DIR"
devices/scan = "$DM_DEV_DIR"
devices/filter = [ "a/dev\/mirror/", "a/dev\/mapper\/.*pv[0-9_]*$/", "r/.*/" ]
devices/cache_dir = "$TESTDIR/etc"
devices/sysfs_scan = 0
devices/default_data_alignment = 1
log/syslog = 0
log/indent = 1
log/level = 9
log/file = "$TESTDIR/debug.log"
log/overwrite = 1
log/activation = 1
backup/backup = 0
backup/archive = 0
global/abort_on_internal_errors = 1
global/library_dir = "$TESTDIR/lib"
global/locking_dir = "$TESTDIR/var/lock/lvm"
global/locking_type=$LVM_TEST_LOCKING
global/si_unit_consistency = 1
global/fallback_to_local_locking = 0
activation/udev_sync = 1
activation/udev_rules = 1
activation/polling_interval = 0
activation/snapshot_autoextend_percent = 50
activation/snapshot_autoextend_threshold = 50
EOF
}
for v in "$@"; do
echo "$v" >> CONFIG_VALUES
done
rm -f CONFIG
for s in `cat CONFIG_VALUES | cut -f1 -d/ | sort | uniq`; do
echo "$s {" >> CONFIG
for k in `grep ^$s/ CONFIG_VALUES | cut -f1 -d= | sed -e 's, *$,,' | sort | uniq`; do
grep "^$k" CONFIG_VALUES | tail -n 1 | sed -e "s,^$s/, ," >> CONFIG
done
echo "}" >> CONFIG
echo >> CONFIG
done
mv -f CONFIG $TESTDIR/etc/lvm.conf
}
apitest() {
t=$1
shift
test -x $abs_top_builddir/test/api/$t.t || {
touch SKIP_THIS_TEST
exit 200
}
$abs_top_builddir/test/api/$t.t "$@"
}
api() {
test -x $abs_top_builddir/test/api/wrapper || exit 200
$abs_top_builddir/test/api/wrapper "$@"
}
test -f DEVICES && devs=$(cat DEVICES)
test -f LOOP && LOOP=$(cat LOOP)
"$@"

View File

@ -25,6 +25,14 @@
set -e -o pipefail
trim()
{
trimmed=${1%% }
trimmed=${trimmed## }
echo "$trimmed"
}
lvl() {
lvs -a --noheadings "$@"
}
@ -195,4 +203,79 @@ inactive() {
}
}
pv_field()
{
actual=$(trim $(pvs --noheadings $4 -o $2 $1))
test "$actual" = "$3" || {
echo "pv_field: PV=$1, field=$2, actual=$actual, expected=$3"
exit 1
}
}
vg_field()
{
actual=$(trim $(vgs --noheadings $4 -o $2 $1))
test "$actual" = "$3" || {
echo "vg_field: vg=$1, field=$2, actual=$actual, expected=$3"
exit 1
}
}
lv_field()
{
actual=$(trim $(lvs --noheadings $4 -o $2 $1))
test "$actual" = "$3" || {
echo "lv_field: lv=$1, field=$2, actual=$actual, expected=$3"
exit 1
}
}
compare_fields()
{
local cmd1=$1;
local obj1=$2;
local field1=$3;
local cmd2=$4;
local obj2=$5;
local field2=$6;
local val1;
local val2;
val1=$($cmd1 --noheadings -o $field1 $obj1)
val2=$($cmd2 --noheadings -o $field2 $obj2)
test "$val1" = "$val2" || {
echo "compare_fields $obj1($field1): $val1 $obj2($field2): $val2"
exit 1
}
}
compare_vg_field()
{
local vg1=$1;
local vg2=$2;
local field=$3;
val1=$(vgs --noheadings -o $field $vg1)
val2=$(vgs --noheadings -o $field $vg2)
test "$val1" = "$val2" || {
echo "compare_vg_field: $vg1: $val1, $vg2: $val2"
exit 1
}
}
pvlv_counts()
{
local local_vg=$1
local num_pvs=$2
local num_lvs=$3
local num_snaps=$4
lvs -a -o+devices $local_vg
vg_field $local_vg pv_count $num_pvs
vg_field $local_vg lv_count $num_lvs
vg_field $local_vg snap_count $num_snaps
}
"$@"

23
test/lib/get.sh Normal file
View File

@ -0,0 +1,23 @@
# Copyright (C) 2011 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
pv_field() {
pvs --noheading -o $2 $1 | sed 's/^ *//'
}
vg_field() {
vgs --noheading -o $2 $1 | sed 's/^ *//'
}
lv_field() {
lvs --noheading -o $2 $1 | sed 's/^ *//'
}
"$@"

View File

@ -40,6 +40,17 @@ int readbuf_sz = 0, readbuf_used = 0;
int die = 0;
int verbose = 0;
int verbose_off = 0;
struct subst {
char *key;
char *value;
};
struct subst subst[2];
char *TESTDIR = NULL;
char *PREFIX = NULL;
#define PASSED 0
#define SKIPPED 1
@ -52,8 +63,60 @@ void handler( int s ) {
die = s;
}
int outline(char *buf, int start, int force) {
char *from = buf + start;
char *next = strchr(buf + start, '\n');
if (!next && !force) /* not a complete line yet... */
return start;
if (!next)
next = from + strlen(from);
else
++next;
if (!strncmp(from, "@TESTDIR=", 9)) {
subst[0].key = "@TESTDIR@";
subst[0].value = strndup(from + 9, next - from - 9 - 1);
} else if (!strncmp(from, "@PREFIX=", 8)) {
subst[1].key = "@PREFIX@";
subst[1].value = strndup(from + 8, next - from - 8 - 1);
} else {
char *line = strndup(from, next - from);
char *a = line, *b;
do {
b = line + strlen(line);
int idx = -1;
int i;
for ( i = 0; i < 2; ++i ) {
if (subst[i].key) {
// printf("trying: %s -> %s\n", subst[i].value, subst[i].key);
char *stop = strstr(a, subst[i].value);
if (stop && stop < b) {
idx = i;
b = stop;
}
}
}
fwrite(a, 1, b - a, stdout);
a = b;
if ( idx >= 0 ) {
fprintf(stdout, "%s", subst[idx].key);
a += strlen(subst[idx].value);
}
} while (b < line + strlen(line));
free(line);
}
return next - buf + (force ? 0 : 1);
}
void dump() {
fwrite(readbuf, 1, readbuf_used, stdout);
int counter = 0;
while ( counter < readbuf_used )
counter = outline( readbuf, counter, 1 );
}
void clear() {
@ -63,8 +126,10 @@ void clear() {
void drain() {
int sz;
char buf[2048];
memset(buf, 0, 2048);
while (1) {
sz = read(fds[1], buf, 2048);
sz = read(fds[1], buf, 2047);
if (verbose)
write(1, buf, sz);
if (sz <= 0)
@ -121,6 +186,8 @@ void run(int i, char *f) {
close(0);
dup2(fds[0], 1);
dup2(fds[0], 2);
close(fds[0]);
close(fds[1]);
execlp("bash", "bash", f, NULL);
perror("execlp");
fflush(stderr);
@ -166,13 +233,9 @@ int main(int argc, char **argv) {
s.nwarned = s.nfailed = s.npassed = s.nskipped = 0;
char *config = getenv("LVM_TEST_CONFIG"),
*config_debug,
*be_verbose = getenv("VERBOSE");
char *be_verbose = getenv("VERBOSE");
if (be_verbose && atoi(be_verbose))
verbose = 1; // XXX
config = config ? config : "";
asprintf(&config_debug, "%s\n%s\n", config, "log { verbose=4 }");
if (socketpair(PF_UNIX, SOCK_STREAM, 0, fds)) {
perror("socketpair");

7
test/lib/lvm-wrapper.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
. lib/paths
cmd=$(echo ./$0|sed "s,.*/,,")
test "$cmd" = lvm && exec "$abs_top_builddir/tools/lvm" "$@"
exec "$abs_top_builddir/tools/lvm" "$cmd" "$@"

55
test/lib/test.sh Normal file
View File

@ -0,0 +1,55 @@
# Copyright (C) 2011 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
# sanitize the environment
LANG=C
LC_ALL=C
TZ=UTC
unset CDPATH
# grab some common utilities
. lib/utils
OLDPWD="`pwd`"
PREFIX="LVMTEST$$"
TESTDIR=$($abs_srcdir/mkdtemp ${LVM_TEST_DIR-$(pwd)} $PREFIX.XXXXXXXXXX) \
|| { echo "failed to create temporary directory in ${LVM_TEST_DIR-$(pwd)}"; exit 1; }
export PREFIX
export TESTDIR
trap 'set +vx; STACKTRACE; set -vx' ERR
trap 'aux teardown' EXIT # don't forget to clean up
export LVM_SYSTEM_DIR=$TESTDIR/etc
export DM_DEV_DIR=$TESTDIR/dev
mkdir $LVM_SYSTEM_DIR $DM_DEV_DIR $DM_DEV_DIR/mapper $TESTDIR/lib
cd $TESTDIR
for i in `find $abs_top_builddir/daemons/dmeventd/plugins/ -name \*.so`; do
#echo Setting up symlink from $i to $TESTDIR/lib
ln -s $i $TESTDIR/lib
done
ln -s $abs_top_builddir/test/lib/* $TESTDIR/lib
# re-do the utils now that we have TESTDIR/PREFIX/...
. lib/utils
set -eE -o pipefail
aux lvmconf
aux prepare_clvmd
echo "@TESTDIR=$TESTDIR"
echo "@PREFIX=$PREFIX"
set -vx

80
test/lib/utils.sh Normal file
View File

@ -0,0 +1,80 @@
# Copyright (C) 2011 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
set -e
STACKTRACE() {
trap - ERR;
i=0;
while FUNC=${FUNCNAME[$i]}; test "$FUNC" != "main"; do
echo "## $i ${FUNC}() called from ${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}"
i=$(($i + 1));
done
# Get backtraces from coredumps
if which gdb >& /dev/null; then
echo bt full > gdb_commands.txt
echo l >> gdb_commands.txt
echo quit >> gdb_commands.txt
for core in `ls core* 2>/dev/null`; do
bin=$(gdb -batch -c $core 2>&1 | grep "generated by" | \
sed -e "s,.*generated by \`\([^ ']*\).*,\1,")
gdb -batch -c $core -x gdb_commands.txt `which $bin`
done
fi
test -z "$LVM_TEST_NODEBUG" && test -f debug.log && {
sed -e "s,^,## DEBUG: ,;s,$top_srcdir/\?,," < debug.log
}
test -f SKIP_THIS_TEST && exit 200
}
init_udev_transaction() {
if test "$DM_UDEV_SYNCHRONISATION" = 1; then
COOKIE=$(dmsetup udevcreatecookie)
# Cookie is not generated if udev is not running!
if test -n "$COOKIE"; then
export DM_UDEV_COOKIE=$COOKIE
fi
fi
}
finish_udev_transaction() {
if test "$DM_UDEV_SYNCHRONISATION" = 1 -a -n "$DM_UDEV_COOKIE"; then
dmsetup udevreleasecookie
unset DM_UDEV_COOKIE
fi
}
. lib/paths || { echo >&2 you must run make first; exit 1; }
PATH=$abs_top_builddir/test/lib:$PATH
LIBDIRS="libdm tools liblvm daemons/dmeventd daemons/dmeventd/plugins/lvm2 \
daemons/dmeventd/plugins/mirror daemons/dmeventd/plugins/snapshot"
for d in $LIBDIRS; do
LD_LIBRARY_PATH=$abs_top_builddir/$d:$LD_LIBRARY_PATH
done
export LD_LIBRARY_PATH
if test -n "$PREFIX"; then
vg=${PREFIX}vg
lv=LV
for i in `seq 1 16`; do
name="${PREFIX}pv$i"
dev="$DM_DEV_DIR/mapper/$name"
eval "dev$i=$dev"
eval "lv$i=LV$i"
eval "vg$i=${PREFIX}vg$i"
done
fi

View File

@ -8,7 +8,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
lvm version

View File

@ -17,9 +17,9 @@
# instead lvconvert --repair them?)
# - linear LVs with bits missing are not activated
. ./test-utils.sh
. lib/test
prepare_vg 4
aux prepare_vg 4
lvcreate -l1 -n linear1 $vg $dev1
lvcreate -l1 -n linear2 $vg $dev2
@ -32,7 +32,7 @@ lvcreate -l1 -m1 -n mirror12 --mirrorlog core $vg $dev1 $dev2
lvcreate -l1 -m1 -n mirror123 $vg $dev1 $dev2 $dev3
vgchange -a n $vg
disable_dev $dev1
aux disable_dev $dev1
not vgchange -a y $vg
not vgck $vg
@ -45,8 +45,8 @@ check inactive $vg mirror12
check inactive $vg mirror123
vgchange -a n $vg
enable_dev $dev1
disable_dev $dev2
aux enable_dev $dev1
aux disable_dev $dev2
not vgchange -a y $vg
not vgck $vg
@ -59,8 +59,8 @@ check inactive $vg mirror12
check inactive $vg mirror123
vgchange -a n $vg
enable_dev $dev2
disable_dev $dev3
aux enable_dev $dev2
aux disable_dev $dev3
not vgchange -a y $vg
not vgck $vg
@ -73,8 +73,8 @@ check inactive $vg mirror123
check active $vg mirror12
vgchange -a n $vg
enable_dev $dev3
disable_dev $dev4
aux enable_dev $dev3
aux disable_dev $dev4
vgchange -a y $vg
not vgck $vg

View File

@ -8,13 +8,13 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
aux prepare_vg 3
lvcreate -m 1 -l 1 -n mirror $vg
lvchange -a n $vg/mirror
disable_dev $dev1
aux disable_dev $dev1
not vgreduce --removemissing $vg
not lvchange -v -a y $vg/mirror

View File

@ -12,7 +12,7 @@
# tests basic functionality of read-ahead and ra regressions
#
. ./test-utils.sh
. lib/test
TEST_UUID="aaaaaa-aaaa-aaaa-aaaa-aaaa-aaaa-aaaaaa"
@ -31,7 +31,7 @@ pvcreate --metadatacopies 0 $dev2
pvcreate --metadatacopies 0 $dev3
pvcreate $dev4
pvcreate --norestorefile -u $TEST_UUID --metadatacopies 0 $dev5
vgcreate -c n $vg $devs
vgcreate -c n $vg $(cat DEVICES)
lvcreate -n $lv -l 5 -i5 -I256 $vg
# test *scan and *display tools

View File

@ -9,10 +9,10 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
prepare_vg 5
prepare_dmeventd
aux prepare_vg 5
aux prepare_dmeventd
which mkfs.ext2 || exit 200
@ -22,7 +22,7 @@ lvcreate -m 2 --ig -L 1 -n 3way $vg
lvchange --monitor y $vg/3way
dmeventd -R -f &
LOCAL_DMEVENTD="$!"
echo "$!" > LOCAL_DMEVENTD
sleep 1 # wait a bit, so we talk to the new dmeventd later

View File

@ -12,7 +12,7 @@
test_description='Exercise fsadm filesystem resize'
exit 200
. ./test-utils.sh
. lib/test
aux prepare_vg 1 100

View File

@ -9,7 +9,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
aux prepare_vg 3
@ -17,14 +17,14 @@ lvcreate -m 1 -l 1 -n mirror $vg
lvcreate -l 1 -n resized $vg
lvchange -a n $vg/mirror
backup_dev $devs
aux backup_dev $(cat DEVICES)
init() {
restore_dev $devs
aux restore_dev $(cat DEVICES)
lvs -o lv_name,lv_size --units k $vg | tee lvs.out
grep resized lvs.out | not grep 8192
lvresize -L 8192K $vg/resized
restore_dev $dev1
aux restore_dev $dev1
}
check() {
@ -66,10 +66,10 @@ check
echo Check auto-repair of failed vgextend - metadata written to original pv but not new pv
vgremove -f $vg
pvremove -ff $devs
pvcreate $devs
backup_dev $dev2
pvremove -ff $(cat DEVICES)
pvcreate $(cat DEVICES)
aux backup_dev $dev2
vgcreate $vg $dev1
vgextend $vg $dev2
restore_dev $dev2
should compare_two_fields_ vgs $vg vg_mda_count pvs $dev2 vg_mda_count
aux restore_dev $dev2
should check compare_fields vgs $vg vg_mda_count pvs $dev2 vg_mda_count

View File

@ -12,7 +12,7 @@
# tests functionality of lvs, pvs, vgs, *display tools
#
. ./test-utils.sh
. lib/test
get_lvs_()
{
@ -38,16 +38,16 @@ test $(wc -l <out) -eq 5
pvs --noheadings -o seg_all,pv_all,lv_all,vg_all | tee out
test $(wc -l <out) -eq 5
vgcreate -c n $vg $devs
vgcreate -c n $vg $(cat DEVICES)
#COMM pvs and vgs report mda_count, mda_free (bz202886, bz247444)
pvs -o +pv_mda_count,pv_mda_free $devs
pvs -o +pv_mda_count,pv_mda_free $(cat DEVICES)
for I in $dev2 $dev3 $dev5; do
aux check_pv_field_ $I pv_mda_count 0
aux check_pv_field_ $I pv_mda_free 0
check pv_field $I pv_mda_count 0
check pv_field $I pv_mda_free 0
done
vgs -o +vg_mda_count,vg_mda_free $vg
aux check_vg_field_ $vg vg_mda_count 2
check vg_field $vg vg_mda_count 2
#COMM pvs doesn't display --metadatacopies 0 PVs as orphans (bz409061)
pvdisplay $dev2|grep "VG Name.*$vg"
@ -77,7 +77,7 @@ vgs -o pv_name,vg_name $vg
# would complain if not
#COMM pvdisplay --maps feature (bz149814)
pvdisplay $devs >out
pvdisplay --maps $devs >out2
pvdisplay $(cat DEVICES) >out
pvdisplay --maps $(cat DEVICES) >out2
not diff out out2

View File

@ -11,7 +11,7 @@
test_description='test some blocking / non-blocking multi-vg operations'
. ./test-utils.sh
. lib/test
aux prepare_devs 3
test -n "$LOCAL_CLVMD" && exit 200

View File

@ -9,7 +9,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
aux prepare_vg 3
# force resync 2-way active mirror

View File

@ -8,7 +8,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
log_name_to_count()
{
@ -83,7 +83,7 @@ test_lvconvert()
max_log_count=$start_log_count
fi
prepare_vg 5
aux prepare_vg 5
if [ $start_count -gt 0 ]; then
# Are there extra devices for the log or do we overlap

View File

@ -9,7 +9,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
# convert from linear to 2-way mirror
aux prepare_vg 5

View File

@ -9,18 +9,18 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
prepare_vg 5
prepare_dmeventd
aux prepare_vg 5
aux prepare_dmeventd
which mkfs.ext2 || exit 200
lvcreate -m 3 --ig -L 1 -n 4way $vg
lvchange --monitor y $vg/4way
disable_dev $dev2 $dev4
aux disable_dev $dev2 $dev4
mkfs.ext2 $DM_DEV_DIR/$vg/4way
sleep 10 # FIXME: need a "poll" utility, akin to "check"
enable_dev $dev2 $dev4
aux enable_dev $dev2 $dev4
check mirror $vg 4way
check mirror_legs $vg 4way 2

View File

@ -9,16 +9,16 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
prepare_vg 4
aux prepare_vg 4
# Clean-up and create a 2-way mirror, where the the
# leg devices are always on $dev[12] and the log
# is always on $dev3. ($dev4 behaves as a spare)
cleanup() {
vgreduce --removemissing $vg
for d in "$@"; do enable_dev $d; done
for d in "$@"; do aux enable_dev $d; done
for d in "$@"; do vgextend $vg $d; done
lvremove -ff $vg/mirror
lvcreate -m 1 --ig -l 2 -n mirror $vg $dev1 $dev2 $dev3:0
@ -36,7 +36,7 @@ aux disable_dev $dev1
lvchange --partial -a y $vg/mirror
repair 'activation { mirror_image_fault_policy = "remove" }'
check linear $vg mirror
aux cleanup $dev1
cleanup $dev1
# Fail a leg of a mirror.
# Expected result: Mirror (leg replaced)
@ -44,7 +44,7 @@ aux disable_dev $dev1
repair 'activation { mirror_image_fault_policy = "replace" }'
check mirror $vg mirror
lvs | grep mirror_mlog
aux cleanup $dev1
cleanup $dev1
# Fail a leg of a mirror (use old name for policy specification)
# Expected result: Mirror (leg replaced)
@ -52,7 +52,7 @@ aux disable_dev $dev1
repair 'activation { mirror_device_fault_policy = "replace" }'
check mirror $vg mirror
lvs | grep mirror_mlog
aux cleanup $dev1
cleanup $dev1
# Fail a leg of a mirror w/ no available spare
# Expected result: 2-way with corelog
@ -60,7 +60,7 @@ aux disable_dev $dev2 $dev4
repair 'activation { mirror_image_fault_policy = "replace" }'
check mirror $vg mirror
lvs | not grep mirror_mlog
aux cleanup $dev2 $dev4
cleanup $dev2 $dev4
# Fail the log device of a mirror w/ no available spare
# Expected result: mirror w/ corelog
@ -68,7 +68,7 @@ aux disable_dev $dev3 $dev4
repair 'activation { mirror_image_fault_policy = "replace" }' $vg/mirror
check mirror $vg mirror
lvs | not grep mirror_mlog
aux cleanup $dev3 $dev4
cleanup $dev3 $dev4
# Fail the log device with a remove policy
# Expected result: mirror w/ corelog

View File

@ -9,43 +9,43 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
prepare_vg 6
aux prepare_vg 6
# multiple failures, full replace
lvcreate --mirrorlog disk -m 2 --ig -L 1 -n 3way $vg $dev1 $dev2 $dev3 $dev4:0-1
disable_dev $dev1 $dev2
aux disable_dev $dev1 $dev2
echo y | lvconvert --repair $vg/3way 2>&1 | tee 3way.out
lvs -a -o +devices | not grep unknown
not grep "WARNING: Failed" 3way.out
vgreduce --removemissing $vg
check mirror $vg 3way
enable_dev $dev1 $dev2
aux enable_dev $dev1 $dev2
vgremove -ff $vg; vgcreate -c n $vg $dev1 $dev2 $dev3 $dev4 $dev5
# multiple failures, partial replace
lvcreate --mirrorlog disk -m 2 --ig -L 1 -n 3way $vg $dev1 $dev2 $dev3 $dev4
disable_dev $dev1 $dev2
aux disable_dev $dev1 $dev2
echo y | lvconvert --repair $vg/3way 2>&1 | tee 3way.out
grep "WARNING: Failed" 3way.out
lvs -a -o +devices | not grep unknown
vgreduce --removemissing $vg
check mirror $vg 3way
enable_dev $dev1 $dev2
aux enable_dev $dev1 $dev2
lvchange -a n $vg/3way
vgremove -ff $vg; vgcreate -c n $vg $dev1 $dev2 $dev3
lvcreate --mirrorlog disk -m 1 --ig -L 1 -n 2way $vg $dev1 $dev2 $dev3
disable_dev $dev1
aux disable_dev $dev1
echo y | lvconvert --repair $vg/2way 2>&1 | tee 2way.out
grep "WARNING: Failed" 2way.out
lvs -a -o +devices | not grep unknown
vgreduce --removemissing $vg
check mirror $vg 2way
enable_dev $dev1 $dev2
aux enable_dev $dev1 $dev2
lvchange -a n $vg/2way
vgremove -ff $vg; vgcreate -c n $vg $dev1 $dev2 $dev3 $dev4

View File

@ -9,18 +9,18 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
prepare_vg 5
. lib/test
exit 200 # this breaks upstream .33 and RHEL6 kernel :(
aux prepare_vg 5
# fail multiple devices
lvcreate -m 3 --ig -L 1 -n 4way $vg
disable_dev $dev2 $dev4
aux disable_dev $dev2 $dev4
mkfs.ext3 $DM_DEV_DIR/$vg/4way
enable_dev $dev2 $dev4
aux enable_dev $dev2 $dev4
echo n | lvconvert --repair $vg/4way 2>&1 | tee 4way.out
lvs -a -o +devices | not grep unknown
vgreduce --removemissing $vg

View File

</
@ -9,54 +9,54 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
. lib/test
# fail multiple devices
aux prepare_vg 5
lvcreate -m 3 --ig -L 1 -n 4way $vg $dev1 $dev2 $dev3 $dev4 $dev5:0
disable_dev $dev2 $dev4
aux disable_dev $dev2 $dev4
echo n | lvconvert --repair $vg/4way 2>&1 | tee 4way.out
lvs -a -o +devices | not grep unknown
vgreduce --removemissing $vg
enable_dev $dev2 $dev4
aux enable_dev $dev2 $dev4
check mirror $vg 4way $dev5
aux prepare_vg 5
lvcreate -m 2 --ig -L 1 -n 3way $vg
disable_dev $dev1 $dev2
aux disable_dev $dev1 $dev2
echo n | lvconvert --repair $vg/3way
check linear $vg 3way
lvs -a -o +devices | not grep unknown
lvs -a -o +devices | not grep mlog
dmsetup ls | grep $PREFIX | not grep mlog
vgreduce --removemissing $vg
enable_dev $dev1 $dev2
aux enable_dev $dev1 $dev2
check linear $vg 3way
# fail just log and get it removed
aux prepare_vg 5
lvcreate -m 2 --ig -L 1 -n 3way $vg $dev1 $dev2 $dev3 $dev4:0
disable_dev $dev4
aux disable_dev $dev4
echo n | lvconvert --repair $vg/3way
check mirror $vg 3way core
lvs -a -o +devices | not grep unknown
lvs -a -o +devices | not grep mlog
dmsetup ls | grep $PREFIX | not grep mlog
vgreduce --removemissing $vg