]>
Commit | Line | Data |
---|---|---|
c1cc73f4 CR |
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 | ||
f8792047 | 11 | import os |
c1cc73f4 CR |
12 | import logging |
13 | ||
14 | from avocado_qemu import Test | |
f8792047 PMD |
15 | from avocado.utils import process |
16 | from avocado.utils import archive | |
c1cc73f4 CR |
17 | |
18 | ||
19 | class BootLinuxConsole(Test): | |
20 | """ | |
78664ed8 CR |
21 | Boots a Linux kernel and checks that the console is operational and the |
22 | kernel command line is properly passed from QEMU to the kernel | |
c1cc73f4 CR |
23 | """ |
24 | ||
61f74506 | 25 | timeout = 90 |
c1cc73f4 | 26 | |
b50fcd39 CR |
27 | KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' |
28 | ||
0d1d74e5 CR |
29 | def wait_for_console_pattern(self, success_message, |
30 | failure_message='Kernel panic - not syncing'): | |
31 | """ | |
32 | Waits for messages to appear on the console, while logging the content | |
33 | ||
34 | :param success_message: if this message appears, test succeeds | |
35 | :param failure_message: if this message appears, test fails | |
36 | """ | |
37 | console = self.vm.console_socket.makefile() | |
38 | console_logger = logging.getLogger('console') | |
39 | while True: | |
40 | msg = console.readline() | |
41 | console_logger.debug(msg.strip()) | |
42 | if success_message in msg: | |
43 | break | |
44 | if failure_message in msg: | |
45 | fail = 'Failure message found in console: %s' % failure_message | |
46 | self.fail(fail) | |
47 | ||
f8792047 PMD |
48 | def extract_from_deb(self, deb, path): |
49 | """ | |
50 | Extracts a file from a deb package into the test workdir | |
51 | ||
52 | :param deb: path to the deb archive | |
53 | :param file: path within the deb archive of the file to be extracted | |
54 | :returns: path of the extracted file | |
55 | """ | |
56 | cwd = os.getcwd() | |
57 | os.chdir(self.workdir) | |
58 | process.run("ar x %s data.tar.gz" % deb) | |
59 | archive.extract("data.tar.gz", self.workdir) | |
60 | os.chdir(cwd) | |
61 | return self.workdir + path | |
62 | ||
78664ed8 CR |
63 | def test_x86_64_pc(self): |
64 | """ | |
65 | :avocado: tags=arch:x86_64 | |
66 | :avocado: tags=machine:pc | |
67 | """ | |
7d7985b1 CR |
68 | kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/' |
69 | 'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz') | |
70 | kernel_hash = '23bebd2680757891cf7adedb033532163a792495' | |
c1cc73f4 CR |
71 | kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) |
72 | ||
73 | self.vm.set_machine('pc') | |
74 | self.vm.set_console() | |
b50fcd39 | 75 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' |
c1cc73f4 CR |
76 | self.vm.add_args('-kernel', kernel_path, |
77 | '-append', kernel_command_line) | |
78 | self.vm.launch() | |
0d1d74e5 CR |
79 | console_pattern = 'Kernel command line: %s' % kernel_command_line |
80 | self.wait_for_console_pattern(console_pattern) | |
f8792047 PMD |
81 | |
82 | def test_mips_malta(self): | |
83 | """ | |
84 | :avocado: tags=arch:mips | |
85 | :avocado: tags=machine:malta | |
86 | :avocado: tags=endian:big | |
87 | """ | |
88 | deb_url = ('http://snapshot.debian.org/archive/debian/' | |
89 | '20130217T032700Z/pool/main/l/linux-2.6/' | |
90 | 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb') | |
91 | deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04' | |
92 | deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash) | |
93 | kernel_path = self.extract_from_deb(deb_path, | |
94 | '/boot/vmlinux-2.6.32-5-4kc-malta') | |
95 | ||
96 | self.vm.set_machine('malta') | |
97 | self.vm.set_console() | |
98 | kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' | |
99 | self.vm.add_args('-kernel', kernel_path, | |
100 | '-append', kernel_command_line) | |
101 | self.vm.launch() | |
102 | console_pattern = 'Kernel command line: %s' % kernel_command_line | |
103 | self.wait_for_console_pattern(console_pattern) |