]> git.proxmox.com Git - mirror_qemu.git/blob - tests/acceptance/boot_linux_console.py
Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into...
[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)
158
159 def test_arm_virt(self):
160 """
161 :avocado: tags=arch:arm
162 :avocado: tags=machine:virt
163 """
164 kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
165 'releases/29/Everything/armhfp/os/images/pxeboot/vmlinuz')
166 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
167 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
168
169 self.vm.set_machine('virt')
170 self.vm.set_console()
171 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
172 'console=ttyAMA0')
173 self.vm.add_args('-kernel', kernel_path,
174 '-append', kernel_command_line)
175 self.vm.launch()
176 console_pattern = 'Kernel command line: %s' % kernel_command_line
177 self.wait_for_console_pattern(console_pattern)
178
179 def test_s390x_s390_ccw_virtio(self):
180 """
181 :avocado: tags=arch:s390x
182 :avocado: tags=machine:s390_ccw_virtio
183 """
184 kernel_url = ('https://download.fedoraproject.org/pub/fedora-secondary/'
185 'releases/29/Everything/s390x/os/images/kernel.img')
186 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
187 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
188
189 self.vm.set_machine('s390-ccw-virtio')
190 self.vm.set_console()
191 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
192 self.vm.add_args('-nodefaults',
193 '-kernel', kernel_path,
194 '-append', kernel_command_line)
195 self.vm.launch()
196 console_pattern = 'Kernel command line: %s' % kernel_command_line
197 self.wait_for_console_pattern(console_pattern)
198
199 def test_alpha_clipper(self):
200 """
201 :avocado: tags=arch:alpha
202 :avocado: tags=machine:clipper
203 """
204 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
205 'installer-alpha/current/images/cdrom/vmlinuz')
206 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
207 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
208
209 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
210
211 self.vm.set_machine('clipper')
212 self.vm.set_console()
213 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
214 self.vm.add_args('-vga', 'std',
215 '-kernel', uncompressed_kernel,
216 '-append', kernel_command_line)
217 self.vm.launch()
218 console_pattern = 'Kernel command line: %s' % kernel_command_line
219 self.wait_for_console_pattern(console_pattern)