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 6import os 7 8from .testcase import QemuSystemTest 9from .cmd import wait_for_console_pattern 10from .archive import deb_extract 11 12 13class LinuxKernelTest(QemuSystemTest): 14 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 15 16 def wait_for_console_pattern(self, success_message, vm=None): 17 wait_for_console_pattern(self, success_message, 18 failure_message='Kernel panic - not syncing', 19 vm=vm) 20 21 def launch_kernel(self, kernel, initrd=None, dtb=None, console_index=0, 22 wait_for=None): 23 self.vm.set_console(console_index=console_index) 24 self.vm.add_args('-kernel', kernel) 25 if initrd: 26 self.vm.add_args('-initrd', initrd) 27 if dtb: 28 self.vm.add_args('-dtb', dtb) 29 self.vm.launch() 30 if wait_for: 31 self.wait_for_console_pattern(wait_for) 32 33 def extract_from_deb(self, deb_path, path): 34 """ 35 Extracts a file from a deb package into the test workdir 36 37 :param deb_path: path to the deb archive 38 :param path: path within the deb archive of the file to be extracted 39 :returns: path of the extracted file 40 """ 41 deb_extract(deb_path, self.workdir, member="." + path) 42 # Return complete path to extracted file. Because callers to 43 # extract_from_deb() specify 'path' with a leading slash, it is 44 # necessary to use os.path.relpath() as otherwise scratch_file() 45 # interprets it as an absolute path and drops the required prefix 46 return os.path.normpath(self.scratch_file(os.path.relpath(path, '/'))) 47 48