[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] small cleanup to tests



I've added a VERBOSE option for show/hide the test instead of editing
the file every time to change it. defaulted to show. and cleaned up
indentation on the last commit i saw to test.

Note i have not tested the changes but breakage should be minimal; if at
all.

Regards,
Danny Rawlins
diff -pruN LVM2.orig/test/harness.sh LVM2/test/harness.sh
--- LVM2.orig/test/harness.sh	2008-10-09 21:24:11.000000000 +1100
+++ LVM2/test/harness.sh	2008-10-09 22:24:52.000000000 +1100
@@ -1,4 +1,6 @@
-#!/bin/sh
+#!/bin/bash
+
+[ -z "${VERBOSE}" ] && VERBOSE='yes' # change to no to be quiet by default
 
 tests="$@"
 test -z "$tests" && tests=`echo t-*.sh`
diff -pruN LVM2.orig/test/test-utils.sh LVM2/test/test-utils.sh
--- LVM2.orig/test/test-utils.sh	2008-10-09 21:24:11.000000000 +1100
+++ LVM2/test/test-utils.sh	2008-10-09 22:12:07.000000000 +1100
@@ -12,75 +12,77 @@ test_description="foo" # silence test-li
 . ./test-lib.sh
 
 aux() {
-    # use just "$@" for verbose operation
-    "$@" > /dev/null 2> /dev/null
-	#"$@"
+	if [ "$VERBOSE" = 'yes' ]; then
+		"$@"
+	else
+		"$@" > /dev/null 2>&1
+	fi
 }
 
-not () { "$@" && exit 1 || return 0; }
+not() { "$@" && exit 1 || return 0; }
 
 STACKTRACE() {
 	trap - ERR;
-	i=0;
-	while FUNC=${FUNCNAME[$i]}; test "$FUNC" != "main"; do 
+	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
 }	
 
 teardown() {
-    echo $LOOP
-    echo $PREFIX
+	echo $LOOP
+	echo $PREFIX
 
-    test -n "$PREFIX" && {
-	rm -rf /dev/$PREFIX*
-	while dmsetup table | grep -q ^$PREFIX; do
-            for s in `dmsetup table | grep ^$PREFIX| cut -f1 -d:`; do
-		dmsetup resume $s 2>/dev/null > /dev/null || true
-		dmsetup remove $s 2>/dev/null > /dev/null || true
-            done
-	done
-    }
+	test -n "$PREFIX" && {
+		rm -rf /dev/$PREFIX*
+		while dmsetup table | grep -q ^$PREFIX; do
+			for s in $(dmsetup table | grep ^$PREFIX | cut -f1 -d:); do
+				dmsetup resume $s > /dev/null 2>&1 || true
+				dmsetup remove $s > /dev/null 2>&1 || true
+			done
+		done
+	}
 
-    test -n "$LOOP" && losetup -d $LOOP
-    test -n "$LOOPFILE" && rm -f $LOOPFILE
+	test -n "$LOOP" && losetup -d $LOOP
+	test -n "$LOOPFILE" && rm -f $LOOPFILE
 
-    cleanup_ # user-overridable cleanup
-    testlib_cleanup_ # call test-lib cleanup routine, too
+	cleanup_ # user-overridable cleanup
+	testlib_cleanup_ # call test-lib cleanup routine, too
 }
 
 make_ioerror() {
-    echo 0 10000000 error | dmsetup create ioerror
-    dmsetup resume ioerror
-    ln -s /dev/mapper/ioerror /dev/ioerror
+	echo '0 10000000 error' | dmsetup create ioerror
+	dmsetup resume ioerror
+	ln -s /dev/mapper/ioerror /dev/ioerror
 }
 
 prepare_loop() {
-    size=$1
-    test -n "$size" || size=32
+	size="$1"
+	test -n "$size" || size=32
 
-    test -n "$LOOP" && return 0
+	test -n "$LOOP" && return 0
 	trap 'aux teardown' EXIT # don't forget to clean up
 	trap 'set +vex; STACKTRACE; set -vex' ERR
 	#trap - ERR
 
 	LOOPFILE="$PWD/test.img"
 	dd if=/dev/zero of="$LOOPFILE" bs=$((1024*1024)) count=1 seek=$(($size-1))
-	if LOOP=`losetup -s -f "$LOOPFILE" 2>/dev/null`; then
+	if LOOP=$(losetup -s -f "$LOOPFILE" 2> /dev/null); then
 		return 0
-	elif LOOP=`losetup -f` && losetup $LOOP "$LOOPFILE"; then
+	elif LOOP="$(losetup -f)" && losetup $LOOP "$LOOPFILE"; then
 		# no -s support
 		return 0
 	else
 		# no -f support 
 		# 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
+			for i in {0..9}; do
 				local dev=$G_dev_/loop$slash$i
 				! losetup $dev >/dev/null 2>&1 || continue
 				# got a free
 				losetup "$dev" "$LOOPFILE"
-				LOOP=$dev
+				LOOP="$dev"
 			done
 		done
 		test -n "LOOP" # confirm or fail
@@ -89,87 +91,87 @@ prepare_loop() {
 }
 
 prepare_devs() {
-    local n="$1"
-    test -z "$n" && n=3
-    local devsize="$2"
-    test -z "$devsize" && devsize=33
-
-    prepare_loop $(($n*$devsize))
-
-    PREFIX="LVMTEST$$"
-
-    local loopsz=`blockdev --getsz $LOOP`
-    local size=$(($loopsz/$n))
-
-    for i in `seq 1 $n`; do
-	local name="${PREFIX}pv$i"
-	local dev="$G_dev_/mapper/$name"
-	eval "dev$i=$dev"
-	devs="$devs $dev"
-	echo 0 $size linear $LOOP $((($i-1)*$size)) > $name.table
-	dmsetup create $name $name.table
-	dmsetup resume $name
-    done
-
-    # set up some default names
-    vg=${PREFIX}vg
-    vg1=${PREFIX}vg1
-    vg2=${PREFIX}vg2
-    lv=LV
-    lv1=LV1
-    lv2=LV2
-    lv3=LV3
+	local n="$1"
+	test -z "$n" && n=3
+	local devsize="$2"
+	test -z "$devsize" && devsize=33
+
+	prepare_loop $(($n*$devsize))
+
+	PREFIX="LVMTEST$$"
+
+	local loopsz=`blockdev --getsz $LOOP`
+	local size=$(($loopsz/$n))
+
+	for i in $(seq 1 $n); do
+		local name="${PREFIX}pv$i"
+		local dev="$G_dev_/mapper/$name"
+		eval "dev$i=$dev"
+		devs="$devs $dev"
+		echo 0 $size linear $LOOP $((($i-1)*$size)) > $name.table
+		dmsetup create $name $name.table
+		dmsetup resume $name
+	done
+
+	# set up some default names
+	vg=${PREFIX}vg
+	vg1=${PREFIX}vg1
+	vg2=${PREFIX}vg2
+	lv=LV
+	lv1=LV1
+	lv2=LV2
+	lv3=LV3
 }
 
 disable_dev() {
-    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
+	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
 }
 
 enable_dev() {
-    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
+	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
 }
 
 prepare_pvs() {
-    prepare_devs "$@"
-    pvcreate $devs
+	prepare_devs "$@"
+	pvcreate $devs
 }
 
 prepare_vg() {
-    prepare_pvs "$@"
-    vgcreate $vg $devs
+	prepare_pvs "$@"
+	vgcreate $vg $devs
 }
 
 prepare_lvmconf() {
-  cat > $G_root_/etc/lvm.conf <<-EOF
-  devices {
-    dir = "$G_dev_"
-    scan = "$G_dev_"
-    filter = [ "a/dev\/mirror/", "a/dev\/mapper/", "r/.*/" ]
-    cache_dir = "$G_root_/etc"
-    sysfs_scan = 0
-  }
-  log {
-    verbose = $verboselevel
-    syslog = 0
-    indent = 1
-  }
-  backup {
-    backup = 0
-    archive = 0
-  }
-  global {
-    library_dir = "$G_root_/lib"
-  }
+	cat > $G_root_/etc/lvm.conf <<-EOF
+devices {
+  dir = "$G_dev_"
+  scan = "$G_dev_"
+  filter = [ "a/dev\/mirror/", "a/dev\/mapper/", "r/.*/" ]
+  cache_dir = "$G_root_/etc"
+  sysfs_scan = 0
+}
+log {
+  verbose = $verboselevel
+  syslog = 0
+  indent = 1
+}
+backup {
+  backup = 0
+  archive = 0
+}
+global {
+  library_dir = "$G_root_/lib"
+}
 EOF
 }
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]