]> git.ipfire.org Git - thirdparty/qemu.git/blob - tests/acceptance/boot_linux_console.py
tests/boot_linux_console: Add a test for the Raspberry Pi 2
[thirdparty/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 lzma
13 import gzip
14 import shutil
15
16 from avocado_qemu import Test
17 from avocado_qemu import exec_command_and_wait_for_pattern
18 from avocado_qemu import wait_for_console_pattern
19 from avocado.utils import process
20 from avocado.utils import archive
21
22
23 class BootLinuxConsole(Test):
24 """
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
27 """
28
29 timeout = 90
30
31 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
32
33 def wait_for_console_pattern(self, success_message):
34 wait_for_console_pattern(self, success_message,
35 failure_message='Kernel panic - not syncing')
36
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)
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)
50 os.chdir(cwd)
51 return self.workdir + path
52
53 def test_x86_64_pc(self):
54 """
55 :avocado: tags=arch:x86_64
56 :avocado: tags=machine:pc
57 """
58 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
59 '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
60 '/vmlinuz')
61 kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
62 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
63
64 self.vm.set_machine('pc')
65 self.vm.set_console()
66 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
67 self.vm.add_args('-kernel', kernel_path,
68 '-append', kernel_command_line)
69 self.vm.launch()
70 console_pattern = 'Kernel command line: %s' % kernel_command_line
71 self.wait_for_console_pattern(console_pattern)
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)
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)
128
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"
148 archive.gzip_uncompress(initrd_path_gz, initrd_path)
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
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')
168
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
225 def test_aarch64_virt(self):
226 """
227 :avocado: tags=arch:aarch64
228 :avocado: tags=machine:virt
229 """
230 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
231 '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
232 '/vmlinuz')
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)
246
247 def test_arm_virt(self):
248 """
249 :avocado: tags=arch:arm
250 :avocado: tags=machine:virt
251 """
252 kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
253 '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
254 '/vmlinuz')
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)
267
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
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
331 def test_s390x_s390_ccw_virtio(self):
332 """
333 :avocado: tags=arch:s390x
334 :avocado: tags=machine:s390_ccw_virtio
335 """
336 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
337 '/fedora-secondary/releases/29/Everything/s390x/os/images'
338 '/kernel.img')
339 kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
340 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
341
342 self.vm.set_machine('s390-ccw-virtio')
343 self.vm.set_console()
344 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
345 self.vm.add_args('-nodefaults',
346 '-kernel', kernel_path,
347 '-append', kernel_command_line)
348 self.vm.launch()
349 console_pattern = 'Kernel command line: %s' % kernel_command_line
350 self.wait_for_console_pattern(console_pattern)
351
352 def test_alpha_clipper(self):
353 """
354 :avocado: tags=arch:alpha
355 :avocado: tags=machine:clipper
356 """
357 kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
358 'installer-alpha/current/images/cdrom/vmlinuz')
359 kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
360 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
361
362 uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
363
364 self.vm.set_machine('clipper')
365 self.vm.set_console()
366 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
367 self.vm.add_args('-vga', 'std',
368 '-kernel', uncompressed_kernel,
369 '-append', kernel_command_line)
370 self.vm.launch()
371 console_pattern = 'Kernel command line: %s' % kernel_command_line
372 self.wait_for_console_pattern(console_pattern)
373
374 def test_ppc64_pseries(self):
375 """
376 :avocado: tags=arch:ppc64
377 :avocado: tags=machine:pseries
378 """
379 kernel_url = ('https://archives.fedoraproject.org/pub/archive'
380 '/fedora-secondary/releases/29/Everything/ppc64le/os'
381 '/ppc/ppc64/vmlinuz')
382 kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
383 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
384
385 self.vm.set_machine('pseries')
386 self.vm.set_console()
387 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
388 self.vm.add_args('-kernel', kernel_path,
389 '-append', kernel_command_line)
390 self.vm.launch()
391 console_pattern = 'Kernel command line: %s' % kernel_command_line
392 self.wait_for_console_pattern(console_pattern)