Add tests to verify add, edit and remove features of mediated devices. Signed-off-by: Shalini Chellathurai Saroja <shalini@xxxxxxxxxxxxx> --- .../virt-xml-add-hostdev-mdev-start.xml | 12 +++++++ .../cli/compare/virt-xml-add-hostdev-mdev.xml | 14 ++++++++ tests/data/cli/compare/virt-xml-edit-all.xml | 7 ++++ .../compare/virt-xml-edit-hostdev-mdev.xml | 11 +++++++ .../compare/virt-xml-edit-simple-redirdev.xml | 2 +- .../compare/virt-xml-remove-hostdev-mdev.xml | 15 +++++++++ tests/data/testdriver/testsuite.xml | 32 +++++++++++++++++++ tests/test_cli.py | 4 +++ tests/utils.py | 2 +- 9 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 tests/data/cli/compare/virt-xml-add-hostdev-mdev-start.xml create mode 100644 tests/data/cli/compare/virt-xml-add-hostdev-mdev.xml create mode 100644 tests/data/cli/compare/virt-xml-edit-hostdev-mdev.xml create mode 100644 tests/data/cli/compare/virt-xml-remove-hostdev-mdev.xml diff --git a/tests/data/cli/compare/virt-xml-add-hostdev-mdev-start.xml b/tests/data/cli/compare/virt-xml-add-hostdev-mdev-start.xml new file mode 100644 index 00000000..3742d454 --- /dev/null +++ b/tests/data/cli/compare/virt-xml-add-hostdev-mdev-start.xml @@ -0,0 +1,12 @@ + <model type="cirrus" vram="16384" heads="1" primary="yes"/> + </video> + <memballoon model="virtio"/> ++ <hostdev mode="subsystem" type="mdev" managed="no" model="vfio-ccw"> ++ <source> ++ <address uuid="8e37ee90-2b51-45e3-9b25-bf8283c03110"/> ++ </source> ++ </hostdev> + </devices> + </domain> + +Domain 'test-state-shutoff' started successfully. diff --git a/tests/data/cli/compare/virt-xml-add-hostdev-mdev.xml b/tests/data/cli/compare/virt-xml-add-hostdev-mdev.xml new file mode 100644 index 00000000..c2acff8f --- /dev/null +++ b/tests/data/cli/compare/virt-xml-add-hostdev-mdev.xml @@ -0,0 +1,14 @@ + <vsock model="virtio"> + <cid auto="no" address="5"/> + </vsock> ++ <hostdev mode="subsystem" type="mdev" managed="no" model="vfio-ccw"> ++ <source> ++ <address uuid="8e37ee90-2b51-45e3-9b25-bf8283c03110"/> ++ </source> ++ </hostdev> + </devices> + <seclabel type="dynamic" model="selinux" relabel="yes"/> + <keywrap> + +Domain 'test-for-virtxml' defined successfully. +Changes will take effect after the domain is fully powered off. diff --git a/tests/data/cli/compare/virt-xml-edit-all.xml b/tests/data/cli/compare/virt-xml-edit-all.xml index ed09effc..5bdee2aa 100644 --- a/tests/data/cli/compare/virt-xml-edit-all.xml +++ b/tests/data/cli/compare/virt-xml-edit-all.xml @@ -8,6 +8,13 @@ <address domain="0x0000" bus="0x00" slot="0x19" function="0x0"/> </source> <rom bar="off"/> ++ <driver name="vfio"/> + </hostdev> + <hostdev mode="subsystem" type="mdev" managed="no" model="vfio-ccw"> + <source> + <address uuid="b1ae8bf6-38b0-4c81-9d44-78ce3f520496"/> + </source> + <address type="ccw" cssid="0xfe" ssid="0x0" devno="0x0002"/> + <driver name="vfio"/> </hostdev> <redirdev bus="usb" type="tcp"> diff --git a/tests/data/cli/compare/virt-xml-edit-hostdev-mdev.xml b/tests/data/cli/compare/virt-xml-edit-hostdev-mdev.xml new file mode 100644 index 00000000..ef5523db --- /dev/null +++ b/tests/data/cli/compare/virt-xml-edit-hostdev-mdev.xml @@ -0,0 +1,11 @@ + <source> + <address uuid="b1ae8bf6-38b0-4c81-9d44-78ce3f520496"/> + </source> +- <address type="ccw" cssid="0xfe" ssid="0x0" devno="0x0002"/> ++ <address type="ccw" cssid="0xfe" ssid="0x0" devno="0x0008"/> + </hostdev> + <redirdev bus="usb" type="tcp"> + <source mode="connect" host="localhost" service="4000"/> + +Domain 'test-for-virtxml' defined successfully. +Changes will take effect after the domain is fully powered off. diff --git a/tests/data/cli/compare/virt-xml-edit-simple-redirdev.xml b/tests/data/cli/compare/virt-xml-edit-simple-redirdev.xml index 52ffddfe..f1a0ff6c 100644 --- a/tests/data/cli/compare/virt-xml-edit-simple-redirdev.xml +++ b/tests/data/cli/compare/virt-xml-edit-simple-redirdev.xml @@ -1,5 +1,5 @@ </source> - <rom bar="off"/> + <address type="ccw" cssid="0xfe" ssid="0x0" devno="0x0002"/> </hostdev> - <redirdev bus="usb" type="tcp"> - <source mode="connect" host="localhost" service="4000"/> diff --git a/tests/data/cli/compare/virt-xml-remove-hostdev-mdev.xml b/tests/data/cli/compare/virt-xml-remove-hostdev-mdev.xml new file mode 100644 index 00000000..d4c33804 --- /dev/null +++ b/tests/data/cli/compare/virt-xml-remove-hostdev-mdev.xml @@ -0,0 +1,15 @@ + </source> + <rom bar="off"/> + </hostdev> +- <hostdev mode="subsystem" type="mdev" managed="no" model="vfio-ccw"> +- <source> +- <address uuid="b1ae8bf6-38b0-4c81-9d44-78ce3f520496"/> +- </source> +- <address type="ccw" cssid="0xfe" ssid="0x0" devno="0x0002"/> +- </hostdev> + <redirdev bus="usb" type="tcp"> + <source mode="connect" host="localhost" service="4000"/> + <protocol type="raw"/> + +Domain 'test-for-virtxml' defined successfully. +Changes will take effect after the domain is fully powered off. diff --git a/tests/data/testdriver/testsuite.xml b/tests/data/testdriver/testsuite.xml index fd255138..a073cbce 100644 --- a/tests/data/testdriver/testsuite.xml +++ b/tests/data/testdriver/testsuite.xml @@ -259,6 +259,12 @@ </source> <rom bar='off'/> </hostdev> + <hostdev mode="subsystem" type="mdev" managed="no" model="vfio-ccw"> + <source> + <address uuid="b1ae8bf6-38b0-4c81-9d44-78ce3f520496"/> + </source> + <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0002'/> + </hostdev> <serial type='null'/> @@ -737,5 +743,31 @@ </capability> </device> +<device> + <name>mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110</name> + <path>/sys/devices/css0/0.0.0023/8e37ee90-2b51-45e3-9b25-bf8283c03110</path> + <parent>css_0_0_0023</parent> + <driver> + <name>vfio_mdev</name> + </driver> + <capability type='mdev'> + <type id='vfio_ccw-io'/> + <iommuGroup number='0'/> + </capability> +</device> + +<device> + <name>mdev_b1ae8bf6_38b0_4c81_9d44_78ce3f520496</name> + <path>/sys/devices/css0/0.0.0023/b1ae8bf6-38b0-4c81-9d44-78ce3f520496</path> + <parent>css_0_0_0023</parent> + <driver> + <name>vfio_mdev</name> + </driver> + <capability type='mdev'> + <type id='vfio_ccw-io'/> + <iommuGroup number='0'/> + </capability> +</device> + </node> diff --git a/tests/test_cli.py b/tests/test_cli.py index 48c10b8e..b59eb4a1 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1288,6 +1288,7 @@ c.add_compare("--edit mac=00:11:7f:33:44:55 --network target=nic55", "edit-selec c.add_compare("--edit target=hda --disk boot_order=1", "edit-select-disk-bootorder") c.add_compare("--edit path=/dev/null --disk path=,target=fdb,boot_order=12", "edit-disk-unset") # --disk matching, using empty value to unset path c.add_compare("--edit --memballoon none", "edit-disable-memballoon") +c.add_compare("--edit address.devno=0x0002 --hostdev address.devno=0x0008", "edit-hostdev-mdev") c = vixml.add_category("edit and start selection", "test-state-shutoff --print-diff --start") c.add_compare("--define --edit target=vda --disk boot_order=1", "start-select-disk-bootorder") @@ -1322,6 +1323,8 @@ c.add_compare("--remove-device --disk /dev/null", "remove-disk-path") c.add_compare("--remove-device --video all", "remove-video-all") c.add_compare("--remove-device --host-device 0x04b3:0x4485", "remove-hostdev-name") c.add_compare("--remove-device --memballoon all", "remove-memballoon") +c.add_compare("--add-device --hostdev mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110", "add-hostdev-mdev") +c.add_compare("--remove-device --hostdev mdev_b1ae8bf6_38b0_4c81_9d44_78ce3f520496", "remove-hostdev-mdev") c = vixml.add_category("add/rm devices and start", "test-state-shutoff --print-diff --start") c.add_invalid("--add-device --pm suspend_to_disk=yes") # --add-device without a device @@ -1332,6 +1335,7 @@ c.add_compare("--define --add-device --host-device usb_device_4b3_4485_noserial" c.add_compare("--add-device --disk %(EXISTIMG1)s,bus=virtio,target=vdf", "add-disk-basic-start") c.add_compare("--add-device --disk %(NEWIMG1)s,size=.01", "add-disk-create-storage-start") c.add_compare("--remove-device --disk /dev/null", "remove-disk-path-start") +c.add_compare("--add-device --hostdev mdev_8e37ee90_2b51_45e3_9b25_bf8283c03110", "add-hostdev-mdev-start") c = vixml.add_category("add/rm devices OS KVM", "--connect %(URI-KVM)s test --print-diff --define") c.add_compare("--add-device --disk %(EXISTIMG1)s", "kvm-add-disk-os-from-xml") # Guest OS (none) from XML diff --git a/tests/utils.py b/tests/utils.py index 802d6590..8a8a243a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -232,7 +232,7 @@ def diff_compare(actual_out, filename=None, expect_out=None): open(filename, "w").write(actual_out) expect_out = open(filename).read() - diff = xmlutil.diff(expect_out, actual_out, + diff = xmlutil.diff(expect_out.rstrip(), actual_out.rstrip(), filename or '', "Generated output") if diff: raise AssertionError("Conversion outputs did not match.\n%s" % diff) -- 2.30.2