From: Ruediger Meier Date: Fri, 9 Mar 2018 17:27:44 +0000 (+0100) Subject: tests: fix grep expressions for devices X-Git-Tag: v2.32~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec182d8b9da7596809aab9aab4fc931e9ccb7494;p=thirdparty%2Futil-linux.git tests: fix grep expressions for devices ts_is_mounted "/dev/loop1" returned true if /dev/loop17 was mounted. A very annoying source of sporadic failures since many years. This issue became more visible since running the checks in parallel, which increases the probability to get bigger loop device numbers. Signed-off-by: Ruediger Meier --- diff --git a/tests/functions.sh b/tests/functions.sh index fc8f86377d..66eaa9d6ef 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -618,10 +618,10 @@ function ts_mount { function ts_is_mounted { local DEV=$(ts_canonicalize "$1") - grep -q $DEV /proc/mounts && return 0 + grep -q "\(^\| \)$DEV " /proc/mounts && return 0 if [ "${DEV#/dev/loop/}" != "$DEV" ]; then - grep -q "/dev/loop${DEV#/dev/loop/}" /proc/mounts && return 0 + grep -q "^/dev/loop${DEV#/dev/loop/} " /proc/mounts && return 0 fi return 1 } diff --git a/tests/ts/libmount/context b/tests/ts/libmount/context index 5a4f36afa4..3750c701fb 100755 --- a/tests/ts/libmount/context +++ b/tests/ts/libmount/context @@ -53,7 +53,7 @@ DEVICE="${TS_DEVICE}1" udevadm settle -grep -q $DEVNAME /proc/partitions +grep -q " $DEVNAME\$" /proc/partitions if [ $? -ne 0 ]; then ts_skip "no partition!" fi diff --git a/tests/ts/libmount/context-py b/tests/ts/libmount/context-py index b4e22b4000..dfc8faaeec 100755 --- a/tests/ts/libmount/context-py +++ b/tests/ts/libmount/context-py @@ -58,7 +58,7 @@ DEVICE="${TS_DEVICE}1" udevadm settle -grep -q $DEVNAME /proc/partitions +grep -q " $DEVNAME\$" /proc/partitions if [ $? -ne 0 ]; then ts_skip "no partition!" fi @@ -77,7 +77,7 @@ function is_mounted { ts_is_mounted "$1" return $? fi - grep -q "$1" $LIBMOUNT_MTAB && return 0 + grep -q "\(^\| \)$1 " $LIBMOUNT_MTAB && return 0 return 1 } diff --git a/tests/ts/libmount/context-utab b/tests/ts/libmount/context-utab index 24d528d872..a63ba57d61 100755 --- a/tests/ts/libmount/context-utab +++ b/tests/ts/libmount/context-utab @@ -44,7 +44,7 @@ DEVICE="${TS_DEVICE}1" udevadm settle -grep -q $DEVNAME /proc/partitions +grep -q " $DEVNAME\$" /proc/partitions if [ $? -ne 0 ]; then ts_skip "no partition!" fi @@ -67,14 +67,14 @@ udevadm settle ts_init_subtest "mount-by-devname" mkdir -p $MOUNTPOINT &> /dev/null ts_run $TESTPROG --mount $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/mounts || \ +ts_is_mounted "$DEVICE" || \ echo "(by device) cannot find $DEVICE in /proc/mounts" >> $TS_OUTPUT 2>&1 ts_finalize_subtest ts_init_subtest "umount-by-devname" ts_run $TESTPROG --umount $DEVICE >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/mounts && +ts_is_mounted "$DEVICE" && echo "umount (device) failed: found $DEVICE in /proc/mounts" >> $TS_OUTPUT 2>&1 ts_finalize_subtest @@ -82,14 +82,14 @@ ts_finalize_subtest ts_init_subtest "mount-uhelper" mkdir -p $MOUNTPOINT &> /dev/null ts_run $TESTPROG --mount -o uhelper=foo,rw LABEL="$LABEL" $MOUNTPOINT >> $TS_OUTPUT 2>&1 -grep -q $DEVICE $LIBMOUNT_UTAB || \ +grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" || \ echo "(by label) cannot find $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest ts_init_subtest "umount" ts_run $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1 -grep -q $DEVICE $LIBMOUNT_UTAB && \ +grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" && \ echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest @@ -109,7 +109,7 @@ if type "mkfs.btrfs" &>/dev/null && mkfs.btrfs --version &>/dev/null; then ts_init_subtest "mount-uhelper-subvol" mkdir -p $MOUNTPOINT &> /dev/null ts_run $TESTPROG --mount -o uhelper=foo,rw,subvol=sub $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1 - grep -q $DEVICE $LIBMOUNT_UTAB || \ + grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" || \ echo "cannot find $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest @@ -123,7 +123,7 @@ if type "mkfs.btrfs" &>/dev/null && mkfs.btrfs --version &>/dev/null; then ts_init_subtest "umount-subvol" ts_run $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1 - grep -q $DEVICE $LIBMOUNT_UTAB && \ + grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" && \ echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest fi diff --git a/tests/ts/libmount/context-utab-py b/tests/ts/libmount/context-utab-py index 94c957d915..89fc0c1573 100755 --- a/tests/ts/libmount/context-utab-py +++ b/tests/ts/libmount/context-utab-py @@ -45,7 +45,7 @@ DEVICE="${TS_DEVICE}1" udevadm settle -grep -q $DEVNAME /proc/partitions +grep -q " $DEVNAME\$" /proc/partitions if [ $? -ne 0 ]; then ts_skip "no partition!" fi @@ -68,14 +68,14 @@ udevadm settle ts_init_subtest "mount-by-devname" mkdir -p $MOUNTPOINT &> /dev/null $PYTHON $TESTPROG --mount $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/mounts || \ +ts_is_mounted "$DEVICE" || \ echo "(by device) cannot find $DEVICE in /proc/mounts" >> $TS_OUTPUT 2>&1 ts_finalize_subtest ts_init_subtest "umount-by-devname" $PYTHON $TESTPROG --umount $DEVICE >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/mounts && +ts_is_mounted "$DEVICE" && echo "umount (device) failed: found $DEVICE in /proc/mounts" >> $TS_OUTPUT 2>&1 ts_finalize_subtest @@ -83,14 +83,14 @@ ts_finalize_subtest ts_init_subtest "mount-uhelper" mkdir -p $MOUNTPOINT &> /dev/null $PYTHON $TESTPROG --mount -o uhelper=foo,rw LABEL="$LABEL" $MOUNTPOINT >> $TS_OUTPUT 2>&1 -grep -q $DEVICE $LIBMOUNT_UTAB || \ +grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" || \ echo "(by label) cannot find $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest ts_init_subtest "umount" $PYTHON $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1 -grep -q $DEVICE $LIBMOUNT_UTAB && \ +grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" && \ echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest @@ -110,7 +110,7 @@ if type "mkfs.btrfs" &>/dev/null && mkfs.btrfs --version &>/dev/null; then ts_init_subtest "mount-uhelper-subvol" mkdir -p $MOUNTPOINT &> /dev/null $PYTHON $TESTPROG --mount -o uhelper=foo,rw,subvol=sub $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1 - grep -q $DEVICE $LIBMOUNT_UTAB || \ + grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" || \ echo "cannot find $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1 ts_finalize_subtest diff --git a/tests/ts/losetup/losetup-loop b/tests/ts/losetup/losetup-loop index 6d1ef21bc3..037e5c7c6d 100755 --- a/tests/ts/losetup/losetup-loop +++ b/tests/ts/losetup/losetup-loop @@ -47,7 +47,7 @@ $TS_CMD_LOSETUP -d "$LODEV" LODEV=$( $TS_CMD_LOSETUP --find --nooverlap --show $BACKFILE ) udevadm settle dd if=/dev/zero of="$LODEV" count=1 bs=1 >/dev/null 2>&1 -$TS_CMD_LOSETUP --list | grep -q "$LODEV" +$TS_CMD_LOSETUP --list | grep -q "$LODEV\b" ts_log $? udevadm settle $TS_CMD_LOSETUP -d "$LODEV" >/dev/null 2>&1 diff --git a/tests/ts/mount/devname b/tests/ts/mount/devname index 65a1ba2176..4db878bb6d 100755 --- a/tests/ts/mount/devname +++ b/tests/ts/mount/devname @@ -48,12 +48,12 @@ $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1 ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts" -grep -q $DEVICE $MTAB_FILE || +grep -q "\(^\| \)$DEVICE " $MTAB_FILE || echo "mount failed: cannot find $DEVICE in $MTAB_FILE" >> $TS_OUTPUT 2>&1 $TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" -grep -q $DEVICE $MTAB_FILE && +grep -q "\(^\| \)$DEVICE " $MTAB_FILE && echo "umount failed: found $DEVICE in $MTAB_FILE" >> $TS_OUTPUT 2>&1 ts_log "Success" diff --git a/tests/ts/swapon/devname b/tests/ts/swapon/devname index de9a5f20c6..7469dcb180 100755 --- a/tests/ts/swapon/devname +++ b/tests/ts/swapon/devname @@ -38,7 +38,7 @@ ts_device_has "TYPE" "swap" $DEVICE || ts_die "Cannot find swap on $DEVICE" $TS_CMD_SWAPON $DEVICE >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" +grep -q "^$DEVICE\b" /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $TS_CMD_SWAPOFF $DEVICE diff --git a/tests/ts/swapon/fixpgsz b/tests/ts/swapon/fixpgsz index 01b2e9afff..4479cd8f9a 100755 --- a/tests/ts/swapon/fixpgsz +++ b/tests/ts/swapon/fixpgsz @@ -40,7 +40,7 @@ ts_device_has "TYPE" "swap" $DEVICE || ts_die "Cannot find swap on $DEVICE" # $TS_CMD_SWAPON --fixpgsz $DEVICE &> /dev/null -grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" +grep -q "^$DEVICE\b" /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $TS_CMD_SWAPOFF $DEVICE diff --git a/tests/ts/swapon/fixsig b/tests/ts/swapon/fixsig index 3f9e3ff840..c3104a23e0 100755 --- a/tests/ts/swapon/fixsig +++ b/tests/ts/swapon/fixsig @@ -41,7 +41,7 @@ ts_device_has "TYPE" "swsuspend" $DEVICE || ts_die "Cannot find swsuspend on $DE # $TS_CMD_SWAPON $DEVICE &> /dev/null -grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" +grep -q "^$DEVICE\b" /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $TS_CMD_SWAPOFF $DEVICE diff --git a/tests/ts/swapon/label b/tests/ts/swapon/label index 056953a290..210a12c972 100755 --- a/tests/ts/swapon/label +++ b/tests/ts/swapon/label @@ -42,7 +42,7 @@ ts_device_has "LABEL" $LABEL $DEVICE \ $TS_CMD_SWAPON -L $LABEL >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" +grep -q "^$DEVICE\b" /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $TS_CMD_SWAPOFF $DEVICE diff --git a/tests/ts/swapon/uuid b/tests/ts/swapon/uuid index 9f244f39a4..65af6cb6de 100755 --- a/tests/ts/swapon/uuid +++ b/tests/ts/swapon/uuid @@ -40,7 +40,7 @@ UUID=$(ts_uuid_by_devname $DEVICE) $TS_CMD_SWAPON -U $UUID >> $TS_OUTPUT 2>&1 -grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" +grep -q "^$DEVICE\b" /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $TS_CMD_SWAPOFF $DEVICE