s390x/cpumodel: Fix feature property error API violations
[qemu/ar7.git] / tests / acceptance / boot_linux_console.py
blob7e41cebd47df096fe9407ad087a1916744c0b6a0
1 # Functional test that boots a Linux kernel and checks the console
3 # Copyright (c) 2018 Red Hat, Inc.
5 # Author:
6 # Cleber Rosa <crosa@redhat.com>
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.
11 import os
12 import lzma
13 import gzip
14 import shutil
16 from avocado import skipUnless
17 from avocado_qemu import Test
18 from avocado_qemu import exec_command_and_wait_for_pattern
19 from avocado_qemu import wait_for_console_pattern
20 from avocado.utils import process
21 from avocado.utils import archive
24 class BootLinuxConsole(Test):
25 """
26 Boots a Linux kernel and checks that the console is operational and the
27 kernel command line is properly passed from QEMU to the kernel
28 """
30 timeout = 90
32 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
34 def wait_for_console_pattern(self, success_message):
35 wait_for_console_pattern(self, success_message,
36 failure_message='Kernel panic - not syncing')
38 def extract_from_deb(self, deb, path):
39 """
40 Extracts a file from a deb package into the test workdir
42 :param deb: path to the deb archive
43 :param file: path within the deb archive of the file to be extracted
44 :returns: path of the extracted file
45 """
46 cwd = os.getcwd()
47 os.chdir(self.workdir)
48 file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
49 process.run("ar x %s %s" % (deb, file_path))
50 archive.extract(file_path, self.workdir)
51 os.chdir(cwd)
52 return self.workdir + path
54 def test_x86_64_pc(self):
55 """
56 :avocado: tags=arch:x86_64
57 :avocado: tags=machine:pc
58 """
59 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
60 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
61 '/vmlinuz')
62 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
63 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
65 self.vm.set_machine('pc')
66 self.vm.set_console()
67 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
68 self.vm.add_args('-kernel', kernel_path,
69 '-append', kernel_command_line)
70 self.vm.launch()
71 console_pattern = 'Kernel command line: %s' % kernel_command_line
72 self.wait_for_console_pattern(console_pattern)
74 def test_mips_malta(self):
75 """
76 :avocado: tags=arch:mips
77 :avocado: tags=machine:malta
78 :avocado: tags=endian:big
79 """
80 deb_url = ('http://snapshot.debian.org/archive/debian/'
81 '20130217T032700Z/pool/main/l/linux-2.6/'
82 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
83 deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
84 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
85 kernel_path = self.extract_from_deb(deb_path,
86 '/boot/vmlinux-2.6.32-5-4kc-malta')
88 self.vm.set_machine('malta')
89 self.vm.set_console()
90 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
91 self.vm.add_args('-kernel', kernel_path,
92 '-append', kernel_command_line)
93 self.vm.launch()
94 console_pattern = 'Kernel command line: %s' % kernel_command_line
95 self.wait_for_console_pattern(console_pattern)
97 def test_mips64el_malta(self):
98 """
99 This test requires the ar tool to extract "data.tar.gz" from
100 the Debian package.
102 The kernel can be rebuilt using this Debian kernel source [1] and
103 following the instructions on [2].
105 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
106 #linux-source-2.6.32_2.6.32-48
107 [2] https://kernel-team.pages.debian.net/kernel-handbook/
108 ch-common-tasks.html#s-common-official
110 :avocado: tags=arch:mips64el
111 :avocado: tags=machine:malta
113 deb_url = ('http://snapshot.debian.org/archive/debian/'
114 '20130217T032700Z/pool/main/l/linux-2.6/'
115 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
116 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
117 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
118 kernel_path = self.extract_from_deb(deb_path,
119 '/boot/vmlinux-2.6.32-5-5kc-malta')
121 self.vm.set_machine('malta')
122 self.vm.set_console()
123 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
124 self.vm.add_args('-kernel', kernel_path,
125 '-append', kernel_command_line)
126 self.vm.launch()
127 console_pattern = 'Kernel command line: %s' % kernel_command_line
128 self.wait_for_console_pattern(console_pattern)
130 def test_mips_malta_cpio(self):
132 :avocado: tags=arch:mips
133 :avocado: tags=machine:malta
134 :avocado: tags=endian:big
136 deb_url = ('http://snapshot.debian.org/archive/debian/'
137 '20160601T041800Z/pool/main/l/linux/'
138 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
139 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
140 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
141 kernel_path = self.extract_from_deb(deb_path,
142 '/boot/vmlinux-4.5.0-2-4kc-malta')
143 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
144 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
145 'mips/rootfs.cpio.gz')
146 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
147 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
148 initrd_path = self.workdir + "rootfs.cpio"
149 archive.gzip_uncompress(initrd_path_gz, initrd_path)
151 self.vm.set_machine('malta')
152 self.vm.set_console()
153 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
154 + 'console=ttyS0 console=tty '
155 + 'rdinit=/sbin/init noreboot')
156 self.vm.add_args('-kernel', kernel_path,
157 '-initrd', initrd_path,
158 '-append', kernel_command_line,
159 '-no-reboot')
160 self.vm.launch()
161 self.wait_for_console_pattern('Boot successful.')
163 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
164 'BogoMIPS')
165 exec_command_and_wait_for_pattern(self, 'uname -a',
166 'Debian')
167 exec_command_and_wait_for_pattern(self, 'reboot',
168 'reboot: Restarting system')
170 @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
171 def test_mips64el_malta_5KEc_cpio(self):
173 :avocado: tags=arch:mips64el
174 :avocado: tags=machine:malta
175 :avocado: tags=endian:little
177 kernel_url = ('https://github.com/philmd/qemu-testing-blob/'
178 'raw/9ad2df38/mips/malta/mips64el/'
179 'vmlinux-3.19.3.mtoman.20150408')
180 kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754'
181 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
182 initrd_url = ('https://github.com/groeck/linux-build-test/'
183 'raw/8584a59e/rootfs/'
184 'mipsel64/rootfs.mipsel64r1.cpio.gz')
185 initrd_hash = '1dbb8a396e916847325284dbe2151167'
186 initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5',
187 asset_hash=initrd_hash)
188 initrd_path = self.workdir + "rootfs.cpio"
189 archive.gzip_uncompress(initrd_path_gz, initrd_path)
191 self.vm.set_machine('malta')
192 self.vm.set_console()
193 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
194 + 'console=ttyS0 console=tty '
195 + 'rdinit=/sbin/init noreboot')
196 self.vm.add_args('-cpu', '5KEc',
197 '-kernel', kernel_path,
198 '-initrd', initrd_path,
199 '-append', kernel_command_line,
200 '-no-reboot')
201 self.vm.launch()
202 wait_for_console_pattern(self, 'Boot successful.')
204 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
205 'MIPS 5KE')
206 exec_command_and_wait_for_pattern(self, 'uname -a',
207 '3.19.3.mtoman.20150408')
208 exec_command_and_wait_for_pattern(self, 'reboot',
209 'reboot: Restarting system')
211 def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash):
212 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
213 kernel_path = self.workdir + "kernel"
214 with lzma.open(kernel_path_xz, 'rb') as f_in:
215 with open(kernel_path, 'wb') as f_out:
216 shutil.copyfileobj(f_in, f_out)
218 self.vm.set_machine('malta')
219 self.vm.set_console()
220 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
221 + 'mem=256m@@0x0 '
222 + 'console=ttyS0')
223 self.vm.add_args('-no-reboot',
224 '-cpu', 'I7200',
225 '-kernel', kernel_path,
226 '-append', kernel_command_line)
227 self.vm.launch()
228 console_pattern = 'Kernel command line: %s' % kernel_command_line
229 self.wait_for_console_pattern(console_pattern)
231 def test_mips_malta32el_nanomips_4k(self):
233 :avocado: tags=arch:mipsel
234 :avocado: tags=machine:malta
235 :avocado: tags=endian:little
237 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
238 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
239 'generic_nano32r6el_page4k.xz')
240 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
241 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
243 def test_mips_malta32el_nanomips_16k_up(self):
245 :avocado: tags=arch:mipsel
246 :avocado: tags=machine:malta
247 :avocado: tags=endian:little
249 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
250 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
251 'generic_nano32r6el_page16k_up.xz')
252 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
253 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
255 def test_mips_malta32el_nanomips_64k_dbg(self):
257 :avocado: tags=arch:mipsel
258 :avocado: tags=machine:malta
259 :avocado: tags=endian:little
261 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
262 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
263 'generic_nano32r6el_page64k_dbg.xz')
264 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
265 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
267 def test_aarch64_virt(self):
269 :avocado: tags=arch:aarch64
270 :avocado: tags=machine:virt
272 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
273 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
274 '/vmlinuz')
275 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
276 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
278 self.vm.set_machine('virt')
279 self.vm.set_console()
280 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
281 'console=ttyAMA0')
282 self.vm.add_args('-cpu', 'cortex-a53',
283 '-kernel', kernel_path,
284 '-append', kernel_command_line)
285 self.vm.launch()
286 console_pattern = 'Kernel command line: %s' % kernel_command_line
287 self.wait_for_console_pattern(console_pattern)
289 def test_arm_virt(self):
291 :avocado: tags=arch:arm
292 :avocado: tags=machine:virt
294 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
295 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
296 '/vmlinuz')
297 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
298 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
300 self.vm.set_machine('virt')
301 self.vm.set_console()
302 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
303 'console=ttyAMA0')
304 self.vm.add_args('-kernel', kernel_path,
305 '-append', kernel_command_line)
306 self.vm.launch()
307 console_pattern = 'Kernel command line: %s' % kernel_command_line
308 self.wait_for_console_pattern(console_pattern)
310 def test_arm_emcraft_sf2(self):
312 :avocado: tags=arch:arm
313 :avocado: tags=machine:emcraft_sf2
314 :avocado: tags=endian:little
316 uboot_url = ('https://raw.githubusercontent.com/'
317 'Subbaraya-Sundeep/qemu-test-binaries/'
318 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
319 uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
320 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
321 spi_url = ('https://raw.githubusercontent.com/'
322 'Subbaraya-Sundeep/qemu-test-binaries/'
323 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
324 spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a'
325 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
327 self.vm.set_machine('emcraft-sf2')
328 self.vm.set_console()
329 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
330 self.vm.add_args('-kernel', uboot_path,
331 '-append', kernel_command_line,
332 '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
333 '-no-reboot')
334 self.vm.launch()
335 self.wait_for_console_pattern('init started: BusyBox')
337 def do_test_arm_raspi2(self, uart_id):
339 The kernel can be rebuilt using the kernel source referenced
340 and following the instructions on the on:
341 https://www.raspberrypi.org/documentation/linux/kernel/building.md
343 serial_kernel_cmdline = {
344 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
346 deb_url = ('http://archive.raspberrypi.org/debian/'
347 'pool/main/r/raspberrypi-firmware/'
348 'raspberrypi-kernel_1.20190215-1_armhf.deb')
349 deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
350 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
351 kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
352 dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
354 self.vm.set_machine('raspi2')
355 self.vm.set_console()
356 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
357 serial_kernel_cmdline[uart_id])
358 self.vm.add_args('-kernel', kernel_path,
359 '-dtb', dtb_path,
360 '-append', kernel_command_line)
361 self.vm.launch()
362 console_pattern = 'Kernel command line: %s' % kernel_command_line
363 self.wait_for_console_pattern(console_pattern)
365 def test_arm_raspi2_uart0(self):
367 :avocado: tags=arch:arm
368 :avocado: tags=machine:raspi2
369 :avocado: tags=device:pl011
371 self.do_test_arm_raspi2(0)
373 def test_arm_exynos4210_initrd(self):
375 :avocado: tags=arch:arm
376 :avocado: tags=machine:smdkc210
378 deb_url = ('https://snapshot.debian.org/archive/debian/'
379 '20190928T224601Z/pool/main/l/linux/'
380 'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb')
381 deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82'
382 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
383 kernel_path = self.extract_from_deb(deb_path,
384 '/boot/vmlinuz-4.19.0-6-armmp')
385 dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb'
386 dtb_path = self.extract_from_deb(deb_path, dtb_path)
388 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
389 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
390 'arm/rootfs-armv5.cpio.gz')
391 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
392 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
393 initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
394 archive.gzip_uncompress(initrd_path_gz, initrd_path)
396 self.vm.set_machine('smdkc210')
397 self.vm.set_console()
398 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
399 'earlycon=exynos4210,0x13800000 earlyprintk ' +
400 'console=ttySAC0,115200n8 ' +
401 'random.trust_cpu=off cryptomgr.notests ' +
402 'cpuidle.off=1 panic=-1 noreboot')
404 self.vm.add_args('-kernel', kernel_path,
405 '-dtb', dtb_path,
406 '-initrd', initrd_path,
407 '-append', kernel_command_line,
408 '-no-reboot')
409 self.vm.launch()
411 self.wait_for_console_pattern('Boot successful.')
412 # TODO user command, for now the uart is stuck
414 def test_s390x_s390_ccw_virtio(self):
416 :avocado: tags=arch:s390x
417 :avocado: tags=machine:s390_ccw_virtio
419 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
420 '/fedora-secondary/releases/29/Everything/s390x/os/images'
421 '/kernel.img')
422 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
423 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
425 self.vm.set_machine('s390-ccw-virtio')
426 self.vm.set_console()
427 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
428 self.vm.add_args('-nodefaults',
429 '-kernel', kernel_path,
430 '-append', kernel_command_line)
431 self.vm.launch()
432 console_pattern = 'Kernel command line: %s' % kernel_command_line
433 self.wait_for_console_pattern(console_pattern)
435 def test_alpha_clipper(self):
437 :avocado: tags=arch:alpha
438 :avocado: tags=machine:clipper
440 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
441 'installer-alpha/current/images/cdrom/vmlinuz')
442 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
443 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
445 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
447 self.vm.set_machine('clipper')
448 self.vm.set_console()
449 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
450 self.vm.add_args('-vga', 'std',
451 '-kernel', uncompressed_kernel,
452 '-append', kernel_command_line)
453 self.vm.launch()
454 console_pattern = 'Kernel command line: %s' % kernel_command_line
455 self.wait_for_console_pattern(console_pattern)
457 def test_ppc64_pseries(self):
459 :avocado: tags=arch:ppc64
460 :avocado: tags=machine:pseries
462 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
463 '/fedora-secondary/releases/29/Everything/ppc64le/os'
464 '/ppc/ppc64/vmlinuz')
465 kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
466 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
468 self.vm.set_machine('pseries')
469 self.vm.set_console()
470 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
471 self.vm.add_args('-kernel', kernel_path,
472 '-append', kernel_command_line)
473 self.vm.launch()
474 console_pattern = 'Kernel command line: %s' % kernel_command_line
475 self.wait_for_console_pattern(console_pattern)
477 def test_m68k_q800(self):
479 :avocado: tags=arch:m68k
480 :avocado: tags=machine:q800
482 deb_url = ('http://ftp.ports.debian.org/debian-ports/pool-m68k/main'
483 '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
484 deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
485 try:
486 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
487 except OSError as exp:
488 self.cancel(exp)
489 kernel_path = self.extract_from_deb(deb_path,
490 '/boot/vmlinux-5.3.0-1-m68k')
492 self.vm.set_machine('q800')
493 self.vm.set_console()
494 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
495 'console=ttyS0 vga=off')
496 self.vm.add_args('-kernel', kernel_path,
497 '-append', kernel_command_line)
498 self.vm.launch()
499 console_pattern = 'Kernel command line: %s' % kernel_command_line
500 self.wait_for_console_pattern(console_pattern)
501 console_pattern = 'No filesystem could mount root'
502 self.wait_for_console_pattern(console_pattern)