From 064b8c3842cf347cdf203f7b2d4f4b82f4eeaaa2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 16 May 2007 02:07:07 +0200 Subject: [PATCH] tests: code refactoring -- new ts_udev_loop_support function The patch moves generic and duplicated code to a new ts_udev_loop_support function. Signed-off-by: Karel Zak --- tests/functions.sh | 12 ++++++++++++ tests/ts-cramfs-mkfs | 10 +++------- tests/ts-mkswap-doit | 10 +++------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/functions.sh b/tests/functions.sh index 86abfb4e..6c0658b1 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -99,4 +99,16 @@ function ts_device_deinit { rm -f "$IMAGE" &> /dev/null fi } + +function ts_udev_loop_support { + ldd $TS_CMD_MOUNT | grep -q 'libvolume_id' 2>&1 >> $TS_OUTPUT + if [ "$?" == "0" ]; then + HAS_VOLUMEID="yes" + fi + if [ -n "$HAS_VOLUMEID" ] && [ ! -L "/dev/disk/by-label/$1" ]; then + return 1 + fi + return 0 +} + diff --git a/tests/ts-cramfs-mkfs b/tests/ts-cramfs-mkfs index c1f46f11..715f575c 100755 --- a/tests/ts-cramfs-mkfs +++ b/tests/ts-cramfs-mkfs @@ -36,11 +36,6 @@ IMAGE_RE=$( echo $IMAGE | sed 's:/:\\/:g' ) LABEL="testCramfs" MOUNTPOINT="$TS_OUTDIR/cramfs-mnt" -ldd $TS_CMD_MOUNT | grep -q 'libvolume_id' 2>&1 >> $TS_OUTPUT -if [ "$?" == "0" ]; then - HAS_VOLUMEID="yes" -fi - echo "create mountpoint dir" >> $TS_OUTPUT if [ ! -d "$MOUNTPOINT" ]; then mkdir -p $MOUNTPOINT @@ -85,8 +80,9 @@ if [ "$($TS_CMD_MOUNT --guess-fstype $DEVICE)" != "cramfs" ]; then ts_finalize fi -if [ -n "$HAS_VOLUMEID" ] && [ ! -L "/dev/disk/by-label/$LABEL" ]; then - $TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT +ts_udev_loop_support $LABEL +if [ "$?" != "0" ]; then + ts_device_deinit; ts_skip "udev ignores /dev/loop*" fi diff --git a/tests/ts-mkswap-doit b/tests/ts-mkswap-doit index cd567cf3..600acbac 100755 --- a/tests/ts-mkswap-doit +++ b/tests/ts-mkswap-doit @@ -32,11 +32,6 @@ touch $TS_OUTPUT LABEL="testSwap" -ldd $TS_CMD_SWAPON | grep -q 'libvolume_id' 2>&1 >> $TS_OUTPUT -if [ "$?" == "0" ]; then - HAS_VOLUMEID="yes" -fi - ts_device_init || ts_finalize $TS_CMD_MKSWAP -L $LABEL $DEVICE 2>&1 >> $TS_OUTPUT @@ -47,8 +42,9 @@ if [ "$($TS_CMD_MOUNT --guess-fstype $DEVICE)" != "swap" ]; then ts_finalize fi -if [ -n "$HAS_VOLUMEID" ] && [ ! -L "/dev/disk/by-label/$LABEL" ]; then - ts_device_deinit +ts_udev_loop_support $LABEL +if [ "$?" != "0" ]; then + ts_device_deinit; ts_skip "udev ignores /dev/loop*" fi -- 2.39.5