]> git.proxmox.com Git - mirror_qemu.git/blob - tests/acceptance/boot_linux_console.py
tests/boot_linux_console: add a test for aarch64 + virt
[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 os
12 import logging
13
14 from avocado_qemu import Test
15 from avocado.utils import process
16 from avocado.utils import archive
17
18
19 class BootLinuxConsole(Test):
20 """
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
23 """
24
25 timeout = 90
26
27 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
28
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
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
63 def test_x86_64_pc(self):
64 """
65 :avocado: tags=arch:x86_64
66 :avocado: tags=machine:pc
67 """
68 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
69 'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
70 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
71 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
72
73 self.vm.set_machine('pc')
74 self.vm.set_console()
75 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
76 self.vm.add_args('-kernel', kernel_path,
77 '-append', kernel_command_line)
78 self.vm.launch()
79 console_pattern = 'Kernel command line: %s' % kernel_command_line
80 self.wait_for_console_pattern(console_pattern)
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)
104
105 def test_mips64el_malta(self):
106 """
107 This test requires the ar tool to extract "data.tar.gz" from
108 the Debian package.
109
110 The kernel can be rebuilt using this Debian kernel source [1] and
111 following the instructions on [2].
112
113 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
114 #linux-source-2.6.32_2.6.32-48
115 [2] https://kernel-team.pages.debian.net/kernel-handbook/
116 ch-common-tasks.html#s-common-official
117
118 :avocado: tags=arch:mips64el
119 :avocado: tags=machine:malta
120 """
121 deb_url = ('http://snapshot.debian.org/archive/debian/'
122 '20130217T032700Z/pool/main/l/linux-2.6/'
123 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
124 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
125 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
126 kernel_path = self.extract_from_deb(deb_path,
127 '/boot/vmlinux-2.6.32-5-5kc-malta')
128
129 self.vm.set_machine('malta')
130 self.vm.set_console()
131 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
132 self.vm.add_args('-kernel', kernel_path,
133 '-append', kernel_command_line)
134 self.vm.launch()
135 console_pattern = 'Kernel command line: %s' % kernel_command_line
136 self.wait_for_console_pattern(console_pattern)
137
138 def test_aarch64_virt(self):
139 """
140 :avocado: tags=arch:aarch64
141 :avocado: tags=machine:virt
142 """
143 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
144 'releases/29/Everything/aarch64/os/images/pxeboot/vmlinuz')
145 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
146 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
147
148 self.vm.set_machine('virt')
149 self.vm.set_console()
150 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
151 'console=ttyAMA0')
152 self.vm.add_args('-cpu', 'cortex-a53',
153 '-kernel', kernel_path,
154 '-append', kernel_command_line)
155 self.vm.launch()
156 console_pattern = 'Kernel command line: %s' % kernel_command_line
157 self.wait_for_console_pattern(console_pattern)