diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-05-11 19:17:13 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-05-14 12:43:28 +0200 |
commit | 7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5 (patch) | |
tree | 9464b421b4486e0af21b49706467a1f8053eda8f /test/units/TEST-17-UDEV.13.sh | |
parent | test: Rework integration test definitions (diff) | |
download | systemd-7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5.tar.xz systemd-7a321b5a21f7ad4ed526ac5a40ea0fabeb2e2ba5.zip |
test: Rename testsuite-XX units to match test name
Having these named differently than the test itself mostly creates
unecessary confusion and makes writing logic against the tests harder
so let's rename the testsuite-xx units and scripts to just use the
test name itself.
Diffstat (limited to 'test/units/TEST-17-UDEV.13.sh')
-rwxr-xr-x | test/units/TEST-17-UDEV.13.sh | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/units/TEST-17-UDEV.13.sh b/test/units/TEST-17-UDEV.13.sh new file mode 100755 index 0000000000..d9dfdd7c22 --- /dev/null +++ b/test/units/TEST-17-UDEV.13.sh @@ -0,0 +1,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 |