linuxkernel.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Test class for testing the boot process of a Linux kernel
  2. #
  3. # This work is licensed under the terms of the GNU GPL, version 2 or
  4. # later. See the COPYING file in the top-level directory.
  5. import os
  6. from .testcase import QemuSystemTest
  7. from .cmd import run_cmd, wait_for_console_pattern
  8. from .utils import archive_extract
  9. class LinuxKernelTest(QemuSystemTest):
  10. KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
  11. def wait_for_console_pattern(self, success_message, vm=None):
  12. wait_for_console_pattern(self, success_message,
  13. failure_message='Kernel panic - not syncing',
  14. vm=vm)
  15. def launch_kernel(self, kernel, initrd=None, dtb=None, console_index=0,
  16. wait_for=None):
  17. self.vm.set_console(console_index=console_index)
  18. self.vm.add_args('-kernel', kernel)
  19. if initrd:
  20. self.vm.add_args('-initrd', initrd)
  21. if dtb:
  22. self.vm.add_args('-dtb', dtb)
  23. self.vm.launch()
  24. if wait_for:
  25. self.wait_for_console_pattern(wait_for)
  26. def extract_from_deb(self, deb_path, path):
  27. """
  28. Extracts a file from a deb package into the test workdir
  29. :param deb_path: path to the deb archive
  30. :param path: path within the deb archive of the file to be extracted
  31. :returns: path of the extracted file
  32. """
  33. cwd = os.getcwd()
  34. os.chdir(self.workdir)
  35. (stdout, stderr, ret) = run_cmd(['ar', 't', deb_path])
  36. file_path = stdout.split()[2]
  37. run_cmd(['ar', 'x', deb_path, file_path])
  38. archive_extract(file_path, self.workdir)
  39. os.chdir(cwd)
  40. # Return complete path to extracted file. Because callers to
  41. # extract_from_deb() specify 'path' with a leading slash, it is
  42. # necessary to use os.path.relpath() as otherwise os.path.join()
  43. # interprets it as an absolute path and drops the self.workdir part.
  44. return os.path.normpath(os.path.join(self.workdir,
  45. os.path.relpath(path, '/')))