boot_linux_console.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Functional test that boots a Linux kernel and checks the console
  2. #
  3. # Copyright (c) 2018 Red Hat, Inc.
  4. #
  5. # Author:
  6. # Cleber Rosa <crosa@redhat.com>
  7. #
  8. # This work is licensed under the terms of the GNU GPL, version 2 or
  9. # later. See the COPYING file in the top-level directory.
  10. import os
  11. import lzma
  12. import gzip
  13. import shutil
  14. from avocado import skip
  15. from avocado import skipUnless
  16. from avocado import skipUnless
  17. from avocado_qemu import QemuSystemTest
  18. from avocado_qemu import exec_command
  19. from avocado_qemu import exec_command_and_wait_for_pattern
  20. from avocado_qemu import interrupt_interactive_console_until_pattern
  21. from avocado_qemu import wait_for_console_pattern
  22. from avocado.utils import process
  23. from avocado.utils import archive
  24. class LinuxKernelTest(QemuSystemTest):
  25. KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
  26. def wait_for_console_pattern(self, success_message, vm=None):
  27. wait_for_console_pattern(self, success_message,
  28. failure_message='Kernel panic - not syncing',
  29. vm=vm)
  30. def extract_from_deb(self, deb, path):
  31. """
  32. Extracts a file from a deb package into the test workdir
  33. :param deb: path to the deb archive
  34. :param path: path within the deb archive of the file to be extracted
  35. :returns: path of the extracted file
  36. """
  37. cwd = os.getcwd()
  38. os.chdir(self.workdir)
  39. file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
  40. process.run("ar x %s %s" % (deb, file_path))
  41. archive.extract(file_path, self.workdir)
  42. os.chdir(cwd)
  43. # Return complete path to extracted file. Because callers to
  44. # extract_from_deb() specify 'path' with a leading slash, it is
  45. # necessary to use os.path.relpath() as otherwise os.path.join()
  46. # interprets it as an absolute path and drops the self.workdir part.
  47. return os.path.normpath(os.path.join(self.workdir,
  48. os.path.relpath(path, '/')))
  49. def extract_from_rpm(self, rpm, path):
  50. """
  51. Extracts a file from an RPM package into the test workdir.
  52. :param rpm: path to the rpm archive
  53. :param path: path within the rpm archive of the file to be extracted
  54. needs to be a relative path (starting with './') because
  55. cpio(1), which is used to extract the file, expects that.
  56. :returns: path of the extracted file
  57. """
  58. cwd = os.getcwd()
  59. os.chdir(self.workdir)
  60. process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True)
  61. os.chdir(cwd)
  62. return os.path.normpath(os.path.join(self.workdir, path))
  63. class BootLinuxConsole(LinuxKernelTest):
  64. """
  65. Boots a Linux kernel and checks that the console is operational and the
  66. kernel command line is properly passed from QEMU to the kernel
  67. """
  68. timeout = 90
  69. def test_x86_64_pc(self):
  70. """
  71. :avocado: tags=arch:x86_64
  72. :avocado: tags=machine:pc
  73. """
  74. kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
  75. '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
  76. '/vmlinuz')
  77. kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
  78. kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
  79. self.vm.set_console()
  80. kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
  81. self.vm.add_args('-kernel', kernel_path,
  82. '-append', kernel_command_line)
  83. self.vm.launch()
  84. console_pattern = 'Kernel command line: %s' % kernel_command_line
  85. self.wait_for_console_pattern(console_pattern)