hardware.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. #
  14. # This program 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
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. #
  23. #
  24. import os
  25. import qubes.tests
  26. import time
  27. import subprocess
  28. from unittest import expectedFailure
  29. class TC_00_HVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  30. def setUp(self):
  31. super(TC_00_HVM, self).setUp()
  32. self.vm = self.qc.add_new_vm("QubesHVm",
  33. name=self.make_vm_name('vm1'))
  34. self.vm.create_on_disk(verbose=False)
  35. @expectedFailure
  36. def test_000_pci_passthrough_presence(self):
  37. pcidev = os.environ.get('QUBES_TEST_PCIDEV', None)
  38. if pcidev is None:
  39. self.skipTest('Specify PCI device with QUBES_TEST_PCIDEV '
  40. 'environment variable')
  41. self.vm.pcidevs = [pcidev]
  42. self.vm.pci_strictreset = False
  43. self.qc.save()
  44. self.qc.unlock_db()
  45. init_script = (
  46. "#!/bin/sh\n"
  47. "set -e\n"
  48. "lspci -n > /dev/xvdb\n"
  49. "poweroff\n"
  50. )
  51. self.prepare_hvm_system_linux(self.vm, init_script,
  52. ['/usr/sbin/lspci'])
  53. self.vm.start()
  54. timeout = 60
  55. while timeout > 0:
  56. if not self.vm.is_running():
  57. break
  58. time.sleep(1)
  59. timeout -= 1
  60. if self.vm.is_running():
  61. self.fail("Timeout while waiting for VM shutdown")
  62. with open(self.vm.storage.private_img, 'r') as f:
  63. lspci_vm = f.read(512).strip('\0')
  64. p = subprocess.Popen(['lspci', '-ns', pcidev], stdout=subprocess.PIPE)
  65. (lspci_host, _) = p.communicate()
  66. # strip BDF, as it is different in VM
  67. pcidev_desc = ' '.join(lspci_host.strip().split(' ')[1:])
  68. self.assertIn(pcidev_desc, lspci_vm)