2022-11-11 17:28:25 +03:00
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -ex
set -o pipefail
2023-05-16 20:09:13 +03:00
# shellcheck source=test/units/util.sh
. " $( dirname " $0 " ) " /util.sh
2022-11-11 17:28:25 +03:00
# Coverage test for udevadm
2023-05-16 21:55:45 +03:00
# shellcheck disable=SC2317
2022-11-11 17:28:25 +03:00
cleanup_17_10( ) {
2023-03-01 13:19:02 +03:00
set +e
2022-11-11 17:28:25 +03:00
2023-03-01 13:19:02 +03:00
losetup -d " $loopdev "
rm -f " $blk "
2022-11-11 17:28:25 +03:00
2023-03-01 13:19:02 +03:00
ip link delete " $netdev "
2022-11-11 17:28:25 +03:00
}
# Set up some test devices
trap cleanup_17_10 EXIT
netdev = dummy17.10
ip link add $netdev type dummy
blk = " $( mktemp) "
2023-11-15 10:15:59 +03:00
dd if = /dev/zero of = " $blk " bs = 1M count = 1
2022-11-11 17:28:25 +03:00
loopdev = " $( losetup --show -f " $blk " ) "
udevadm -h
2023-03-03 07:32:37 +03:00
udevadm control -e
2022-11-11 17:28:25 +03:00
udevadm control -l emerg
udevadm control -l alert
udevadm control -l crit
udevadm control -l err
udevadm control -l warning
udevadm control -l notice
udevadm control --log-level info
2023-03-03 07:32:37 +03:00
udevadm control --log-level debug
2023-03-01 13:19:02 +03:00
( ! udevadm control -l hello)
2022-11-11 17:28:25 +03:00
udevadm control -s
udevadm control -S
udevadm control -R
udevadm control -p HELLO = world
udevadm control -m 42
udevadm control --ping
udevadm control -t 5
udevadm control -h
udevadm info /dev/null
udevadm info /sys/class/net/$netdev
udevadm info " $( systemd-escape -p --suffix device /sys/devices/virtual/net/$netdev ) "
udevadm info --property DEVNAME /sys/class/net/$netdev
udevadm info --property DEVNAME --value /sys/class/net/$netdev
udevadm info --property HELLO /sys/class/net/$netdev
udevadm info -p class/net/$netdev
udevadm info -p /class/net/$netdev
2023-10-12 12:02:49 +03:00
udevadm info --json= off -p class/net/$netdev
udevadm info --json= pretty -p class/net/$netdev | jq .
udevadm info --json= short -p class/net/$netdev | jq .
2022-11-11 17:28:25 +03:00
udevadm info -n null
udevadm info -q all /sys/class/net/$netdev
udevadm info -q name /dev/null
udevadm info -q path /sys/class/net/$netdev
udevadm info -q property /sys/class/net/$netdev
udevadm info -q symlink /sys/class/net/$netdev
udevadm info -q name -r /dev/null
udevadm info --query symlink --root /sys/class/net/$netdev
2023-03-01 13:19:02 +03:00
( ! udevadm info -q hello -r /sys/class/net/$netdev )
2022-11-11 17:28:25 +03:00
udevadm info -a /sys/class/net/$netdev
2023-03-01 13:19:02 +03:00
udevadm info -t >/dev/null
2022-11-11 17:28:25 +03:00
udevadm info --tree /sys/class/net/$netdev
udevadm info -x /sys/class/net/$netdev
udevadm info -x -q path /sys/class/net/$netdev
udevadm info -P TEST_ /sys/class/net/$netdev
udevadm info -d /dev/null
2023-03-01 13:19:02 +03:00
udevadm info -e >/dev/null
2023-10-12 12:02:49 +03:00
udevadm info -e --json= off >/dev/null
udevadm info -e --json= pretty | jq . >/dev/null
udevadm info -e --json= short | jq . >/dev/null
2023-10-12 12:20:06 +03:00
udevadm info -e --subsystem-match acpi >/dev/null
udevadm info -e --subsystem-nomatch acpi >/dev/null
udevadm info -e --attr-match ifindex = 2 >/dev/null
udevadm info -e --attr-nomatch ifindex = 2 >/dev/null
udevadm info -e --property-match SUBSYSTEM = acpi >/dev/null
udevadm info -e --tag-match systemd >/dev/null
udevadm info -e --sysname-match lo >/dev/null
udevadm info -e --name-match /sys/class/net/$netdev >/dev/null
udevadm info -e --parent-match /sys/class/net/$netdev >/dev/null
udevadm info -e --initialized-match >/dev/null
udevadm info -e --initialized-nomatch >/dev/null
2022-11-11 17:28:25 +03:00
# udevadm info -c
udevadm info -w /sys/class/net/$netdev
udevadm info --wait-for-initialization= 5 /sys/class/net/$netdev
udevadm info -h
2023-08-04 23:03:16 +03:00
assert_rc 124 timeout 1 udevadm monitor
assert_rc 124 timeout 1 udevadm monitor -k
assert_rc 124 timeout 1 udevadm monitor -u
assert_rc 124 timeout 1 udevadm monitor -s net
assert_rc 124 timeout 1 udevadm monitor --subsystem-match net/$netdev
assert_rc 124 timeout 1 udevadm monitor -t systemd
assert_rc 124 timeout 1 udevadm monitor --tag-match hello
2022-11-11 17:28:25 +03:00
udevadm monitor -h
2023-03-03 17:19:27 +03:00
udevadm settle
2022-11-11 17:28:25 +03:00
udevadm settle -t 5
udevadm settle -E /sys/class/net/$netdev
udevadm settle -h
udevadm test /dev/null
udevadm info /sys/class/net/$netdev
udevadm test " $( systemd-escape -p --suffix device /sys/devices/virtual/net/$netdev ) "
udevadm test -a add /sys/class/net/$netdev
udevadm test -a change /sys/class/net/$netdev
udevadm test -a move /sys/class/net/$netdev
udevadm test -a online /sys/class/net/$netdev
udevadm test -a offline /sys/class/net/$netdev
udevadm test -a bind /sys/class/net/$netdev
udevadm test -a unbind /sys/class/net/$netdev
udevadm test -a help /sys/class/net/$netdev
udevadm test --action help
2023-03-01 13:19:02 +03:00
( ! udevadm test -a hello /sys/class/net/$netdev )
2022-11-11 17:28:25 +03:00
udevadm test -N early /sys/class/net/$netdev
udevadm test -N late /sys/class/net/$netdev
udevadm test --resolve-names never /sys/class/net/$netdev
2023-03-01 13:19:02 +03:00
( ! udevadm test -N hello /sys/class/net/$netdev )
2022-11-11 17:28:25 +03:00
udevadm test -h
# udevadm test-builtin path_id "$loopdev"
udevadm test-builtin net_id /sys/class/net/$netdev
udevadm test-builtin net_id " $( systemd-escape -p --suffix device /sys/devices/virtual/net/$netdev ) "
udevadm test-builtin -a add net_id /sys/class/net/$netdev
udevadm test-builtin -a remove net_id /sys/class/net/$netdev
udevadm test-builtin -a change net_id /sys/class/net/$netdev
udevadm test-builtin -a move net_id /sys/class/net/$netdev
udevadm test-builtin -a online net_id /sys/class/net/$netdev
udevadm test-builtin -a offline net_id /sys/class/net/$netdev
udevadm test-builtin -a bind net_id /sys/class/net/$netdev
udevadm test-builtin -a unbind net_id /sys/class/net/$netdev
udevadm test-builtin -a help net_id /sys/class/net/$netdev
udevadm test-builtin net_setup_link /sys/class/net/$netdev
udevadm test-builtin blkid " $loopdev "
udevadm test-builtin input_id /sys/class/net/$netdev
udevadm test-builtin keyboard /dev/null
# udevadm test-builtin kmod /sys/class/net/$netdev
udevadm test-builtin uaccess /dev/null
# udevadm test-builtin usb_id dev/null
2023-03-01 13:19:02 +03:00
( ! udevadm test-builtin hello /sys/class/net/$netdev )
2023-03-01 13:06:42 +03:00
# systemd-hwdb update is extremely slow when combined with sanitizers and run
# in a VM without acceleration, so let's just skip the one particular test
# if we detect this combination
if ! [ [ -v ASAN_OPTIONS && " $( systemd-detect-virt -v) " = = "qemu" ] ] ; then
modprobe scsi_debug
scsidev = $( readlink -f /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/[ 0-9] *)
2023-03-15 11:00:00 +03:00
mkdir -p /etc/udev/hwdb.d
2023-03-01 13:19:02 +03:00
cat >/etc/udev/hwdb.d/99-test.hwdb <<EOF
2023-03-01 13:06:42 +03:00
scsi:*
ID_TEST = test
EOF
systemd-hwdb update
udevadm test-builtin hwdb " $scsidev "
2023-03-09 15:32:56 +03:00
rmmod scsi_debug || :
rm -fv /etc/udev/hwdb.d/99-test.hwdb
2023-03-01 13:06:42 +03:00
systemd-hwdb update
fi
2022-11-11 17:28:25 +03:00
udevadm trigger
udevadm trigger /dev/null
udevadm trigger /sys/class/net/$netdev
udevadm trigger " $( systemd-escape -p --suffix device /sys/devices/virtual/net/$netdev ) "
udevadm trigger -v /sys/class/net/$netdev
udevadm trigger -n /sys/class/net/$netdev
udevadm trigger -q /sys/class/net/$netdev
udevadm trigger -t all /sys/class/net/$netdev
udevadm trigger -t devices /sys/class/net/$netdev
udevadm trigger --type subsystems /sys/class/net/$netdev
2023-03-01 13:19:02 +03:00
( ! udevadm trigger -t hello /sys/class/net/$netdev )
2022-11-11 17:28:25 +03:00
udevadm trigger -c add /sys/class/net/$netdev
udevadm trigger -c remove /sys/class/net/$netdev
udevadm trigger -c change /sys/class/net/$netdev
udevadm trigger -c move /sys/class/net/$netdev
udevadm trigger -c online /sys/class/net/$netdev
udevadm trigger -c offline /sys/class/net/$netdev
udevadm trigger -c bind /sys/class/net/$netdev
udevadm trigger -c unbind /sys/class/net/$netdev
udevadm trigger -c help /sys/class/net/$netdev
udevadm trigger --action help /sys/class/net/$netdev
2023-03-01 13:19:02 +03:00
( ! udevadm trigger -c hello /sys/class/net/$netdev )
2022-11-11 17:28:25 +03:00
udevadm trigger --prioritized-subsystem block
udevadm trigger --prioritized-subsystem block,net
udevadm trigger --prioritized-subsystem hello
udevadm trigger -s net
udevadm trigger -S net
udevadm trigger -a subsystem = net
udevadm trigger --attr-match hello = world
udevadm trigger -p DEVNAME = null
udevadm trigger --property-match HELLO = world
udevadm trigger -g systemd
udevadm trigger --tag-match hello
udevadm trigger -y net
udevadm trigger --sysname-match hello
udevadm trigger --name-match /sys/class/net/$netdev
udevadm trigger --name-match /sys/class/net/$netdev --name-match /dev/null
udevadm trigger -b /sys/class/net/$netdev
udevadm trigger --parent-match /sys/class/net/$netdev --name-match /dev/null
udevadm trigger --initialized-match
udevadm trigger --initialized-nomatch
udevadm trigger -w
udevadm trigger --uuid /sys/class/net/$netdev
2023-03-03 17:19:27 +03:00
udevadm settle -t 300
2022-11-11 17:28:25 +03:00
udevadm trigger --wait-daemon
2023-03-03 17:19:27 +03:00
udevadm settle -t 300
2022-11-11 17:28:25 +03:00
udevadm trigger --wait-daemon= 5
udevadm trigger -h
2023-11-06 14:26:53 +03:00
# https://github.com/systemd/systemd/issues/29863
if [ [ " $( systemd-detect-virt -v) " != "qemu" ] ] ; then
udevadm control --log-level= 0
for _ in { 0..9} ; do
timeout 30 udevadm trigger --settle
done
udevadm control --log-level= debug
fi
2022-11-11 17:28:25 +03:00
udevadm wait /dev/null
udevadm wait /sys/class/net/$netdev
udevadm wait -t 5 /sys/class/net/$netdev
udevadm wait --initialized true /sys/class/net/$netdev
udevadm wait --initialized false /sys/class/net/$netdev
2023-03-01 13:19:02 +03:00
( ! udevadm wait --initialized hello /sys/class/net/$netdev )
2022-11-11 17:28:25 +03:00
assert_rc 124 timeout 5 udevadm wait --removed /sys/class/net/$netdev
udevadm wait --settle /sys/class/net/$netdev
udevadm wait -h
2023-12-29 20:51:50 +03:00
udevadm lock --help
udevadm lock --version
for i in /dev/block/*; do
udevadm lock --device " $i " --print
udevadm lock --device " $i " true
( ! udevadm lock --device " $i " false )
done
for i in / /usr; do
udevadm lock --backing " $i " --print
udevadm lock --backing " $i " true
( ! udevadm lock --backing " $i " false )
done
2022-11-11 17:28:25 +03:00
exit 0