2021-03-07 23:21:45 +03:00
#!/bin/bash
2021-10-17 19:13:06 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-03-07 23:21:45 +03:00
set -ex
set -o pipefail
# tests for udev watch
function check_validity( ) {
local f ID_OR_HANDLE
for f in /run/udev/watch/*; do
2021-09-29 21:30:08 +03:00
ID_OR_HANDLE = " $( readlink " $f " ) "
test -L " /run/udev/watch/ ${ ID_OR_HANDLE } "
test " $( readlink " /run/udev/watch/ ${ ID_OR_HANDLE } " ) " = " $( basename " $f " ) "
2021-03-07 23:21:45 +03:00
done
}
function check( ) {
local i j
for ( ( i = 0; i<2; i++) ) ; do
systemctl restart systemd-udevd.service
udevadm control --ping
udevadm settle
check_validity
for ( ( j = 0; j<2; j++) ) ; do
udevadm trigger -w --action add --subsystem-match= block
check_validity
done
for ( ( j = 0; j<2; j++) ) ; do
udevadm trigger -w --action change --subsystem-match= block
check_validity
done
done
}
mkdir -p /run/udev/rules.d/
cat >/run/udev/rules.d/00-debug.rules <<EOF
SUBSYSTEM = = "block" , KERNEL = = "sda*" , OPTIONS = "log_level=debug"
EOF
cat >/run/udev/rules.d/50-testsuite.rules <<EOF
ACTION = = "add" , SUBSYSTEM = = "block" , KERNEL = = "sda" , OPTIONS:= "watch"
EOF
check
MAJOR = $( udevadm info /dev/sda | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//' )
MINOR = $( udevadm info /dev/sda | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//' )
2021-09-29 21:30:08 +03:00
test -L " /run/udev/watch/b ${ MAJOR } : ${ MINOR } "
2021-03-07 23:21:45 +03:00
cat >/run/udev/rules.d/50-testsuite.rules <<EOF
ACTION = = "change" , SUBSYSTEM = = "block" , KERNEL = = "sda" , OPTIONS:= "nowatch"
EOF
check
MAJOR = $( udevadm info /dev/sda | grep -e '^E: MAJOR=' | sed -e 's/^E: MAJOR=//' )
MINOR = $( udevadm info /dev/sda | grep -e '^E: MINOR=' | sed -e 's/^E: MINOR=//' )
2021-09-29 21:30:08 +03:00
test ! -e " /run/udev/watch/b ${ MAJOR } : ${ MINOR } "
2021-03-07 23:21:45 +03:00
rm /run/udev/rules.d/00-debug.rules
rm /run/udev/rules.d/50-testsuite.rules
udevadm control --reload
exit 0