test: test udev with a _very_ long device name

Let's attempt to provide some coverage for #16161, #6867, and similar.
This commit is contained in:
Frantisek Sumsal 2021-10-01 13:56:25 +02:00 committed by Yu Watanabe
parent 414bd2e786
commit f415cdb372
2 changed files with 90 additions and 5 deletions

View file

@ -2,10 +2,9 @@
# vi: ts=4 sw=4 tw=0 et:
#
# TODO:
# * iSCSI
# * LVM over iSCSI (?)
# * SW raid (mdadm)
# * MD (mdadm) -> DM-CRYPT -> LVM
# * MD (mdadm) -> dm-crypt -> LVM
# * iSCSI -> dm-crypt -> LVM
set -e
TEST_DESCRIPTION="systemd-udev storage tests"
@ -69,7 +68,7 @@ test_append_files() {(
instmods "=block" "=md" "=nvme" "=scsi"
install_dmevent
image_install lsblk wc wipefs
image_install lsblk swapoff swapon wc wipefs
# Install the optional features if the host has the respective tooling
for feature in "${!features[@]}"; do
@ -391,13 +390,51 @@ testcase_iscsi_lvm() {
)
done
KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}"
QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}"
test_run_one "${1:?}" || return $?
rm -f "${TESTDIR:?}"/iscsibasic*.img
}
testcase_long_sysfs_path() {
local brid
local testdisk="${TESTDIR:?}/longsysfspath.img"
local qemu_opts=(
"-drive if=none,id=drive0,format=raw,cache=unsafe,file=$testdisk"
"-device pci-bridge,id=pci_bridge0,bus=pci.0,chassis_nr=64"
)
dd if=/dev/zero of="$testdisk" bs=1M count=64
lodev="$(losetup --show -f -P "$testdisk")"
sfdisk "${lodev:?}" <<EOF
label: gpt
name="test_swap", size=32M
uuid="deadbeef-dead-dead-beef-000000000000", name="test_part", size=5M
EOF
udevadm settle
mkswap -U "deadbeef-dead-dead-beef-111111111111" -L "swap_vol" "${lodev}p1"
mkfs.ext4 -U "deadbeef-dead-dead-beef-222222222222" -L "data_vol" "${lodev}p2"
losetup -d "$lodev"
# Create 25 additional PCI bridges, each one connected to the previous one
# (basically a really long extension cable), and attach a virtio drive to
# the last one. This should force udev into attempting to create a device
# unit with a _really_ long name.
for brid in {1..25}; do
qemu_opts+=("-device pci-bridge,id=pci_bridge$brid,bus=pci_bridge$((brid-1)),chassis_nr=$((64+brid))")
done
qemu_opts+=("-device virtio-blk-pci,drive=drive0,scsi=off,bus=pci_bridge$brid")
KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}"
QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}"
test_run_one "${1:?}" || return $?
rm -f "${testdisk:?}"
}
# Allow overriding which tests should be run from the "outside", useful for manual
# testing (make -C test/... TESTCASES="testcase1 testcase2")
if [[ -v "TESTCASES" && -n "$TESTCASES" ]]; then

View file

@ -588,6 +588,53 @@ testcase_iscsi_lvm() {
umount "$mpoint"
rm -rf "$mpoint"
}
testcase_long_sysfs_path() {
local link logfile mpoint
local expected_symlinks=(
"/dev/disk/by-label/data_vol"
"/dev/disk/by-label/swap_vol"
"/dev/disk/by-partlabel/test_swap"
"/dev/disk/by-partlabel/test_part"
"/dev/disk/by-partuuid/deadbeef-dead-dead-beef-000000000000"
"/dev/disk/by-uuid/deadbeef-dead-dead-beef-111111111111"
"/dev/disk/by-uuid/deadbeef-dead-dead-beef-222222222222"
)
# Make sure the test device is connected and show its "wonderful" path
stat /sys/block/vda
readlink -f /sys/block/vda/dev
for link in "${expected_symlinks[@]}"; do
test -e "$link"
done
# Try to mount the data partition manually (using its label)
mpoint="$(mktemp -d /logsysfsXXX)"
mount LABEL=data_vol "$mpoint"
touch "$mpoint/test"
umount "$mpoint"
# Do the same, but with UUID and using fstab
echo "UUID=deadbeef-dead-dead-beef-222222222222 $mpoint ext4 defaults 0 0" >>/etc/fstab
systemctl daemon-reload
mount "$mpoint"
test -e "$mpoint/test"
umount "$mpoint"
# Test out the swap partition
swapon -v -L swap_vol
swapoff -v -L swap_vol
logfile="$(mktemp)"
journalctl -b -q --no-pager -o short-monotonic -p info --grep "Device path.*vda.?' too long to fit into unit name"
# Make sure we don't unnecessarily spam the log
journalctl -b -q --no-pager -o short-monotonic -p info --grep "/sys/devices/.+/vda[0-9]?" _PID=1 + UNIT=systemd-udevd.service | tee "$logfile"
[[ "$(wc -l <"$logfile")" -lt 10 ]]
: >/etc/fstab
rm -fr "${logfile:?}" "${mpoint:?}"
}
: >/failed
udevadm settle
@ -605,6 +652,7 @@ fi
echo "TEST_FUNCTION_NAME=$TEST_FUNCTION_NAME"
"$TEST_FUNCTION_NAME"
udevadm settle
echo "Check if all symlinks under /dev/disk/ are valid (post-test)"
helper_check_device_symlinks