From 6788418af1b206edd2d8b6dedcb5c5f7ac8732f8 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 11 Oct 2022 09:54:35 +0200 Subject: [PATCH] test: add coverage for the nvme-subsystem Specifically for: - https://github.com/systemd/systemd/pull/24748 - https://github.com/systemd/systemd/pull/24766 - https://github.com/systemd/systemd/pull/24946 --- test/TEST-64-UDEV-STORAGE/test.sh | 30 ++++++++++++++++++++++++++++++ test/units/testsuite-64.sh | 12 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/test/TEST-64-UDEV-STORAGE/test.sh b/test/TEST-64-UDEV-STORAGE/test.sh index f662d4dafb6..f93b92e3c3d 100755 --- a/test/TEST-64-UDEV-STORAGE/test.sh +++ b/test/TEST-64-UDEV-STORAGE/test.sh @@ -205,6 +205,36 @@ testcase_nvme_basic() { test_run_one "${1:?}" } +# Testcase for: +# * https://github.com/systemd/systemd/pull/24748 +# * https://github.com/systemd/systemd/pull/24766 +# * https://github.com/systemd/systemd/pull/24946 +# Docs: https://qemu.readthedocs.io/en/latest/system/devices/nvme.html#nvm-subsystems +testcase_nvme_subsystem() { + if ! "${QEMU_BIN:?}" -device help | grep 'name "nvme-subsys"'; then + echo "nvme-subsystem device driver is not available, skipping test..." + return 77 + fi + + local i + local qemu_opts=( + # Create an NVM Subsystem Device + "-device nvme-subsys,id=nvme-subsys-64,nqn=subsys64" + # Attach two NVM controllers to it + "-device nvme,subsys=nvme-subsys-64,serial=deadbeef" + "-device nvme,subsys=nvme-subsys-64,serial=deadbeef" + # And create two shared namespaces attached to both controllers + "-device nvme-ns,drive=nvme0,nsid=16,shared=on" + "-drive format=raw,cache=unsafe,file=${TESTDIR:?}/disk0.img,if=none,id=nvme0" + "-device nvme-ns,drive=nvme1,nsid=17,shared=on" + "-drive format=raw,cache=unsafe,file=${TESTDIR:?}/disk1.img,if=none,id=nvme1" + ) + + KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}" + QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}" + test_run_one "${1:?}" +} + # Test for issue https://github.com/systemd/systemd/issues/20212 testcase_virtio_scsi_identically_named_partitions() { diff --git a/test/units/testsuite-64.sh b/test/units/testsuite-64.sh index df92a0bb43a..76730363350 100755 --- a/test/units/testsuite-64.sh +++ b/test/units/testsuite-64.sh @@ -177,6 +177,18 @@ testcase_nvme_basic() { [[ "$(lsblk --noheadings | grep -c "^nvme")" -ge 28 ]] } +testcase_nvme_subsystem() { + local expected_symlinks=( + # Controller(s) + /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_deadbeef + # Shared namespaces + /dev/disk/by-path/pci-*-nvme-16 + /dev/disk/by-path/pci-*-nvme-17 + ) + + udevadm wait --settle --timeout=30 "${expected_symlinks[@]}" +} + testcase_virtio_scsi_identically_named_partitions() { local num