1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

test: update test case for failed udev event

This commit is contained in:
Yu Watanabe 2024-01-03 04:23:26 +09:00
parent b16c6076cb
commit 5592608bdc

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -ex
set -eux
TMPDIR=
TEST_RULE="/run/udev/rules.d/49-test.rules"
KILL_PID=
@ -10,8 +11,15 @@ setup() {
[[ -e /etc/udev/udev.conf ]] && cp -f /etc/udev/udev.conf /etc/udev/udev.conf.bak
cat >"${TEST_RULE}" <<EOF
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug"
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", PROGRAM=="/bin/sleep 60"
ACTION!="add", GOTO="test_end"
SUBSYSTEM!="mem", GOTO="test_end"
KERNEL!="null", GOTO="test_end"
OPTIONS="log_level=debug"
PROGRAM=="/bin/touch /tmp/test-udev-marker"
PROGRAM!="/bin/sleep 60", ENV{PROGRAM_RESULT}="KILLED"
LABEL="test_end"
EOF
cat >/etc/udev/udev.conf <<EOF
event_timeout=10
@ -35,11 +43,7 @@ teardown() {
systemctl restart systemd-udevd.service
}
run_test() {
local since
since="$(date '+%F %T')"
run_test_timeout() {
TMPDIR=$(mktemp -d -p /tmp udev-tests.XXXXXX)
udevadm monitor --udev --property --subsystem-match=mem >"$TMPDIR"/monitor.txt &
KILL_PID="$!"
@ -47,7 +51,43 @@ run_test() {
SYSTEMD_LOG_LEVEL=debug udevadm trigger --verbose --action add /dev/null
for _ in {1..40}; do
if coredumpctl --since "$since" --no-legend --no-pager | grep /bin/udevadm ; then
if grep -q 'PROGRAM_RESULT=KILLED' "$TMPDIR"/monitor.txt; then
sleep .5
kill "$KILL_PID"
KILL_PID=
cat "$TMPDIR"/monitor.txt
(! grep -q 'UDEV_WORKER_FAILED=1' "$TMPDIR"/monitor.txt)
(! grep -q 'UDEV_WORKER_SIGNAL=6' "$TMPDIR"/monitor.txt)
(! grep -q 'UDEV_WORKER_SIGNAL_NAME=ABRT' "$TMPDIR"/monitor.txt)
grep -q 'PROGRAM_RESULT=KILLED' "$TMPDIR"/monitor.txt
rm -rf "$TMPDIR"
return 0
fi
sleep .5
done
return 1
}
run_test_killed() {
local killed=
TMPDIR=$(mktemp -d -p /tmp udev-tests.XXXXXX)
udevadm monitor --udev --property --subsystem-match=mem >"$TMPDIR"/monitor.txt &
KILL_PID="$!"
rm -f /tmp/test-udev-marker
SYSTEMD_LOG_LEVEL=debug udevadm trigger --verbose --action add /dev/null
for _ in {1..40}; do
if [[ -z "$killed" ]]; then
if [[ -e /tmp/test-udev-marker ]]; then
killall --signal ABRT --regexp udev-worker
killed=1
fi
elif grep -q 'UDEV_WORKER_FAILED=1' "$TMPDIR"/monitor.txt; then
sleep .5
kill "$KILL_PID"
KILL_PID=
@ -55,6 +95,8 @@ run_test() {
grep -q 'UDEV_WORKER_FAILED=1' "$TMPDIR"/monitor.txt
grep -q 'UDEV_WORKER_SIGNAL=6' "$TMPDIR"/monitor.txt
grep -q 'UDEV_WORKER_SIGNAL_NAME=ABRT' "$TMPDIR"/monitor.txt
(! grep -q 'PROGRAM_RESULT=KILLED' "$TMPDIR"/monitor.txt)
rm -rf "$TMPDIR"
return 0
fi
sleep .5
@ -66,6 +108,7 @@ run_test() {
trap teardown EXIT
setup
run_test
run_test_timeout
run_test_killed
exit 0