diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2021-10-01 13:56:25 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-10-06 20:17:44 +0200 |
commit | f415cdb3723200e3ceebd2ef18a919fbe2d76710 (patch) | |
tree | 8f4fb267daabbc9344b640759157202695c0aebe /test | |
parent | coredump: Don't log an error if D-Bus isn't running (diff) | |
download | systemd-f415cdb3723200e3ceebd2ef18a919fbe2d76710.tar.xz systemd-f415cdb3723200e3ceebd2ef18a919fbe2d76710.zip |
test: test udev with a _very_ long device name
Let's attempt to provide some coverage for #16161, #6867, and similar.
Diffstat (limited to 'test')
-rwxr-xr-x | test/TEST-64-UDEV-STORAGE/test.sh | 47 | ||||
-rwxr-xr-x | test/units/testsuite-64.sh | 48 |
2 files changed, 90 insertions, 5 deletions
diff --git a/test/TEST-64-UDEV-STORAGE/test.sh b/test/TEST-64-UDEV-STORAGE/test.sh index 23cdefa5ce..bd3f8250a3 100755 --- a/test/TEST-64-UDEV-STORAGE/test.sh +++ b/test/TEST-64-UDEV-STORAGE/test.sh @@ -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 diff --git a/test/units/testsuite-64.sh b/test/units/testsuite-64.sh index 13a1316b7a..6f8382707f 100755 --- a/test/units/testsuite-64.sh +++ b/test/units/testsuite-64.sh @@ -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 |