TEST-81-GENERATORS: add test cases for systemd.getty_auto=console and friends

This commit is contained in:
Yu Watanabe
2025-07-19 02:10:15 +09:00
parent 3a883e89bc
commit 36c3862789

View File

@@ -20,20 +20,25 @@ trap at_exit EXIT
test -x "${GENERATOR_BIN:?}"
if in_container; then
# Do a limited test in a container, as writing to /dev is usually restrited
: "getty-generator: \$container_ttys env (container)"
# In a container we allow only /dev/pts/* ptys
PID1_ENVIRON="container_ttys=tty0 pts/0 /dev/tty0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_none() {
[[ "$(find "$OUT_DIR" ! -type d | wc -l)" -eq 0 ]]
}
# console-getty.service is always pulled in in containers
check_container() {
link_endswith "$OUT_DIR/normal/getty.target.wants/console-getty.service" "/lib/systemd/system/console-getty.service"
link_endswith "$OUT_DIR/normal/getty.target.wants/container-getty@0.service" "/lib/systemd/system/container-getty@.service"
test ! -e "$OUT_DIR/normal/getty.target.wants/container-getty@tty0.service"
test ! -h "$OUT_DIR/normal/getty.target.wants/container-getty@tty0.service"
}
exit 0
fi
check_no_container() {
local unit
for unit in console-getty.service container-getty@0.service container-getty@tty0.service; do
test ! -e "$OUT_DIR/normal/getty.target.wants/$unit"
test ! -h "$OUT_DIR/normal/getty.target.wants/$unit"
done
}
DUMMY_ACTIVE_CONSOLES=(
"hvc99"
@@ -52,6 +57,94 @@ DUMMY_CONSOLES=(
"${DUMMY_ACTIVE_CONSOLES[@]}"
"${DUMMY_INACTIVE_CONSOLES[@]}"
)
check_console() {
local console unit
for console in "${DUMMY_ACTIVE_CONSOLES[@]}"; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
link_endswith "$OUT_DIR/normal/getty.target.wants/$unit" "/lib/systemd/system/serial-getty@.service"
done
for console in "${DUMMY_INACTIVE_CONSOLES[@]}" /dev/notatty99; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
test ! -e "$OUT_DIR/normal/getty.target.wants/$unit"
test ! -h "$OUT_DIR/normal/getty.target.wants/$unit"
done
}
check_no_console() {
local console unit
for console in "${DUMMY_CONSOLES[@]}" /dev/notatty99; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
test ! -e "$OUT_DIR/normal/getty.target.wants/$unit"
test ! -h "$OUT_DIR/normal/getty.target.wants/$unit"
done
}
BUILTINS=(
"hvc0"
"xvc0"
"hvsi0"
"sclp_line0"
"ttysclp0"
"3270/tty1"
)
check_builtin() {
local console unit
for console in "${BUILTINS[@]}"; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
if [[ -e "/dev/$console" ]]; then
link_endswith "$OUT_DIR/normal/getty.target.wants/$unit" "/lib/systemd/system/serial-getty@.service"
else
test ! -e "$OUT_DIR/normal/getty.target.wants/$unit"
test ! -h "$OUT_DIR/normal/getty.target.wants/$unit"
fi
done
}
check_no_builtin() {
local console unit
for console in "${BUILTINS[@]}"; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
test ! -e "$OUT_DIR/normal/getty.target.wants/$unit"
test ! -h "$OUT_DIR/normal/getty.target.wants/$unit"
done
}
if in_container; then
# Do a limited test in a container, as writing to /dev is usually restrited
: "getty-generator: \$container_ttys env (container)"
# In a container we allow only /dev/pts/* ptys
PID1_ENVIRON="container_ttys=tty0 pts/0 /dev/tty0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_container
check_no_console
check_no_builtin
: "getty-generator: SYSTEMD_GETTY_AUTO=0 in PID1's environment (container)"
PID1_ENVIRON="container_ttys=tty0 pts/0 /dev/tty0\0SYSTEMD_GETTY_AUTO=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_none
: "getty-generator: SYSTEMD_GETTY_AUTO=console in PID1's environment (container)"
PID1_ENVIRON="container_ttys=tty0 pts/0 /dev/tty0\0SYSTEMD_GETTY_AUTO=console" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_none
: "getty-generator: SYSTEMD_GETTY_AUTO=console,builtin in PID1's environment (container)"
PID1_ENVIRON="container_ttys=tty0 pts/0 /dev/tty0\0SYSTEMD_GETTY_AUTO=console,builtin" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_none
: "getty-generator: SYSTEMD_GETTY_AUTO=console,builtin,container in PID1's environment (container)"
PID1_ENVIRON="container_ttys=tty0 pts/0 /dev/tty0\0SYSTEMD_GETTY_AUTO=console,builtin,container" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_container
check_no_console
check_no_builtin
exit 0
fi
# Create a bunch of dummy consoles
for console in "${DUMMY_CONSOLES[@]}"; do
mknod "/dev/$console" c 4 0
@@ -60,29 +153,55 @@ done
touch /dev/notatty99
# Temporarily replace /sys/class/tty/console/active with our list of dummy
# consoles so getty-generator can process them
echo -ne "${DUMMY_ACTIVE_CONSOLES[@]}" /dev/notatty99 >/tmp/dummy-active-consoles
echo -ne "${DUMMY_ACTIVE_CONSOLES[@]}" /dev/notatty99 >/tmp/dummy-active-consoles
mount -v --bind /tmp/dummy-active-consoles /sys/class/tty/console/active
: "getty-generator: no arguments"
# Sneak in an invalid value for $SYSTEMD_GETTY_AUTO to test things out
PID1_ENVIRON="SYSTEMD_GETTY_AUTO=foo" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
for console in "${DUMMY_ACTIVE_CONSOLES[@]}"; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
link_endswith "$OUT_DIR/normal/getty.target.wants/$unit" "/lib/systemd/system/serial-getty@.service"
done
for console in "${DUMMY_INACTIVE_CONSOLES[@]}" /dev/notatty99; do
unit="$(systemd-escape --template serial-getty@.service "$console")"
test ! -e "$OUT_DIR/normal/getty.target.wants/$unit"
test ! -h "$OUT_DIR/normal/getty.target.wants/$unit"
done
check_no_container
check_console
check_builtin
: "getty-generator: systemd.getty_auto=0 on kernel cmdline"
SYSTEMD_PROC_CMDLINE="systemd.getty_auto=foo systemd.getty_auto=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
[[ "$(find "$OUT_DIR" ! -type d | wc -l)" -eq 0 ]]
check_none
: "getty-generator: systemd.getty_auto=container on kernel cmdline"
SYSTEMD_PROC_CMDLINE="systemd.getty_auto=foo systemd.getty_auto=container" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_none
: "getty-generator: systemd.getty_auto=container,console on kernel cmdline"
SYSTEMD_PROC_CMDLINE="systemd.getty_auto=foo systemd.getty_auto=container,console" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_no_container
check_console
check_no_builtin
: "getty-generator: systemd.getty_auto=container,builtin on kernel cmdline"
SYSTEMD_PROC_CMDLINE="systemd.getty_auto=foo systemd.getty_auto=container,builtin" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_no_container
check_no_console
check_builtin
: "getty-generator: SYSTEMD_GETTY_AUTO=0 in PID1's environment"
PID1_ENVIRON="SYSTEMD_GETTY_AUTO=0" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
[[ "$(find "$OUT_DIR" ! -type d | wc -l)" -eq 0 ]]
check_none
: "getty-generator: SYSTEMD_GETTY_AUTO=container in PID1's environment"
PID1_ENVIRON="SYSTEMD_GETTY_AUTO=container" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_none
: "getty-generator: SYSTEMD_GETTY_AUTO=container,console in PID1's environment"
PID1_ENVIRON="SYSTEMD_GETTY_AUTO=container,console" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_no_container
check_console
check_no_builtin
: "getty-generator: SYSTEMD_GETTY_AUTO=container,builtin in PID1's environment"
PID1_ENVIRON="SYSTEMD_GETTY_AUTO=container,builtin" run_and_list "$GENERATOR_BIN" "$OUT_DIR"
check_no_container
check_no_console
check_builtin
# Cleanup
umount /sys/class/tty/console/active --lazy