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