summaryrefslogtreecommitdiffstats
path: root/tests/functions.sh
diff options
context:
space:
mode:
authorRuediger Meier2018-03-10 19:44:32 +0100
committerKarel Zak2018-03-19 11:46:11 +0100
commit9ca02cf52d70d56fc3f7e152c55154a15c62af6d (patch)
treeef005d92180afe8fbea8db7aa18079939de9f922 /tests/functions.sh
parenttests: fix grep expressions for devices (diff)
downloadkernel-qcow2-util-linux-9ca02cf52d70d56fc3f7e152c55154a15c62af6d.tar.gz
kernel-qcow2-util-linux-9ca02cf52d70d56fc3f7e152c55154a15c62af6d.tar.xz
kernel-qcow2-util-linux-9ca02cf52d70d56fc3f7e152c55154a15c62af6d.zip
tests: consolidate ts_device_has UUID or LABEL
Regarding parallel root checks ... - fix: add a few missing "udevadm settle" where we are using LABELs or UUIDs - introduce ts_udevadm_settle(): * Still trivial implementation. The idea is to use it in future for all tests instead of directly calling "udevadm settle". So we could add debug messages, wait for specific events, add code for non-udev systems or even use "udevadm --{start,stop}-exec-queue" to be really sure what we are doing and why using udevadm at all. * The currently unused args may be used in future and show the code reader already now why we are calling "udevadm settle" at all. * So far this patch only affects swapon/, mount/, libmount/ tests, and is only about UUIDs and LABELs, but may be continued later for "partitions", "md devices", whatever. * We are calling ts_udevadm_settle() right *before* we need a LABEL or UUID, not just *after* we created one. This may be a bit better for speed and shows the code reader which command would fail without settle. - function ts_device_has_uuid() is unused now, we trust blkid(1). Renamed to ts_is_uuid() in case we would need it again. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/functions.sh')
-rw-r--r--tests/functions.sh50
1 files changed, 34 insertions, 16 deletions
diff --git a/tests/functions.sh b/tests/functions.sh
index 66eaa9d6e..0f991881a 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -555,16 +555,34 @@ function ts_device_deinit {
fi
}
+function ts_blkidtag_by_devname()
+{
+ local tag=$1
+ local dev=$2
+ local out
+ local rval
+
+ out=$($TS_CMD_BLKID -p -s "$tag" -o value "$dev")
+ rval=$?
+ printf "%s\n" "$out"
+
+ test -n "$out" -a "$rval" = "0"
+ return $?
+}
+
function ts_uuid_by_devname {
- echo $($TS_CMD_BLKID -p -s UUID -o value $1)
+ ts_blkidtag_by_devname "UUID" "$1"
+ return $?
}
function ts_label_by_devname {
- echo $($TS_CMD_BLKID -p -s LABEL -o value $1)
+ ts_blkidtag_by_devname "LABEL" "$1"
+ return $?
}
function ts_fstype_by_devname {
- echo $($TS_CMD_BLKID -p -s TYPE -o value $1)
+ ts_blkidtag_by_devname "TYPE" "$1"
+ return $?
}
function ts_device_has {
@@ -573,24 +591,24 @@ function ts_device_has {
local DEV="$3"
local vl=""
- case $TAG in
- "TYPE") vl=$(ts_fstype_by_devname $DEV);;
- "LABEL") vl=$(ts_label_by_devname $DEV);;
- "UUID") vl=$(ts_uuid_by_devname $DEV);;
- *) return 1;;
- esac
-
- if [ "$vl" == "$VAL" ]; then
- return 0
- fi
- return 1
+ vl=$(ts_blkidtag_by_devname "$TAG" "$DEV")
+ test $? = 0 -a "$vl" = "$VAL"
+ return $?
}
-function ts_device_has_uuid {
- ts_uuid_by_devname "$1" | egrep -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
+function ts_is_uuid()
+{
+ printf "%s\n" "$1" | egrep -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
return $?
}
+function ts_udevadm_settle()
+{
+ local dev=$1 # optional, might be empty
+ shift # all other args are tags, LABEL, UUID, ...
+ udevadm settle
+}
+
function ts_mount {
local out
local result