Sfoglia il codice sorgente

tests: PCI passthrough to HVM

A simple test which checks if the device is visible there at all.
Device set with QUBES_TEST_PCIDEV env variable is used - it should be
some unimportant device which can be freely detached from dom0.

QubesOS/qubes-issues#1659
Marek Marczykowski-Górecki 8 anni fa
parent
commit
3bef37f881
3 ha cambiato i file con 78 aggiunte e 1 eliminazioni
  1. 2 0
      tests/Makefile
  2. 1 0
      tests/__init__.py
  3. 75 1
      tests/hardware.py

+ 2 - 0
tests/Makefile

@@ -31,3 +31,5 @@ endif
 	cp storage.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)
 	cp storage_xen.py $(DESTDIR)$(PYTHON_TESTSPATH)
 	cp storage_xen.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)
+	cp hardware.py $(DESTDIR)$(PYTHON_TESTSPATH)
+	cp hardware.py[co] $(DESTDIR)$(PYTHON_TESTSPATH)

+ 1 - 0
tests/__init__.py

@@ -696,6 +696,7 @@ def load_tests(loader, tests, pattern):
             'qubes.tests.regressions',
             'qubes.tests.storage',
             'qubes.tests.storage_xen',
+            'qubes.tests.hardware',
             ):
         tests.addTests(loader.loadTestsFromName(modname))
 

+ 75 - 1
tests/hardware.py

@@ -1 +1,75 @@
-__author__ = 'user'
+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
+#
+# The Qubes OS Project, http://www.qubes-os.org
+#
+# Copyright (C) 2016  Marek Marczykowski-Górecki
+#                                        <marmarek@invisiblethingslab.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+#
+import os
+
+import qubes.tests
+import time
+import subprocess
+from unittest import expectedFailure
+
+
+class TC_00_HVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
+    def setUp(self):
+        super(TC_00_HVM, self).setUp()
+        self.vm = self.qc.add_new_vm("QubesHVm",
+            name=self.make_vm_name('vm1'))
+        self.vm.create_on_disk(verbose=False)
+
+    @expectedFailure
+    def test_000_pci_passthrough_presence(self):
+        pcidev = os.environ.get('QUBES_TEST_PCIDEV', None)
+        if pcidev is None:
+            self.skipTest('Specify PCI device with QUBES_TEST_PCIDEV '
+                          'environment variable')
+        self.vm.pcidevs = [pcidev]
+        self.vm.pci_strictreset = False
+        self.qc.save()
+        self.qc.unlock_db()
+
+        init_script = (
+            "#!/bin/sh\n"
+            "set -e\n"
+            "lspci -n > /dev/xvdb\n"
+            "poweroff\n"
+        )
+
+        self.prepare_hvm_system_linux(self.vm, init_script,
+            ['/usr/sbin/lspci'])
+        self.vm.start()
+        timeout = 60
+        while timeout > 0:
+            if not self.vm.is_running():
+                break
+            time.sleep(1)
+            timeout -= 1
+        if self.vm.is_running():
+            self.fail("Timeout while waiting for VM shutdown")
+
+        with open(self.vm.storage.private_img, 'r') as f:
+            lspci_vm = f.read(512).strip('\0')
+        p = subprocess.Popen(['lspci', '-ns', pcidev], stdout=subprocess.PIPE)
+        (lspci_host, _) = p.communicate()
+        # strip BDF, as it is different in VM
+        pcidev_desc = ' '.join(lspci_host.strip().split(' ')[1:])
+        self.assertIn(pcidev_desc, lspci_vm)