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