blob: d9dfdd7c222b257cab40fd872a20c2e47a7bfb60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -ex
set -o pipefail
# shellcheck source=test/units/util.sh
. "$(dirname "$0")"/util.sh
# Test for `udevadm control -p`
test_not_property() {
assert_eq "$(udevadm info --query property --property "$2" --value "$1")" ""
}
test_property() {
assert_eq "$(udevadm info --query property --property "$2" --value "$1")" "$3"
}
# shellcheck disable=SC2317
cleanup() {
set +e
udevadm control -p FOO= -p BAR=
rm -f "$rules"
}
# Set up a test device
trap cleanup EXIT
rules="/run/udev/rules.d/99-test-17.13.rules"
mkdir -p "${rules%/*}"
cat > "$rules" <<'EOF'
ENV{FOO}=="?*", ENV{PROP_FOO}="$env{FOO}"
ENV{BAR}=="?*", ENV{PROP_BAR}="$env{BAR}"
EOF
udevadm control --reload
test_not_property /dev/null PROP_FOO
test_not_property /dev/null PROP_BAR
: Setting of a property works
udevadm control --property FOO=foo
udevadm trigger --action change --settle /dev/null
test_property /dev/null PROP_FOO foo
test_not_property /dev/null PROP_BAR
: Change of a property works
udevadm control --property FOO=goo
udevadm trigger --action change --settle /dev/null
test_property /dev/null PROP_FOO goo
: Removal of a property works
udevadm control --property FOO=
udevadm trigger --action change --settle /dev/null
test_not_property /dev/null PROP_FOO
: Repeated removal of a property does nothing
udevadm control --property FOO=
udevadm trigger --action change --settle /dev/null
test_not_property /dev/null PROP_FOO
: Multiple properties can be set at once
udevadm control --property FOO=foo --property BAR=bar
udevadm trigger --action change --settle /dev/null
test_property /dev/null PROP_FOO foo
test_property /dev/null PROP_BAR bar
: Multiple setting of the same property is handled correctly
udevadm control --property FOO=foo --property FOO=42
udevadm trigger --action change --settle /dev/null
test_property /dev/null PROP_FOO 42
: Mix of settings and removals of the same property is handled correctly
udevadm control -p FOO= -p FOO=foo -p BAR=car -p BAR=
udevadm trigger --action change --settle /dev/null
test_property /dev/null PROP_FOO foo
test_not_property /dev/null PROP_BAR
exit 0
|