1 # Functional test that boots a Linux kernel and checks the console
3 # Copyright (c) 2018 Red Hat, Inc.
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.
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
):
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
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
):
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
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
)
52 return self
.workdir
+ path
54 def test_x86_64_pc(self
):
56 :avocado: tags=arch:x86_64
57 :avocado: tags=machine:pc
59 kernel_url
= ('https://archives.fedoraproject.org/pub/archive/fedora'
60 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
62 kernel_hash
= '23bebd2680757891cf7adedb033532163a792495'
63 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
66 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
67 self
.vm
.add_args('-kernel', kernel_path
,
68 '-append', kernel_command_line
)
70 console_pattern
= 'Kernel command line: %s' % kernel_command_line
71 self
.wait_for_console_pattern(console_pattern
)
73 def test_mips_malta(self
):
75 :avocado: tags=arch:mips
76 :avocado: tags=machine:malta
77 :avocado: tags=endian:big
79 deb_url
= ('http://snapshot.debian.org/archive/debian/'
80 '20130217T032700Z/pool/main/l/linux-2.6/'
81 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
82 deb_hash
= 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
83 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
84 kernel_path
= self
.extract_from_deb(deb_path
,
85 '/boot/vmlinux-2.6.32-5-4kc-malta')
88 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
89 self
.vm
.add_args('-kernel', kernel_path
,
90 '-append', kernel_command_line
)
92 console_pattern
= 'Kernel command line: %s' % kernel_command_line
93 self
.wait_for_console_pattern(console_pattern
)
95 def test_mips64el_malta(self
):
97 This test requires the ar tool to extract "data.tar.gz" from
100 The kernel can be rebuilt using this Debian kernel source [1] and
101 following the instructions on [2].
103 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
104 #linux-source-2.6.32_2.6.32-48
105 [2] https://kernel-team.pages.debian.net/kernel-handbook/
106 ch-common-tasks.html#s-common-official
108 :avocado: tags=arch:mips64el
109 :avocado: tags=machine:malta
111 deb_url
= ('http://snapshot.debian.org/archive/debian/'
112 '20130217T032700Z/pool/main/l/linux-2.6/'
113 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
114 deb_hash
= '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
115 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
116 kernel_path
= self
.extract_from_deb(deb_path
,
117 '/boot/vmlinux-2.6.32-5-5kc-malta')
119 self
.vm
.set_console()
120 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
121 self
.vm
.add_args('-kernel', kernel_path
,
122 '-append', kernel_command_line
)
124 console_pattern
= 'Kernel command line: %s' % kernel_command_line
125 self
.wait_for_console_pattern(console_pattern
)
127 def test_mips_malta_cpio(self
):
129 :avocado: tags=arch:mips
130 :avocado: tags=machine:malta
131 :avocado: tags=endian:big
133 deb_url
= ('http://snapshot.debian.org/archive/debian/'
134 '20160601T041800Z/pool/main/l/linux/'
135 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
136 deb_hash
= 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
137 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
138 kernel_path
= self
.extract_from_deb(deb_path
,
139 '/boot/vmlinux-4.5.0-2-4kc-malta')
140 initrd_url
= ('https://github.com/groeck/linux-build-test/raw/'
141 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
142 'mips/rootfs.cpio.gz')
143 initrd_hash
= 'bf806e17009360a866bf537f6de66590de349a99'
144 initrd_path_gz
= self
.fetch_asset(initrd_url
, asset_hash
=initrd_hash
)
145 initrd_path
= self
.workdir
+ "rootfs.cpio"
146 archive
.gzip_uncompress(initrd_path_gz
, initrd_path
)
148 self
.vm
.set_console()
149 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
150 + 'console=ttyS0 console=tty '
151 + 'rdinit=/sbin/init noreboot')
152 self
.vm
.add_args('-kernel', kernel_path
,
153 '-initrd', initrd_path
,
154 '-append', kernel_command_line
,
157 self
.wait_for_console_pattern('Boot successful.')
159 exec_command_and_wait_for_pattern(self
, 'cat /proc/cpuinfo',
161 exec_command_and_wait_for_pattern(self
, 'uname -a',
163 exec_command_and_wait_for_pattern(self
, 'reboot',
164 'reboot: Restarting system')
166 @skipUnless(os
.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
167 def test_mips64el_malta_5KEc_cpio(self
):
169 :avocado: tags=arch:mips64el
170 :avocado: tags=machine:malta
171 :avocado: tags=endian:little
173 kernel_url
= ('https://github.com/philmd/qemu-testing-blob/'
174 'raw/9ad2df38/mips/malta/mips64el/'
175 'vmlinux-3.19.3.mtoman.20150408')
176 kernel_hash
= '00d1d268fb9f7d8beda1de6bebcc46e884d71754'
177 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
178 initrd_url
= ('https://github.com/groeck/linux-build-test/'
179 'raw/8584a59e/rootfs/'
180 'mipsel64/rootfs.mipsel64r1.cpio.gz')
181 initrd_hash
= '1dbb8a396e916847325284dbe2151167'
182 initrd_path_gz
= self
.fetch_asset(initrd_url
, algorithm
='md5',
183 asset_hash
=initrd_hash
)
184 initrd_path
= self
.workdir
+ "rootfs.cpio"
185 archive
.gzip_uncompress(initrd_path_gz
, initrd_path
)
187 self
.vm
.set_console()
188 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
189 + 'console=ttyS0 console=tty '
190 + 'rdinit=/sbin/init noreboot')
191 self
.vm
.add_args('-cpu', '5KEc',
192 '-kernel', kernel_path
,
193 '-initrd', initrd_path
,
194 '-append', kernel_command_line
,
197 wait_for_console_pattern(self
, 'Boot successful.')
199 exec_command_and_wait_for_pattern(self
, 'cat /proc/cpuinfo',
201 exec_command_and_wait_for_pattern(self
, 'uname -a',
202 '3.19.3.mtoman.20150408')
203 exec_command_and_wait_for_pattern(self
, 'reboot',
204 'reboot: Restarting system')
206 def do_test_mips_malta32el_nanomips(self
, kernel_url
, kernel_hash
):
207 kernel_path_xz
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
208 kernel_path
= self
.workdir
+ "kernel"
209 with lzma
.open(kernel_path_xz
, 'rb') as f_in
:
210 with
open(kernel_path
, 'wb') as f_out
:
211 shutil
.copyfileobj(f_in
, f_out
)
213 self
.vm
.set_console()
214 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
217 self
.vm
.add_args('-no-reboot',
219 '-kernel', kernel_path
,
220 '-append', kernel_command_line
)
222 console_pattern
= 'Kernel command line: %s' % kernel_command_line
223 self
.wait_for_console_pattern(console_pattern
)
225 def test_mips_malta32el_nanomips_4k(self
):
227 :avocado: tags=arch:mipsel
228 :avocado: tags=machine:malta
229 :avocado: tags=endian:little
231 kernel_url
= ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
232 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
233 'generic_nano32r6el_page4k.xz')
234 kernel_hash
= '477456aafd2a0f1ddc9482727f20fe9575565dd6'
235 self
.do_test_mips_malta32el_nanomips(kernel_url
, kernel_hash
)
237 def test_mips_malta32el_nanomips_16k_up(self
):
239 :avocado: tags=arch:mipsel
240 :avocado: tags=machine:malta
241 :avocado: tags=endian:little
243 kernel_url
= ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
244 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
245 'generic_nano32r6el_page16k_up.xz')
246 kernel_hash
= 'e882868f944c71c816e832e2303b7874d044a7bc'
247 self
.do_test_mips_malta32el_nanomips(kernel_url
, kernel_hash
)
249 def test_mips_malta32el_nanomips_64k_dbg(self
):
251 :avocado: tags=arch:mipsel
252 :avocado: tags=machine:malta
253 :avocado: tags=endian:little
255 kernel_url
= ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
256 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
257 'generic_nano32r6el_page64k_dbg.xz')
258 kernel_hash
= '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
259 self
.do_test_mips_malta32el_nanomips(kernel_url
, kernel_hash
)
261 def test_aarch64_virt(self
):
263 :avocado: tags=arch:aarch64
264 :avocado: tags=machine:virt
266 kernel_url
= ('https://archives.fedoraproject.org/pub/archive/fedora'
267 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
269 kernel_hash
= '8c73e469fc6ea06a58dc83a628fc695b693b8493'
270 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
272 self
.vm
.set_console()
273 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
275 self
.vm
.add_args('-cpu', 'cortex-a53',
276 '-kernel', kernel_path
,
277 '-append', kernel_command_line
)
279 console_pattern
= 'Kernel command line: %s' % kernel_command_line
280 self
.wait_for_console_pattern(console_pattern
)
282 def test_arm_virt(self
):
284 :avocado: tags=arch:arm
285 :avocado: tags=machine:virt
287 kernel_url
= ('https://archives.fedoraproject.org/pub/archive/fedora'
288 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
290 kernel_hash
= 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
291 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
293 self
.vm
.set_console()
294 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
296 self
.vm
.add_args('-kernel', kernel_path
,
297 '-append', kernel_command_line
)
299 console_pattern
= 'Kernel command line: %s' % kernel_command_line
300 self
.wait_for_console_pattern(console_pattern
)
302 def test_arm_emcraft_sf2(self
):
304 :avocado: tags=arch:arm
305 :avocado: tags=machine:emcraft-sf2
306 :avocado: tags=endian:little
308 uboot_url
= ('https://raw.githubusercontent.com/'
309 'Subbaraya-Sundeep/qemu-test-binaries/'
310 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
311 uboot_hash
= 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
312 uboot_path
= self
.fetch_asset(uboot_url
, asset_hash
=uboot_hash
)
313 spi_url
= ('https://raw.githubusercontent.com/'
314 'Subbaraya-Sundeep/qemu-test-binaries/'
315 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
316 spi_hash
= '85f698329d38de63aea6e884a86fbde70890a78a'
317 spi_path
= self
.fetch_asset(spi_url
, asset_hash
=spi_hash
)
319 self
.vm
.set_console()
320 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
321 self
.vm
.add_args('-kernel', uboot_path
,
322 '-append', kernel_command_line
,
323 '-drive', 'file=' + spi_path
+ ',if=mtd,format=raw',
326 self
.wait_for_console_pattern('init started: BusyBox')
328 def do_test_arm_raspi2(self
, uart_id
):
330 The kernel can be rebuilt using the kernel source referenced
331 and following the instructions on the on:
332 https://www.raspberrypi.org/documentation/linux/kernel/building.md
334 serial_kernel_cmdline
= {
335 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
337 deb_url
= ('http://archive.raspberrypi.org/debian/'
338 'pool/main/r/raspberrypi-firmware/'
339 'raspberrypi-kernel_1.20190215-1_armhf.deb')
340 deb_hash
= 'cd284220b32128c5084037553db3c482426f3972'
341 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
342 kernel_path
= self
.extract_from_deb(deb_path
, '/boot/kernel7.img')
343 dtb_path
= self
.extract_from_deb(deb_path
, '/boot/bcm2709-rpi-2-b.dtb')
345 self
.vm
.set_console()
346 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
347 serial_kernel_cmdline
[uart_id
])
348 self
.vm
.add_args('-kernel', kernel_path
,
350 '-append', kernel_command_line
)
352 console_pattern
= 'Kernel command line: %s' % kernel_command_line
353 self
.wait_for_console_pattern(console_pattern
)
355 def test_arm_raspi2_uart0(self
):
357 :avocado: tags=arch:arm
358 :avocado: tags=machine:raspi2
359 :avocado: tags=device:pl011
361 self
.do_test_arm_raspi2(0)
363 def test_arm_exynos4210_initrd(self
):
365 :avocado: tags=arch:arm
366 :avocado: tags=machine:smdkc210
368 deb_url
= ('https://snapshot.debian.org/archive/debian/'
369 '20190928T224601Z/pool/main/l/linux/'
370 'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb')
371 deb_hash
= 'fa9df4a0d38936cb50084838f2cb933f570d7d82'
372 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
373 kernel_path
= self
.extract_from_deb(deb_path
,
374 '/boot/vmlinuz-4.19.0-6-armmp')
375 dtb_path
= '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb'
376 dtb_path
= self
.extract_from_deb(deb_path
, dtb_path
)
378 initrd_url
= ('https://github.com/groeck/linux-build-test/raw/'
379 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
380 'arm/rootfs-armv5.cpio.gz')
381 initrd_hash
= '2b50f1873e113523967806f4da2afe385462ff9b'
382 initrd_path_gz
= self
.fetch_asset(initrd_url
, asset_hash
=initrd_hash
)
383 initrd_path
= os
.path
.join(self
.workdir
, 'rootfs.cpio')
384 archive
.gzip_uncompress(initrd_path_gz
, initrd_path
)
386 self
.vm
.set_console()
387 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
388 'earlycon=exynos4210,0x13800000 earlyprintk ' +
389 'console=ttySAC0,115200n8 ' +
390 'random.trust_cpu=off cryptomgr.notests ' +
391 'cpuidle.off=1 panic=-1 noreboot')
393 self
.vm
.add_args('-kernel', kernel_path
,
395 '-initrd', initrd_path
,
396 '-append', kernel_command_line
,
400 self
.wait_for_console_pattern('Boot successful.')
401 # TODO user command, for now the uart is stuck
403 def test_s390x_s390_ccw_virtio(self
):
405 :avocado: tags=arch:s390x
406 :avocado: tags=machine:s390-ccw-virtio
408 kernel_url
= ('https://archives.fedoraproject.org/pub/archive'
409 '/fedora-secondary/releases/29/Everything/s390x/os/images'
411 kernel_hash
= 'e8e8439103ef8053418ef062644ffd46a7919313'
412 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
414 self
.vm
.set_console()
415 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=sclp0'
416 self
.vm
.add_args('-nodefaults',
417 '-kernel', kernel_path
,
418 '-append', kernel_command_line
)
420 console_pattern
= 'Kernel command line: %s' % kernel_command_line
421 self
.wait_for_console_pattern(console_pattern
)
423 def test_alpha_clipper(self
):
425 :avocado: tags=arch:alpha
426 :avocado: tags=machine:clipper
428 kernel_url
= ('http://archive.debian.org/debian/dists/lenny/main/'
429 'installer-alpha/current/images/cdrom/vmlinuz')
430 kernel_hash
= '3a943149335529e2ed3e74d0d787b85fb5671ba3'
431 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
433 uncompressed_kernel
= archive
.uncompress(kernel_path
, self
.workdir
)
435 self
.vm
.set_console()
436 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=ttyS0'
437 self
.vm
.add_args('-vga', 'std',
438 '-kernel', uncompressed_kernel
,
439 '-append', kernel_command_line
)
441 console_pattern
= 'Kernel command line: %s' % kernel_command_line
442 self
.wait_for_console_pattern(console_pattern
)
444 def test_ppc64_pseries(self
):
446 :avocado: tags=arch:ppc64
447 :avocado: tags=machine:pseries
449 kernel_url
= ('https://archives.fedoraproject.org/pub/archive'
450 '/fedora-secondary/releases/29/Everything/ppc64le/os'
451 '/ppc/ppc64/vmlinuz')
452 kernel_hash
= '3fe04abfc852b66653b8c3c897a59a689270bc77'
453 kernel_path
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
455 self
.vm
.set_console()
456 kernel_command_line
= self
.KERNEL_COMMON_COMMAND_LINE
+ 'console=hvc0'
457 self
.vm
.add_args('-kernel', kernel_path
,
458 '-append', kernel_command_line
)
460 console_pattern
= 'Kernel command line: %s' % kernel_command_line
461 self
.wait_for_console_pattern(console_pattern
)
463 def test_m68k_q800(self
):
465 :avocado: tags=arch:m68k
466 :avocado: tags=machine:q800
468 deb_url
= ('https://snapshot.debian.org/archive/debian-ports'
469 '/20191021T083923Z/pool-m68k/main'
470 '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
471 deb_hash
= '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
472 deb_path
= self
.fetch_asset(deb_url
, asset_hash
=deb_hash
)
473 kernel_path
= self
.extract_from_deb(deb_path
,
474 '/boot/vmlinux-5.3.0-1-m68k')
476 self
.vm
.set_console()
477 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
478 'console=ttyS0 vga=off')
479 self
.vm
.add_args('-kernel', kernel_path
,
480 '-append', kernel_command_line
)
482 console_pattern
= 'Kernel command line: %s' % kernel_command_line
483 self
.wait_for_console_pattern(console_pattern
)
484 console_pattern
= 'No filesystem could mount root'
485 self
.wait_for_console_pattern(console_pattern
)