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 run_cmd, wait_for_console_pattern
10from .utils import archive_extract
11
12class LinuxKernelTest(QemuSystemTest):
13    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
14
15    def wait_for_console_pattern(self, success_message, vm=None):
16        wait_for_console_pattern(self, success_message,
17                                 failure_message='Kernel panic - not syncing',
18                                 vm=vm)
19
20    def extract_from_deb(self, deb_path, path):
21        """
22        Extracts a file from a deb package into the test workdir
23
24        :param deb_path: path to the deb archive
25        :param path: path within the deb archive of the file to be extracted
26        :returns: path of the extracted file
27        """
28        cwd = os.getcwd()
29        os.chdir(self.workdir)
30        (stdout, stderr, ret) = run_cmd(['ar', 't', deb_path])
31        file_path = stdout.split()[2]
32        run_cmd(['ar', 'x', deb_path, file_path])
33        archive_extract(file_path, self.workdir)
34        os.chdir(cwd)
35        # Return complete path to extracted file.  Because callers to
36        # extract_from_deb() specify 'path' with a leading slash, it is
37        # necessary to use os.path.relpath() as otherwise os.path.join()
38        # interprets it as an absolute path and drops the self.workdir part.
39        return os.path.normpath(os.path.join(self.workdir,
40                                             os.path.relpath(path, '/')))
41
42