]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add testcase for udev-watch 23087/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Apr 2022 10:28:11 +0000 (19:28 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 11 Sep 2022 16:36:06 +0000 (01:36 +0900)
test/units/testsuite-64.sh

index 6704e9933c043ef4461907a3741862bbbdf47635..4ddea69c51cbaf71f882e578f20fe967f0a1f18a 100755 (executable)
@@ -41,6 +41,48 @@ helper_check_device_symlinks() {(
     done < <(find "${paths[@]}" -type l)
 )}
 
+helper_check_udev_watch() {(
+    set +x
+
+    local link target id dev
+
+    while read -r link; do
+        target="$(readlink "$link")"
+        echo "$link -> $target"
+
+        if [[ ! -L "/run/udev/watch/$target" ]]; then
+            echo >&2 "ERROR: symlink /run/udev/watch/$target does not exist"
+            return 1
+        fi
+        if [[ "$(readlink "/run/udev/watch/$target")" != "$(basename "$link")" ]]; then
+            echo >&2 "ERROR: symlink target of /run/udev/watch/$target is inconsistent with $link"
+            return 1
+        fi
+
+        if [[ "$target" =~ ^[0-9]+$ ]]; then
+            # $link is ID -> wd
+            id="$(basename "$link")"
+        else
+            # $link is wd -> ID
+            id="$target"
+        fi
+
+        if [[ "${id:0:1}" == "b" ]]; then
+            dev="/dev/block/${id:1}"
+        elif [[ "${id:0:1}" == "c" ]]; then
+            dev="/dev/char/${id:1}"
+        else
+            echo >&2 "ERROR: unexpected device ID '$id'"
+            return 1
+        fi
+
+        if [[ ! -e "$dev" ]]; then
+            echo >&2 "ERROR: device '$dev' corresponding to symlink '$link' does not exist"
+            return 1
+        fi
+    done < <(find /run/udev/watch -type l)
+)}
+
 testcase_megasas2_basic() {
     lsblk -S
     [[ "$(lsblk --scsi --noheadings | wc -l)" -ge 128 ]]
@@ -201,6 +243,7 @@ EOF
         if ((i % 10 == 0)); then
             udevadm wait --settle --timeout="$timeout" "$blockdev"
             helper_check_device_symlinks
+            helper_check_udev_watch
         fi
     done