]> git.proxmox.com Git - mirror_qemu.git/blob - tests/acceptance/boot_linux_console.py
tests/boot_linux_console: refactor the console watcher into utility method
[mirror_qemu.git] / tests / acceptance / boot_linux_console.py
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
11 import logging
12
13 from avocado_qemu import Test
14
15
16 class BootLinuxConsole(Test):
17 """
18 Boots a Linux kernel and checks that the console is operational and the
19 kernel command line is properly passed from QEMU to the kernel
20 """
21
22 timeout = 90
23
24 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
25
26 def wait_for_console_pattern(self, success_message,
27 failure_message='Kernel panic - not syncing'):
28 """
29 Waits for messages to appear on the console, while logging the content
30
31 :param success_message: if this message appears, test succeeds
32 :param failure_message: if this message appears, test fails
33 """
34 console = self.vm.console_socket.makefile()
35 console_logger = logging.getLogger('console')
36 while True:
37 msg = console.readline()
38 console_logger.debug(msg.strip())
39 if success_message in msg:
40 break
41 if failure_message in msg:
42 fail = 'Failure message found in console: %s' % failure_message
43 self.fail(fail)
44
45 def test_x86_64_pc(self):
46 """
47 :avocado: tags=arch:x86_64
48 :avocado: tags=machine:pc
49 """
50 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
51 'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
52 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
53 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
54
55 self.vm.set_machine('pc')
56 self.vm.set_console()
57 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
58 self.vm.add_args('-kernel', kernel_path,
59 '-append', kernel_command_line)
60 self.vm.launch()
61 console_pattern = 'Kernel command line: %s' % kernel_command_line
62 self.wait_for_console_pattern(console_pattern)