hardware.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2016 Marek Marczykowski-Górecki
  7. # <marmarek@invisiblethingslab.com>
  8. #
  9. # This library is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU Lesser General Public
  11. # License as published by the Free Software Foundation; either
  12. # version 2.1 of the License, or (at your option) any later version.
  13. #
  14. # This library is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. # Lesser General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Lesser General Public
  20. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  21. #
  22. #
  23. import os
  24. import qubes.tests
  25. import time
  26. import subprocess
  27. from unittest import expectedFailure
  28. class TC_00_HVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  29. def setUp(self):
  30. super(TC_00_HVM, self).setUp()
  31. self.vm = self.qc.add_new_vm("QubesHVm",
  32. name=self.make_vm_name('vm1'))
  33. self.vm.create_on_disk(verbose=False)
  34. @expectedFailure
  35. def test_000_pci_passthrough_presence(self):
  36. pcidev = os.environ.get('QUBES_TEST_PCIDEV', None)
  37. if pcidev is None:
  38. self.skipTest('Specify PCI device with QUBES_TEST_PCIDEV '
  39. 'environment variable')
  40. self.vm.pcidevs = [pcidev]
  41. self.vm.pci_strictreset = False
  42. self.qc.save()
  43. self.qc.unlock_db()
  44. init_script = (
  45. "#!/bin/sh\n"
  46. "set -e\n"
  47. "lspci -n > /dev/xvdb\n"
  48. "poweroff\n"
  49. )
  50. self.prepare_hvm_system_linux(self.vm, init_script,
  51. ['/usr/sbin/lspci'])
  52. self.vm.start()
  53. timeout = 60
  54. while timeout > 0:
  55. if not self.vm.is_running():
  56. break
  57. time.sleep(1)
  58. timeout -= 1
  59. if self.vm.is_running():
  60. self.fail("Timeout while waiting for VM shutdown")
  61. with open(self.vm.storage.private_img, 'r') as f:
  62. lspci_vm = f.read(512).strip('\0')
  63. p = subprocess.Popen(['lspci', '-ns', pcidev], stdout=subprocess.PIPE)
  64. (lspci_host, _) = p.communicate()
  65. # strip BDF, as it is different in VM
  66. pcidev_desc = ' '.join(lspci_host.strip().split(' ')[1:])
  67. self.assertIn(pcidev_desc, lspci_vm)