]> git.proxmox.com Git - mirror_qemu.git/blob - tests/acceptance/boot_linux_console.py
Merge remote-tracking branch 'remotes/stsquad/tags/pull-gitdm-next-271019-1' 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 import lzma
14 import gzip
15 import shutil
16
17 from avocado_qemu import Test
18 from avocado.utils import process
19 from avocado.utils import archive
20
21
22 class BootLinuxConsole(Test):
23 """
24 Boots a Linux kernel and checks that the console is operational and the
25 kernel command line is properly passed from QEMU to the kernel
26 """
27
28 timeout = 90
29
30 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
31
32 def wait_for_console_pattern(self, success_message,
33 failure_message='Kernel panic - not syncing'):
34 """
35 Waits for messages to appear on the console, while logging the content
36
37 :param success_message: if this message appears, test succeeds
38 :param failure_message: if this message appears, test fails
39 """
40 console = self.vm.console_socket.makefile()
41 console_logger = logging.getLogger('console')
42 while True:
43 msg = console.readline().strip()
44 if not msg:
45 continue
46 console_logger.debug(msg)
47 if success_message in msg:
48 break
49 if failure_message in msg:
50 fail = 'Failure message found in console: %s' % failure_message
51 self.fail(fail)
52
53 def exec_command_and_wait_for_pattern(self, command, success_message):
54 command += '\n'
55 self.vm.console_socket.sendall(command.encode())
56 self.wait_for_console_pattern(success_message)
57
58 def extract_from_deb(self, deb, path):
59 """
60 Extracts a file from a deb package into the test workdir
61
62 :param deb: path to the deb archive
63 :param file: path within the deb archive of the file to be extracted
64 :returns: path of the extracted file
65 """
66 cwd = os.getcwd()
67 os.chdir(self.workdir)
68 file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
69 process.run("ar x %s %s" % (deb, file_path))
70 archive.extract(file_path, self.workdir)
71 os.chdir(cwd)
72 return self.workdir + path
73
74 def test_x86_64_pc(self):
75 """
76 :avocado: tags=arch:x86_64
77 :avocado: tags=machine:pc
78 """
79 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
80 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
81 '/vmlinuz')
82 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
83 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
84
85 self.vm.set_machine('pc')
86 self.vm.set_console()
87 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
88 self.vm.add_args('-kernel', kernel_path,
89 '-append', kernel_command_line)
90 self.vm.launch()
91 console_pattern = 'Kernel command line: %s' % kernel_command_line
92 self.wait_for_console_pattern(console_pattern)
93
94 def test_mips_malta(self):
95 """
96 :avocado: tags=arch:mips
97 :avocado: tags=machine:malta
98 :avocado: tags=endian:big
99 """
100 deb_url = ('http://snapshot.debian.org/archive/debian/'
101 '20130217T032700Z/pool/main/l/linux-2.6/'
102 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
103 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
104 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
105 kernel_path = self.extract_from_deb(deb_path,
106 '/boot/vmlinux-2.6.32-5-4kc-malta')
107
108 self.vm.set_machine('malta')
109 self.vm.set_console()
110 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
111 self.vm.add_args('-kernel', kernel_path,
112 '-append', kernel_command_line)
113 self.vm.launch()
114 console_pattern = 'Kernel command line: %s' % kernel_command_line
115 self.wait_for_console_pattern(console_pattern)
116
117 def test_mips64el_malta(self):
118 """
119 This test requires the ar tool to extract "data.tar.gz" from
120 the Debian package.
121
122 The kernel can be rebuilt using this Debian kernel source [1] and
123 following the instructions on [2].
124
125 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
126 #linux-source-2.6.32_2.6.32-48
127 [2] https://kernel-team.pages.debian.net/kernel-handbook/
128 ch-common-tasks.html#s-common-official
129
130 :avocado: tags=arch:mips64el
131 :avocado: tags=machine:malta
132 """
133 deb_url = ('http://snapshot.debian.org/archive/debian/'
134 '20130217T032700Z/pool/main/l/linux-2.6/'
135 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
136 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
137 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
138 kernel_path = self.extract_from_deb(deb_path,
139 '/boot/vmlinux-2.6.32-5-5kc-malta')
140
141 self.vm.set_machine('malta')
142 self.vm.set_console()
143 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
144 self.vm.add_args('-kernel', kernel_path,
145 '-append', kernel_command_line)
146 self.vm.launch()
147 console_pattern = 'Kernel command line: %s' % kernel_command_line
148 self.wait_for_console_pattern(console_pattern)
149
150 def test_mips_malta_cpio(self):
151 """
152 :avocado: tags=arch:mips
153 :avocado: tags=machine:malta
154 :avocado: tags=endian:big
155 """
156 deb_url = ('http://snapshot.debian.org/archive/debian/'
157 '20160601T041800Z/pool/main/l/linux/'
158 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
159 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
160 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
161 kernel_path = self.extract_from_deb(deb_path,
162 '/boot/vmlinux-4.5.0-2-4kc-malta')
163 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
164 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
165 'mips/rootfs.cpio.gz')
166 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
167 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
168 initrd_path = self.workdir + "rootfs.cpio"
169
170 with gzip.open(initrd_path_gz, 'rb') as f_in:
171 with open(initrd_path, 'wb') as f_out:
172 shutil.copyfileobj(f_in, f_out)
173
174 self.vm.set_machine('malta')
175 self.vm.set_console()
176 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
177 + 'console=ttyS0 console=tty '
178 + 'rdinit=/sbin/init noreboot')
179 self.vm.add_args('-kernel', kernel_path,
180 '-initrd', initrd_path,
181 '-append', kernel_command_line,
182 '-no-reboot')
183 self.vm.launch()
184 self.wait_for_console_pattern('Boot successful.')
185
186 self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
187 'BogoMIPS')
188 self.exec_command_and_wait_for_pattern('uname -a',
189 'Debian')
190 self.exec_command_and_wait_for_pattern('reboot',
191 'reboot: Restarting system')
192
193 def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash):
194 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
195 kernel_path = self.workdir + "kernel"
196 with lzma.open(kernel_path_xz, 'rb') as f_in:
197 with open(kernel_path, 'wb') as f_out:
198 shutil.copyfileobj(f_in, f_out)
199
200 self.vm.set_machine('malta')
201 self.vm.set_console()
202 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
203 + 'mem=256m@@0x0 '
204 + 'console=ttyS0')
205 self.vm.add_args('-no-reboot',
206 '-cpu', 'I7200',
207 '-kernel', kernel_path,
208 '-append', kernel_command_line)
209 self.vm.launch()
210 console_pattern = 'Kernel command line: %s' % kernel_command_line
211 self.wait_for_console_pattern(console_pattern)
212
213 def test_mips_malta32el_nanomips_4k(self):
214 """
215 :avocado: tags=arch:mipsel
216 :avocado: tags=machine:malta
217 :avocado: tags=endian:little
218 """
219 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
220 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
221 'generic_nano32r6el_page4k.xz')
222 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
223 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
224
225 def test_mips_malta32el_nanomips_16k_up(self):
226 """
227 :avocado: tags=arch:mipsel
228 :avocado: tags=machine:malta
229 :avocado: tags=endian:little
230 """
231 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
232 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
233 'generic_nano32r6el_page16k_up.xz')
234 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
235 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
236
237 def test_mips_malta32el_nanomips_64k_dbg(self):
238 """
239 :avocado: tags=arch:mipsel
240 :avocado: tags=machine:malta
241 :avocado: tags=endian:little
242 """
243 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
244 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
245 'generic_nano32r6el_page64k_dbg.xz')
246 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
247 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
248
249 def test_aarch64_virt(self):
250 """
251 :avocado: tags=arch:aarch64
252 :avocado: tags=machine:virt
253 """
254 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
255 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
256 '/vmlinuz')
257 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
258 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
259
260 self.vm.set_machine('virt')
261 self.vm.set_console()
262 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
263 'console=ttyAMA0')
264 self.vm.add_args('-cpu', 'cortex-a53',
265 '-kernel', kernel_path,
266 '-append', kernel_command_line)
267 self.vm.launch()
268 console_pattern = 'Kernel command line: %s' % kernel_command_line
269 self.wait_for_console_pattern(console_pattern)
270
271 def test_arm_virt(self):
272 """
273 :avocado: tags=arch:arm
274 :avocado: tags=machine:virt
275 """
276 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
277 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
278 '/vmlinuz')
279 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
280 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
281
282 self.vm.set_machine('virt')
283 self.vm.set_console()
284 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
285 'console=ttyAMA0')
286 self.vm.add_args('-kernel', kernel_path,
287 '-append', kernel_command_line)
288 self.vm.launch()
289 console_pattern = 'Kernel command line: %s' % kernel_command_line
290 self.wait_for_console_pattern(console_pattern)
291
292 def test_arm_emcraft_sf2(self):
293 """
294 :avocado: tags=arch:arm
295 :avocado: tags=machine:emcraft_sf2
296 :avocado: tags=endian:little
297 """
298 uboot_url = ('https://raw.githubusercontent.com/'
299 'Subbaraya-Sundeep/qemu-test-binaries/'
300 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
301 uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
302 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
303 spi_url = ('https://raw.githubusercontent.com/'
304 'Subbaraya-Sundeep/qemu-test-binaries/'
305 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
306 spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a'
307 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
308
309 self.vm.set_machine('emcraft-sf2')
310 self.vm.set_console()
311 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
312 self.vm.add_args('-kernel', uboot_path,
313 '-append', kernel_command_line,
314 '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
315 '-no-reboot')
316 self.vm.launch()
317 self.wait_for_console_pattern('init started: BusyBox')
318
319 def test_s390x_s390_ccw_virtio(self):
320 """
321 :avocado: tags=arch:s390x
322 :avocado: tags=machine:s390_ccw_virtio
323 """
324 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
325 '/fedora-secondary/releases/29/Everything/s390x/os/images'
326 '/kernel.img')
327 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
328 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
329
330 self.vm.set_machine('s390-ccw-virtio')
331 self.vm.set_console()
332 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
333 self.vm.add_args('-nodefaults',
334 '-kernel', kernel_path,
335 '-append', kernel_command_line)
336 self.vm.launch()
337 console_pattern = 'Kernel command line: %s' % kernel_command_line
338 self.wait_for_console_pattern(console_pattern)
339
340 def test_alpha_clipper(self):
341 """
342 :avocado: tags=arch:alpha
343 :avocado: tags=machine:clipper
344 """
345 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
346 'installer-alpha/current/images/cdrom/vmlinuz')
347 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
348 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
349
350 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
351
352 self.vm.set_machine('clipper')
353 self.vm.set_console()
354 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
355 self.vm.add_args('-vga', 'std',
356 '-kernel', uncompressed_kernel,
357 '-append', kernel_command_line)
358 self.vm.launch()
359 console_pattern = 'Kernel command line: %s' % kernel_command_line
360 self.wait_for_console_pattern(console_pattern)
361
362 def test_ppc64_pseries(self):
363 """
364 :avocado: tags=arch:ppc64
365 :avocado: tags=machine:pseries
366 """
367 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
368 '/fedora-secondary/releases/29/Everything/ppc64le/os'
369 '/ppc/ppc64/vmlinuz')
370 kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
371 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
372
373 self.vm.set_machine('pseries')
374 self.vm.set_console()
375 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
376 self.vm.add_args('-kernel', kernel_path,
377 '-append', kernel_command_line)
378 self.vm.launch()
379 console_pattern = 'Kernel command line: %s' % kernel_command_line
380 self.wait_for_console_pattern(console_pattern)
381
382 def test_m68k_q800(self):
383 """
384 :avocado: tags=arch:m68k
385 :avocado: tags=machine:q800
386 """
387 deb_url = ('http://ftp.ports.debian.org/debian-ports/pool-m68k/main'
388 '/l/linux/kernel-image-5.2.0-2-m68k-di_5.2.9-2_m68k.udeb')
389 deb_hash = '0797e05129595f22f3c0142db5e199769a723bf9'
390 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
391 kernel_path = self.extract_from_deb(deb_path,
392 '/boot/vmlinux-5.2.0-2-m68k')
393
394 self.vm.set_machine('q800')
395 self.vm.set_console()
396 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
397 'console=ttyS0 vga=off')
398 self.vm.add_args('-kernel', kernel_path,
399 '-append', kernel_command_line)
400 self.vm.launch()
401 console_pattern = 'Kernel command line: %s' % kernel_command_line
402 self.wait_for_console_pattern(console_pattern)
403 console_pattern = 'No filesystem could mount root'
404 self.wait_for_console_pattern(console_pattern)