Skip to content

Commit b249cc2

Browse files
committed
tests: check device on 1000 PCI domain
QubesOS/qubes-issues#6932
1 parent 3384d98 commit b249cc2

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

qubes/tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
14751475
"qubes.tests.events",
14761476
"qubes.tests.devices",
14771477
"qubes.tests.devices_block",
1478+
"qubes.tests.devices_pci",
14781479
"qubes.tests.firewall",
14791480
"qubes.tests.init",
14801481
"qubes.tests.vm.init",

qubes/tests/devices_pci.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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")

rpm_spec/core-dom0.spec.in

+1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ done
455455
%{python3_sitelib}/qubes/tests/app.py
456456
%{python3_sitelib}/qubes/tests/devices.py
457457
%{python3_sitelib}/qubes/tests/devices_block.py
458+
%{python3_sitelib}/qubes/tests/devices_pci.py
458459
%{python3_sitelib}/qubes/tests/events.py
459460
%{python3_sitelib}/qubes/tests/ext.py
460461
%{python3_sitelib}/qubes/tests/firewall.py

0 commit comments

Comments
 (0)