]> git.proxmox.com Git - mirror_qemu.git/blame - tests/acceptance/boot_linux_console.py
tests/boot_linux_console: Add initrd test for the Exynos4210
[mirror_qemu.git] / tests / acceptance / boot_linux_console.py
CommitLineData
c1cc73f4
CR
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
f8792047 11import os
f375ad6a 12import lzma
89368673 13import gzip
f375ad6a 14import shutil
c1cc73f4
CR
15
16from avocado_qemu import Test
2b17d81f 17from avocado_qemu import exec_command_and_wait_for_pattern
77bcd248 18from avocado_qemu import wait_for_console_pattern
f8792047
PMD
19from avocado.utils import process
20from avocado.utils import archive
c1cc73f4
CR
21
22
23class BootLinuxConsole(Test):
24 """
78664ed8
CR
25 Boots a Linux kernel and checks that the console is operational and the
26 kernel command line is properly passed from QEMU to the kernel
c1cc73f4
CR
27 """
28
61f74506 29 timeout = 90
c1cc73f4 30
b50fcd39
CR
31 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
32
77bcd248
CR
33 def wait_for_console_pattern(self, success_message):
34 wait_for_console_pattern(self, success_message,
35 failure_message='Kernel panic - not syncing')
0d1d74e5 36
f8792047
PMD
37 def extract_from_deb(self, deb, path):
38 """
39 Extracts a file from a deb package into the test workdir
40
41 :param deb: path to the deb archive
42 :param file: path within the deb archive of the file to be extracted
43 :returns: path of the extracted file
44 """
45 cwd = os.getcwd()
46 os.chdir(self.workdir)
6c1c4c33
PMD
47 file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
48 process.run("ar x %s %s" % (deb, file_path))
49 archive.extract(file_path, self.workdir)
f8792047
PMD
50 os.chdir(cwd)
51 return self.workdir + path
52
78664ed8
CR
53 def test_x86_64_pc(self):
54 """
55 :avocado: tags=arch:x86_64
56 :avocado: tags=machine:pc
57 """
93bbbdf6
CR
58 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
59 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
60 '/vmlinuz')
7d7985b1 61 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
c1cc73f4
CR
62 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
63
64 self.vm.set_machine('pc')
65 self.vm.set_console()
b50fcd39 66 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
c1cc73f4
CR
67 self.vm.add_args('-kernel', kernel_path,
68 '-append', kernel_command_line)
69 self.vm.launch()
0d1d74e5
CR
70 console_pattern = 'Kernel command line: %s' % kernel_command_line
71 self.wait_for_console_pattern(console_pattern)
f8792047
PMD
72
73 def test_mips_malta(self):
74 """
75 :avocado: tags=arch:mips
76 :avocado: tags=machine:malta
77 :avocado: tags=endian:big
78 """
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')
86
87 self.vm.set_machine('malta')
88 self.vm.set_console()
89 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
90 self.vm.add_args('-kernel', kernel_path,
91 '-append', kernel_command_line)
92 self.vm.launch()
93 console_pattern = 'Kernel command line: %s' % kernel_command_line
94 self.wait_for_console_pattern(console_pattern)
02c2852b
CR
95
96 def test_mips64el_malta(self):
97 """
98 This test requires the ar tool to extract "data.tar.gz" from
99 the Debian package.
100
101 The kernel can be rebuilt using this Debian kernel source [1] and
102 following the instructions on [2].
103
104 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
105 #linux-source-2.6.32_2.6.32-48
106 [2] https://kernel-team.pages.debian.net/kernel-handbook/
107 ch-common-tasks.html#s-common-official
108
109 :avocado: tags=arch:mips64el
110 :avocado: tags=machine:malta
111 """
112 deb_url = ('http://snapshot.debian.org/archive/debian/'
113 '20130217T032700Z/pool/main/l/linux-2.6/'
114 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
115 deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
116 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
117 kernel_path = self.extract_from_deb(deb_path,
118 '/boot/vmlinux-2.6.32-5-5kc-malta')
119
120 self.vm.set_machine('malta')
121 self.vm.set_console()
122 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
123 self.vm.add_args('-kernel', kernel_path,
124 '-append', kernel_command_line)
125 self.vm.launch()
126 console_pattern = 'Kernel command line: %s' % kernel_command_line
127 self.wait_for_console_pattern(console_pattern)
d4e12161 128
89368673
PMD
129 def test_mips_malta_cpio(self):
130 """
131 :avocado: tags=arch:mips
132 :avocado: tags=machine:malta
133 :avocado: tags=endian:big
134 """
135 deb_url = ('http://snapshot.debian.org/archive/debian/'
136 '20160601T041800Z/pool/main/l/linux/'
137 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
138 deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
139 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
140 kernel_path = self.extract_from_deb(deb_path,
141 '/boot/vmlinux-4.5.0-2-4kc-malta')
142 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
143 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
144 'mips/rootfs.cpio.gz')
145 initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
146 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
147 initrd_path = self.workdir + "rootfs.cpio"
f2cd6cf6 148 archive.gzip_uncompress(initrd_path_gz, initrd_path)
89368673
PMD
149
150 self.vm.set_machine('malta')
151 self.vm.set_console()
152 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
153 + 'console=ttyS0 console=tty '
154 + 'rdinit=/sbin/init noreboot')
155 self.vm.add_args('-kernel', kernel_path,
156 '-initrd', initrd_path,
157 '-append', kernel_command_line,
158 '-no-reboot')
159 self.vm.launch()
160 self.wait_for_console_pattern('Boot successful.')
161
2b17d81f
PMD
162 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
163 'BogoMIPS')
164 exec_command_and_wait_for_pattern(self, 'uname -a',
165 'Debian')
166 exec_command_and_wait_for_pattern(self, 'reboot',
167 'reboot: Restarting system')
89368673 168
f375ad6a
PMD
169 def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash):
170 kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
171 kernel_path = self.workdir + "kernel"
172 with lzma.open(kernel_path_xz, 'rb') as f_in:
173 with open(kernel_path, 'wb') as f_out:
174 shutil.copyfileobj(f_in, f_out)
175
176 self.vm.set_machine('malta')
177 self.vm.set_console()
178 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
179 + 'mem=256m@@0x0 '
180 + 'console=ttyS0')
181 self.vm.add_args('-no-reboot',
182 '-cpu', 'I7200',
183 '-kernel', kernel_path,
184 '-append', kernel_command_line)
185 self.vm.launch()
186 console_pattern = 'Kernel command line: %s' % kernel_command_line
187 self.wait_for_console_pattern(console_pattern)
188
189 def test_mips_malta32el_nanomips_4k(self):
190 """
191 :avocado: tags=arch:mipsel
192 :avocado: tags=machine:malta
193 :avocado: tags=endian:little
194 """
195 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
196 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
197 'generic_nano32r6el_page4k.xz')
198 kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
199 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
200
201 def test_mips_malta32el_nanomips_16k_up(self):
202 """
203 :avocado: tags=arch:mipsel
204 :avocado: tags=machine:malta
205 :avocado: tags=endian:little
206 """
207 kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
208 'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
209 'generic_nano32r6el_page16k_up.xz')
210 kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
211 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
212
213 def test_mips_malta32el_nanomips_64k_dbg(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_page64k_dbg.xz')
222 kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
223 self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
224
d4e12161
CR
225 def test_aarch64_virt(self):
226 """
227 :avocado: tags=arch:aarch64
228 :avocado: tags=machine:virt
229 """
93bbbdf6
CR
230 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
231 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
232 '/vmlinuz')
d4e12161
CR
233 kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
234 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
235
236 self.vm.set_machine('virt')
237 self.vm.set_console()
238 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
239 'console=ttyAMA0')
240 self.vm.add_args('-cpu', 'cortex-a53',
241 '-kernel', kernel_path,
242 '-append', kernel_command_line)
243 self.vm.launch()
244 console_pattern = 'Kernel command line: %s' % kernel_command_line
245 self.wait_for_console_pattern(console_pattern)
1a30892e
CR
246
247 def test_arm_virt(self):
248 """
249 :avocado: tags=arch:arm
250 :avocado: tags=machine:virt
251 """
93bbbdf6
CR
252 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
253 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
254 '/vmlinuz')
1a30892e
CR
255 kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
256 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
257
258 self.vm.set_machine('virt')
259 self.vm.set_console()
260 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
261 'console=ttyAMA0')
262 self.vm.add_args('-kernel', kernel_path,
263 '-append', kernel_command_line)
264 self.vm.launch()
265 console_pattern = 'Kernel command line: %s' % kernel_command_line
266 self.wait_for_console_pattern(console_pattern)
79182494 267
77ead6b8
PMD
268 def test_arm_emcraft_sf2(self):
269 """
270 :avocado: tags=arch:arm
271 :avocado: tags=machine:emcraft_sf2
272 :avocado: tags=endian:little
273 """
274 uboot_url = ('https://raw.githubusercontent.com/'
275 'Subbaraya-Sundeep/qemu-test-binaries/'
276 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot')
277 uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff'
278 uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
279 spi_url = ('https://raw.githubusercontent.com/'
280 'Subbaraya-Sundeep/qemu-test-binaries/'
281 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin')
282 spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a'
283 spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
284
285 self.vm.set_machine('emcraft-sf2')
286 self.vm.set_console()
287 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
288 self.vm.add_args('-kernel', uboot_path,
289 '-append', kernel_command_line,
290 '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
291 '-no-reboot')
292 self.vm.launch()
293 self.wait_for_console_pattern('init started: BusyBox')
294
92d93612
PMD
295 def do_test_arm_raspi2(self, uart_id):
296 """
297 The kernel can be rebuilt using the kernel source referenced
298 and following the instructions on the on:
299 https://www.raspberrypi.org/documentation/linux/kernel/building.md
300 """
301 serial_kernel_cmdline = {
302 0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
303 }
304 deb_url = ('http://archive.raspberrypi.org/debian/'
305 'pool/main/r/raspberrypi-firmware/'
306 'raspberrypi-kernel_1.20190215-1_armhf.deb')
307 deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
308 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
309 kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
310 dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
311
312 self.vm.set_machine('raspi2')
313 self.vm.set_console()
314 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
315 serial_kernel_cmdline[uart_id])
316 self.vm.add_args('-kernel', kernel_path,
317 '-dtb', dtb_path,
318 '-append', kernel_command_line)
319 self.vm.launch()
320 console_pattern = 'Kernel command line: %s' % kernel_command_line
321 self.wait_for_console_pattern(console_pattern)
322
323 def test_arm_raspi2_uart0(self):
324 """
325 :avocado: tags=arch:arm
326 :avocado: tags=machine:raspi2
327 :avocado: tags=device:pl011
328 """
329 self.do_test_arm_raspi2(0)
330
017aa60b
PMD
331 def test_arm_exynos4210_initrd(self):
332 """
333 :avocado: tags=arch:arm
334 :avocado: tags=machine:smdkc210
335 """
336 deb_url = ('https://snapshot.debian.org/archive/debian/'
337 '20190928T224601Z/pool/main/l/linux/'
338 'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb')
339 deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82'
340 deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
341 kernel_path = self.extract_from_deb(deb_path,
342 '/boot/vmlinuz-4.19.0-6-armmp')
343 dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb'
344 dtb_path = self.extract_from_deb(deb_path, dtb_path)
345
346 initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
347 '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
348 'arm/rootfs-armv5.cpio.gz')
349 initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
350 initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
351 initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
352 archive.gzip_uncompress(initrd_path_gz, initrd_path)
353
354 self.vm.set_machine('smdkc210')
355 self.vm.set_console()
356 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
357 'earlycon=exynos4210,0x13800000 earlyprintk ' +
358 'console=ttySAC0,115200n8 ' +
359 'random.trust_cpu=off cryptomgr.notests ' +
360 'cpuidle.off=1 panic=-1 noreboot')
361
362 self.vm.add_args('-kernel', kernel_path,
363 '-dtb', dtb_path,
364 '-initrd', initrd_path,
365 '-append', kernel_command_line,
366 '-no-reboot')
367 self.vm.launch()
368
369 self.wait_for_console_pattern('Boot successful.')
370 # TODO user command, for now the uart is stuck
371
79182494
CR
372 def test_s390x_s390_ccw_virtio(self):
373 """
374 :avocado: tags=arch:s390x
375 :avocado: tags=machine:s390_ccw_virtio
376 """
93bbbdf6
CR
377 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
378 '/fedora-secondary/releases/29/Everything/s390x/os/images'
379 '/kernel.img')
79182494
CR
380 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
381 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
382
383 self.vm.set_machine('s390-ccw-virtio')
384 self.vm.set_console()
385 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
386 self.vm.add_args('-nodefaults',
387 '-kernel', kernel_path,
388 '-append', kernel_command_line)
389 self.vm.launch()
390 console_pattern = 'Kernel command line: %s' % kernel_command_line
391 self.wait_for_console_pattern(console_pattern)
b36b5937
CR
392
393 def test_alpha_clipper(self):
394 """
395 :avocado: tags=arch:alpha
396 :avocado: tags=machine:clipper
397 """
398 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
399 'installer-alpha/current/images/cdrom/vmlinuz')
400 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
401 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
402
403 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
404
405 self.vm.set_machine('clipper')
406 self.vm.set_console()
407 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
408 self.vm.add_args('-vga', 'std',
409 '-kernel', uncompressed_kernel,
410 '-append', kernel_command_line)
411 self.vm.launch()
412 console_pattern = 'Kernel command line: %s' % kernel_command_line
413 self.wait_for_console_pattern(console_pattern)
83fa3bc3
CR
414
415 def test_ppc64_pseries(self):
416 """
417 :avocado: tags=arch:ppc64
418 :avocado: tags=machine:pseries
419 """
93bbbdf6
CR
420 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
421 '/fedora-secondary/releases/29/Everything/ppc64le/os'
422 '/ppc/ppc64/vmlinuz')
83fa3bc3
CR
423 kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
424 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
425
426 self.vm.set_machine('pseries')
427 self.vm.set_console()
428 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
429 self.vm.add_args('-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)