Skip to content

Commit

Permalink
q-dev: update tests + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Jun 17, 2024
1 parent 6c57e91 commit 3c031f7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
4 changes: 2 additions & 2 deletions qubes_config/global_config/usb_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ def __init__(self,

for vm in self.qapp.domains:
for assignment in vm.devices['pci'].get_attached_devices():
if any(infc.category for infc in assignment.device.interfaces
) == DeviceCategory.PCI_USB:
cats = [infc.category for infc in assignment.device.interfaces]
if DeviceCategory.PCI_USB in cats:
usb_qubes.add(vm)

self.input_handler = InputDeviceHandler(
Expand Down
14 changes: 14 additions & 0 deletions qubes_config/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ def test_qapp_impl():
add_feature_to_all(qapp, 'service.qubes-u2f-proxy',
['test-vm'])

for vm in qapp.domains:
qapp.expected_calls[
(vm.name, 'admin.vm.device.pci.Attached', None, None)] = b'0\x00'

return qapp


Expand Down Expand Up @@ -380,6 +384,10 @@ def test_qapp_simple(): # pylint: disable=redefined-outer-name
{"netvm": ("vm", False, '')},
{'service.qubes-update-check': None}, [])

for vm in qapp.domains:
qapp.expected_calls[
(vm.name, 'admin.vm.device.pci.Attached', None, None)] = b'0\x00'

return qapp


Expand Down Expand Up @@ -421,6 +429,12 @@ def test_qapp_broken(): # pylint: disable=redefined-outer-name
'gui-default-secure-copy-sequence': None,
'gui-default-secure-paste-sequence': None
}, [])

#
for vm in qapp.domains:
qapp.expected_calls[
(vm.name, 'admin.vm.device.pci.Attached', None, None)] = b'0\x00'

return qapp


Expand Down
42 changes: 30 additions & 12 deletions qubes_config/tests/test_usb_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,13 +843,19 @@ def test_u2f_handler_add_without_service(test_qapp,


def test_devices_handler_unsaved(test_qapp, test_policy_manager, real_builder):
test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.List",
test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.Attached",
None, None)] = \
b"0\x00dom0+00_0d.0 no-strict-reset=True persistent=yes\n"
b"0\x00dom0+00_0d.0 ident='00_0d.0' devclass='pci' " \
b"backend_domain='dom0' required='yes' attach_automatically='yes' " \
b"_no-strict-reset='yes'\n"
test_qapp.expected_calls[('dom0', "admin.vm.device.pci.Available",
None, None)] = \
b"0\x0000_0d.0 function=0 bus=00 libvirt_name=pci_0000_00_0d_0 " \
b"device=0d description=USB controller: Intel Corporation \n"
b"0\x0000_0d.0 ident='00_0d.0' devclass='pci' backend_domain='dom0' " \
b"serial='unknown' manufacturer='unknown' " \
b"self_identity='0000:0000::p0c0300' vendor='unknown' " \
b"product='unknown' name='unknown' interfaces='p0c0300' " \
b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0d_0' " \
b"_device='0d'\n"

handler = DevicesHandler(test_qapp, test_policy_manager, real_builder)

Expand All @@ -870,18 +876,30 @@ def test_devices_handler_unsaved(test_qapp, test_policy_manager, real_builder):

def test_devices_handler_detect_usbvms(test_qapp,
test_policy_manager, real_builder):
test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.List",
test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.Attached",
None, None)] = \
b"0\x00dom0+00_0d.0 no-strict-reset=True persistent=yes\n"
test_qapp.expected_calls[('test-standalone', "admin.vm.device.pci.List",
b"0\x00dom0+00_0d.0 ident='00_0d.0' devclass='pci' " \
b"backend_domain='dom0' required='yes' attach_automatically='yes' " \
b"_no-strict-reset='yes'\n"
test_qapp.expected_calls[('test-standalone', "admin.vm.device.pci.Attached",
None, None)] = \
b"0\x00dom0+00_0f.0 no-strict-reset=True persistent=yes\n"
b"0\x00dom0+00_0f.0 ident='00_0f.0' devclass='pci' " \
b"backend_domain='dom0' required='yes' attach_automatically='yes' " \
b"_no-strict-reset='yes'\n"
test_qapp.expected_calls[('dom0', "admin.vm.device.pci.Available",
None, None)] = \
b"0\x0000_0d.0 function=0 bus=00 libvirt_name=pci_0000_00_0d_0 " \
b"device=0d description=USB controller: Intel Corporation \n" \
b"00_0f.0 function=0 bus=00 libvirt_name=pci_0000_00_0d_0 " \
b"device=0d description=USB controller: Intel Corporation \n"
b"0\x0000_0f.0 ident='00_0f.0' devclass='pci' backend_domain='dom0' " \
b"serial='unknown' manufacturer='unknown' " \
b"self_identity='0000:0000::p0c0300' vendor='unknown' " \
b"product='unknown' name='unknown' interfaces='p0c0300' " \
b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0f_0' " \
b"_device='0f'\n" \
b"00_0d.0 ident='00_0d.0' devclass='pci' backend_domain='dom0' " \
b"serial='unknown' manufacturer='unknown' " \
b"self_identity='0000:0000::p0c0300' vendor='unknown' " \
b"product='unknown' name='unknown' interfaces='p0c0300' " \
b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0d_0' " \
b"_device='0d'\n"

handler = DevicesHandler(test_qapp, test_policy_manager, real_builder)

Expand Down

0 comments on commit 3c031f7

Please sign in to comment.