|
| 1 | +# -*- encoding: utf8 -*- |
| 2 | +# |
| 3 | +# The Qubes OS Project, http://www.qubes-os.org |
| 4 | +# |
| 5 | +# Copyright (C) 2023 Marek Marczykowski-Górecki |
| 6 | + |
| 7 | +# |
| 8 | +# This library is free software; you can redistribute it and/or |
| 9 | +# modify it under the terms of the GNU Lesser General Public |
| 10 | +# License as published by the Free Software Foundation; either |
| 11 | +# version 2.1 of the License, or (at your option) any later version. |
| 12 | +# |
| 13 | +# This library is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | +# Lesser General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU Lesser General Public |
| 19 | +# License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 20 | + |
| 21 | +from unittest import mock |
| 22 | + |
| 23 | +import jinja2 |
| 24 | + |
| 25 | +import qubes.tests |
| 26 | +import qubes.ext.pci |
| 27 | + |
| 28 | + |
| 29 | +class TestVM(object): |
| 30 | + def __init__(self, running=True, name='dom0', qid=0): |
| 31 | + self.name = name |
| 32 | + self.qid = qid |
| 33 | + self.is_running = lambda: running |
| 34 | + self.log = mock.Mock() |
| 35 | + self.app = mock.Mock() |
| 36 | + |
| 37 | + def __eq__(self, other): |
| 38 | + if isinstance(other, TestVM): |
| 39 | + return self.name == other.name |
| 40 | + |
| 41 | +class TC_00_Block(qubes.tests.QubesTestCase): |
| 42 | + def setUp(self): |
| 43 | + super().setUp() |
| 44 | + self.ext = qubes.ext.pci.PCIDeviceExtension() |
| 45 | + |
| 46 | + def test_000_unsupported_device(self): |
| 47 | + vm = TestVM() |
| 48 | + vm.app.configure_mock(**{ |
| 49 | + 'vmm.libvirt_conn.listAllDevices.return_value': |
| 50 | + [mock.Mock(**{"XMLDesc.return_value": """<device> |
| 51 | + <name>pci_0000_00_14_0</name> |
| 52 | + <path>/sys/devices/pci0000:00/0000:00:14.0</path> |
| 53 | + <parent>computer</parent> |
| 54 | + <driver> |
| 55 | + <name>pciback</name> |
| 56 | + </driver> |
| 57 | + <capability type='pci'> |
| 58 | + <class>0x0c0330</class> |
| 59 | + <domain>0</domain> |
| 60 | + <bus>0</bus> |
| 61 | + <slot>20</slot> |
| 62 | + <function>0</function> |
| 63 | + <product id='0x8cb1'>9 Series Chipset Family USB xHCI Controller</product> |
| 64 | + <vendor id='0x8086'>Intel Corporation</vendor> |
| 65 | + </capability> |
| 66 | +</device> |
| 67 | +""", |
| 68 | + "listCaps.return_value": ["pci"] |
| 69 | + }), |
| 70 | + mock.Mock(**{"XMLDesc.return_value": """<device> |
| 71 | + <name>pci_1000_00_14_0</name> |
| 72 | + <path>/sys/devices/pci1000:00/1000:00:14.0</path> |
| 73 | + <parent>computer</parent> |
| 74 | + <driver> |
| 75 | + <name>pciback</name> |
| 76 | + </driver> |
| 77 | + <capability type='pci'> |
| 78 | + <class>0x0c0330</class> |
| 79 | + <domain>0</domain> |
| 80 | + <bus>0</bus> |
| 81 | + <slot>20</slot> |
| 82 | + <function>0</function> |
| 83 | + <product id='0x8cb1'>9 Series Chipset Family USB xHCI Controller</product> |
| 84 | + <vendor id='0x8086'>Intel Corporation</vendor> |
| 85 | + </capability> |
| 86 | +</device> |
| 87 | +""", |
| 88 | + "listCaps.return_value": ["pci"] |
| 89 | + }), |
| 90 | + ] |
| 91 | + }) |
| 92 | + devices = list(self.ext.on_device_list_pci(vm, 'device-list:pci')) |
| 93 | + self.assertEqual(len(devices), 1) |
| 94 | + self.assertEqual(devices[0].ident, "00_14.0") |
0 commit comments