summaryrefslogtreecommitdiffstats
path: root/test/units/testsuite-17.08.sh
blob: e570c69e9fdf1c722a76d54ed324d18621151036 (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
#!/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

# This is a test for issue #24518.

mkdir -p /run/udev/rules.d/
cat >/run/udev/rules.d/50-testsuite.rules <<EOF
SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug", TAG+="systemd"
SUBSYSTEM=="mem", KERNEL=="null", ACTION=="add",    SYMLINK+="test/symlink-to-null-on-add",    ENV{SYSTEMD_ALIAS}+="/sys/test/alias-to-null-on-add"
SUBSYSTEM=="mem", KERNEL=="null", ACTION=="change", SYMLINK+="test/symlink-to-null-on-change", ENV{SYSTEMD_ALIAS}+="/sys/test/alias-to-null-on-change"
EOF

udevadm control --reload

udevadm trigger --settle --action add /dev/null
for i in {1..20}; do
    ((i > 1)) && sleep .5

    (
        systemctl -q is-active /dev/test/symlink-to-null-on-add
        ! systemctl -q is-active /dev/test/symlink-to-null-on-change
        systemctl -q is-active /sys/test/alias-to-null-on-add
        ! systemctl -q is-active /sys/test/alias-to-null-on-change
    ) && break
done
assert_rc 0 systemctl -q is-active /dev/test/symlink-to-null-on-add
assert_rc 3 systemctl -q is-active /dev/test/symlink-to-null-on-change
assert_rc 0 systemctl -q is-active /sys/test/alias-to-null-on-add
assert_rc 3 systemctl -q is-active /sys/test/alias-to-null-on-change

udevadm trigger --settle --action change /dev/null
for i in {1..20}; do
    ((i > 1)) && sleep .5

    (
        ! systemctl -q is-active /dev/test/symlink-to-null-on-add
        systemctl -q is-active /dev/test/symlink-to-null-on-change
        ! systemctl -q is-active /sys/test/alias-to-null-on-add
        systemctl -q is-active /sys/test/alias-to-null-on-change
    ) && break
done
assert_rc 3 systemctl -q is-active /dev/test/symlink-to-null-on-add
assert_rc 0 systemctl -q is-active /dev/test/symlink-to-null-on-change
assert_rc 3 systemctl -q is-active /sys/test/alias-to-null-on-add
assert_rc 0 systemctl -q is-active /sys/test/alias-to-null-on-change

udevadm trigger --settle --action add /dev/null
for i in {1..20}; do
    ((i > 1)) && sleep .5

    (
        systemctl -q is-active /dev/test/symlink-to-null-on-add
        ! systemctl -q is-active /dev/test/symlink-to-null-on-change
        systemctl -q is-active /sys/test/alias-to-null-on-add
        ! systemctl -q is-active /sys/test/alias-to-null-on-change
    ) && break
done
assert_rc 0 systemctl -q is-active /dev/test/symlink-to-null-on-add
assert_rc 3 systemctl -q is-active /dev/test/symlink-to-null-on-change
assert_rc 0 systemctl -q is-active /sys/test/alias-to-null-on-add
assert_rc 3 systemctl -q is-active /sys/test/alias-to-null-on-change

# cleanup
rm -f /run/udev/rules.d/50-testsuite.rules
udevadm control --reload

exit 0