1 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
3 # This copyrighted material is made available to anyone wishing to use,
4 # modify, copy, or redistribute it subject to the terms and conditions
5 # of the GNU General Public License v.2.
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software Foundation,
9 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12 # use just "$@" for verbose operation
13 "$@" > /dev/null 2> /dev/null
21 while FUNC=${FUNCNAME[$i]}; test "$FUNC" != "main"; do
22 echo "$i ${FUNC}() called from ${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}"
26 # Get backtraces from coredumps
27 if which gdb >& /dev/null; then
28 echo bt full > gdb_commands.txt
29 echo l >> gdb_commands.txt
30 echo quit >> gdb_commands.txt
31 for core in `ls core* 2>/dev/null`; do
32 bin=$(gdb -batch -c $core 2>&1 | grep "generated by" | \
33 sed -e "s,.*generated by \`\([^ ']*\).*,\1,")
34 gdb -batch -c $core -x gdb_commands.txt `which $bin`
38 test -f debug.log && {
39 sed -e "s,^,## DEBUG: ,;s,$top_srcdir/\?,," < debug.log
43 init_udev_transaction() {
44 if test "$DM_UDEV_SYNCHRONISATION" = 1; then
45 COOKIE=$(dmsetup udevcreatecookie)
46 # Cookie is not generated if udev is not running!
47 if test -n "$COOKIE"; then
48 export DM_UDEV_COOKIE=$COOKIE
53 finish_udev_transaction() {
54 if test "$DM_UDEV_SYNCHRONISATION" = 1 -a -n "$DM_UDEV_COOKIE"; then
55 dmsetup udevreleasecookie
61 if test -z "$LVM_TEST_LOCKING" || test "$LVM_TEST_LOCKING" -ne 3 ; then
66 echo "Cannot use fake cluster locking with real clvmd ($(pgrep clvmd)) running."
70 # skip if we don't have our own clvmd...
71 (which clvmd | grep $abs_builddir) || exit 200
73 # skip if we singlenode is not compiled in
74 (clvmd --help 2>&1 | grep "Available cluster managers" | grep singlenode) || exit 200
78 clvmd -Isinglenode -d 1 &
81 # check that it is really running now
83 ps $LOCAL_CLVMD || exit 200
87 if pgrep dmeventd ; then
88 echo "Cannot test dmeventd with real dmeventd ($(pgrep dmeventd)) running."
92 # skip if we don't have our own dmeventd...
93 (which dmeventd | grep $abs_builddir) || exit 200
106 TESTDIR=$($abs_srcdir/mkdtemp ${LVM_TEST_DIR-$(pwd)} $PREFIX.XXXXXXXXXX) \
107 || { echo "failed to create temporary directory in ${LVM_TEST_DIR-$(pwd)}"; exit 1; }
109 export LVM_SYSTEM_DIR=$TESTDIR/etc
110 export DM_DEV_DIR=$TESTDIR/dev
111 mkdir $LVM_SYSTEM_DIR $DM_DEV_DIR $DM_DEV_DIR/mapper $TESTDIR/lib
115 for i in `find $abs_top_builddir/daemons/dmeventd/plugins/ -name \*.so`; do
116 echo Setting up symlink from $i to $TESTDIR/lib
117 ln -s $i $TESTDIR/lib
122 test -n "$PREFIX" && {
123 rm -rf $TESTDIR/dev/$PREFIX*
125 init_udev_transaction
126 while dmsetup table | grep -q ^$PREFIX; do
127 for s in `dmsetup info -c -o name --noheading | grep ^$PREFIX`; do
128 umount -fl $DM_DEV_DIR/mapper/$s || true
129 dmsetup remove $s >& /dev/null || true
132 finish_udev_transaction
136 # NOTE: SCSI_DEBUG_DEV test must come before the LOOP test because
137 # prepare_scsi_debug_dev() also sets LOOP to short-circuit prepare_loop()
138 if [ -n "$SCSI_DEBUG_DEV" ] ; then
139 modprobe -r scsi_debug
141 test -n "$LOOP" && losetup -d $LOOP
142 test -n "$LOOPFILE" && rm -f $LOOPFILE
144 unset devs # devs is set in prepare_devs()
152 test -n "$LOCAL_CLVMD" && {
155 kill -9 "$LOCAL_CLVMD" || true
158 test -n "$LOCAL_DMEVENTD" && kill -9 "$LOCAL_DMEVENTD"
162 test -n "$TESTDIR" && {
164 rm -rf $TESTDIR || echo BLA
169 trap 'set +vx; STACKTRACE; set -vx' ERR
170 trap 'aux teardown' EXIT # don't forget to clean up
174 echo 0 10000000 error | dmsetup create ioerror
175 ln -s $DM_DEV_DIR/mapper/ioerror $DM_DEV_DIR/ioerror
180 test -n "$size" || size=32
182 # skip if prepare_scsi_debug_dev() was used
183 if [ -n "$SCSI_DEBUG_DEV" -a -n "$LOOP" ]; then
188 test -n "$DM_DEV_DIR"
192 for i in 0 1 2 3 4 5 6 7; do
193 test -e $DM_DEV_DIR/loop$i || mknod $DM_DEV_DIR/loop$i b 7 $i
196 LOOPFILE="$PWD/test.img"
197 dd if=/dev/zero of="$LOOPFILE" bs=$((1024*1024)) count=0 seek=$(($size-1))
198 if LOOP=`losetup -s -f "$LOOPFILE" 2>/dev/null`; then
200 elif LOOP=`losetup -f` && losetup $LOOP "$LOOPFILE"; then
205 # Iterate through $DM_DEV_DIR/loop{,/}{0,1,2,3,4,5,6,7}
206 for slash in '' /; do
207 for i in 0 1 2 3 4 5 6 7; do
208 local dev=$DM_DEV_DIR/loop$slash$i
209 ! losetup $dev >/dev/null 2>&1 || continue
211 losetup "$dev" "$LOOPFILE"
215 if [ -n "$LOOP" ]; then
219 test -n "$LOOP" # confirm or fail
222 exit 1 # should not happen
225 # A drop-in replacement for prepare_loop() that uses scsi_debug to create
226 # a ramdisk-based SCSI device upon which all LVM devices will be created
227 # - scripts must take care not to use a DEV_SIZE that will enduce OOM-killer
228 prepare_scsi_debug_dev()
232 local SCSI_DEBUG_PARAMS="$@"
234 test -n "$SCSI_DEBUG_DEV" && return 0
236 test -n "$DM_DEV_DIR"
240 # Skip test if awk isn't available (required for get_sd_devs_)
241 which awk || exit 200
243 # Skip test if scsi_debug module is unavailable or is already in use
244 modprobe --dry-run scsi_debug || exit 200
245 lsmod | grep -q scsi_debug && exit 200
247 # Create the scsi_debug device and determine the new scsi device's name
248 # NOTE: it will _never_ make sense to pass num_tgts param;
249 # last param wins.. so num_tgts=1 is imposed
250 modprobe scsi_debug dev_size_mb=$DEV_SIZE $SCSI_DEBUG_PARAMS num_tgts=1 || exit 200
251 sleep 2 # allow for async Linux SCSI device registration
253 local DEBUG_DEV=/dev/$(grep -H scsi_debug /sys/block/*/device/model | cut -f4 -d /)
254 [ -b $DEBUG_DEV ] || exit 1 # should not happen
256 # Create symlink to scsi_debug device in $DM_DEV_DIR
257 SCSI_DEBUG_DEV=$DM_DEV_DIR/$(basename $DEBUG_DEV)
258 # Setting $LOOP provides means for prepare_devs() override
260 ln -snf $DEBUG_DEV $SCSI_DEBUG_DEV
264 cleanup_scsi_debug_dev()
275 test -z "$devsize" && devsize=34
277 test -z "$pvname" && pvname="pv"
279 prepare_loop $(($n*$devsize))
281 if ! loopsz=`blockdev --getsz $LOOP 2>/dev/null`; then
282 loopsz=`blockdev --getsize $LOOP 2>/dev/null`
285 local size=$(($loopsz/$n))
287 init_udev_transaction
288 for i in `seq 1 $n`; do
289 local name="${PREFIX}$pvname$i"
290 local dev="$DM_DEV_DIR/mapper/$name"
293 echo 0 $size linear $LOOP $((($i-1)*$size)) > $name.table
294 dmsetup create $name $name.table
296 finish_udev_transaction
298 for i in `seq 1 $n`; do
299 local name="${PREFIX}$pvname$i"
300 dmsetup info -c $name
302 for i in `seq 1 $n`; do
303 local name="${PREFIX}$pvname$i"
310 init_udev_transaction
312 # first we make the device inaccessible
313 echo 0 10000000 error | dmsetup load $dev
315 # now let's try to get rid of it if it's unused
318 finish_udev_transaction
324 init_udev_transaction
326 local name=`echo "$dev" | sed -e 's,.*/,,'`
327 dmsetup create $name $name.table || dmsetup load $name $name.table
330 finish_udev_transaction
335 dd if=$dev of=$dev.backup bs=1024
341 test -e $dev.backup || {
342 echo "Internal error: $dev not backed up, can't restore!"
345 dd of=$dev if=$dev.backup bs=1024
355 vgremove -ff $vg || true
359 vgcreate -c n $vg $devs
365 test -z "$filter" && \
366 filter='[ "a/dev\/mirror/", "a/dev\/mapper\/.*pv[0-9_]*$/", "r/.*/" ]'
368 if test -z "$LVM_TEST_CONFIG_SNAPSHOT_AUTOEXTEND"; then
369 LVM_TEST_CONFIG_SNAPSHOT_AUTOEXTEND="
370 snapshot_autoextend_percent = 50
371 snapshot_autoextend_threshold = 50"
373 if test -n "$LVM_TEST_LOCKING"; then locktype="locking_type = $LVM_TEST_LOCKING"; fi
374 cat > $TESTDIR/etc/lvm.conf.new <<-EOF
380 cache_dir = "$TESTDIR/etc"
382 default_data_alignment = 1
383 $LVM_TEST_CONFIG_DEVICES
389 file = "$TESTDIR/debug.log"
398 abort_on_internal_errors = 1
399 library_dir = "$TESTDIR/lib"
400 locking_dir = "$TESTDIR/var/lock/lvm"
402 si_unit_consistency = 1
403 fallback_to_local_locking = 0
409 $LVM_TEST_CONFIG_SNAPSHOT_AUTOEXTEND
412 # FIXME remove this workaround after mmap & truncating file problems solved
413 mv -f $TESTDIR/etc/lvm.conf.new $TESTDIR/etc/lvm.conf
414 cat $TESTDIR/etc/lvm.conf
419 # FIXME any way to set this just for our children?
420 # echo 1 > /proc/sys/kernel/core_uses_pid
425 # set up some default names
439 test -x $abs_top_builddir/test/api/$t.t || exit 200
440 $abs_top_builddir/test/api/$t.t "$@"
444 test -x $abs_top_builddir/test/api/wrapper || exit 200
445 $abs_top_builddir/test/api/wrapper "$@"
453 . ./init.sh || { echo >&2 you must run make first; exit 1; }
456 set -vexE -o pipefail