]> Git Repo - qemu.git/blob - tests/acceptance/boot_linux_console.py
block/nvme: Replace magic value by SCALE_MS definition
[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 <[email protected]>
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 import skipUnless
17 from avocado_qemu import Test
18 from avocado_qemu import exec_command_and_wait_for_pattern
19 from avocado_qemu import interrupt_interactive_console_until_pattern
20 from avocado_qemu import wait_for_console_pattern
21 from avocado.utils import process
22 from avocado.utils import archive
23 from avocado.utils.path import find_command, CmdNotFoundError
24
25 P7ZIP_AVAILABLE = True
26 try:
27     find_command('7z')
28 except CmdNotFoundError:
29     P7ZIP_AVAILABLE = False
30
31 """
32 Round up to next power of 2
33 """
34 def pow2ceil(x):
35     return 1 if x == 0 else 2**(x - 1).bit_length()
36
37 """
38 Expand file size to next power of 2
39 """
40 def image_pow2ceil_expand(path):
41         size = os.path.getsize(path)
42         size_aligned = pow2ceil(size)
43         if size != size_aligned:
44             with open(path, 'ab+') as fd:
45                 fd.truncate(size_aligned)
46
47 class LinuxKernelTest(Test):
48     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
49
50     def wait_for_console_pattern(self, success_message, vm=None):
51         wait_for_console_pattern(self, success_message,
52                                  failure_message='Kernel panic - not syncing',
53                                  vm=vm)
54
55     def extract_from_deb(self, deb, path):
56         """
57         Extracts a file from a deb package into the test workdir
58
59         :param deb: path to the deb archive
60         :param path: path within the deb archive of the file to be extracted
61         :returns: path of the extracted file
62         """
63         cwd = os.getcwd()
64         os.chdir(self.workdir)
65         file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
66         process.run("ar x %s %s" % (deb, file_path))
67         archive.extract(file_path, self.workdir)
68         os.chdir(cwd)
69         # Return complete path to extracted file.  Because callers to
70         # extract_from_deb() specify 'path' with a leading slash, it is
71         # necessary to use os.path.relpath() as otherwise os.path.join()
72         # interprets it as an absolute path and drops the self.workdir part.
73         return os.path.normpath(os.path.join(self.workdir,
74                                              os.path.relpath(path, '/')))
75
76     def extract_from_rpm(self, rpm, path):
77         """
78         Extracts a file from an RPM package into the test workdir.
79
80         :param rpm: path to the rpm archive
81         :param path: path within the rpm archive of the file to be extracted
82                      needs to be a relative path (starting with './') because
83                      cpio(1), which is used to extract the file, expects that.
84         :returns: path of the extracted file
85         """
86         cwd = os.getcwd()
87         os.chdir(self.workdir)
88         process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True)
89         os.chdir(cwd)
90         return os.path.normpath(os.path.join(self.workdir, path))
91
92 class BootLinuxConsole(LinuxKernelTest):
93     """
94     Boots a Linux kernel and checks that the console is operational and the
95     kernel command line is properly passed from QEMU to the kernel
96     """
97     timeout = 90
98
99     def test_x86_64_pc(self):
100         """
101         :avocado: tags=arch:x86_64
102         :avocado: tags=machine:pc
103         """
104         kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
105                       '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
106                       '/vmlinuz')
107         kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
108         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
109
110         self.vm.set_console()
111         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
112         self.vm.add_args('-kernel', kernel_path,
113                          '-append', kernel_command_line)
114         self.vm.launch()
115         console_pattern = 'Kernel command line: %s' % kernel_command_line
116         self.wait_for_console_pattern(console_pattern)
117
118     def test_mips_malta(self):
119         """
120         :avocado: tags=arch:mips
121         :avocado: tags=machine:malta
122         :avocado: tags=endian:big
123         """
124         deb_url = ('http://snapshot.debian.org/archive/debian/'
125                    '20130217T032700Z/pool/main/l/linux-2.6/'
126                    'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
127         deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
128         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
129         kernel_path = self.extract_from_deb(deb_path,
130                                             '/boot/vmlinux-2.6.32-5-4kc-malta')
131
132         self.vm.set_console()
133         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
134         self.vm.add_args('-kernel', kernel_path,
135                          '-append', kernel_command_line)
136         self.vm.launch()
137         console_pattern = 'Kernel command line: %s' % kernel_command_line
138         self.wait_for_console_pattern(console_pattern)
139
140     def test_mips64el_malta(self):
141         """
142         This test requires the ar tool to extract "data.tar.gz" from
143         the Debian package.
144
145         The kernel can be rebuilt using this Debian kernel source [1] and
146         following the instructions on [2].
147
148         [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
149             #linux-source-2.6.32_2.6.32-48
150         [2] https://kernel-team.pages.debian.net/kernel-handbook/
151             ch-common-tasks.html#s-common-official
152
153         :avocado: tags=arch:mips64el
154         :avocado: tags=machine:malta
155         """
156         deb_url = ('http://snapshot.debian.org/archive/debian/'
157                    '20130217T032700Z/pool/main/l/linux-2.6/'
158                    'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
159         deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
160         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
161         kernel_path = self.extract_from_deb(deb_path,
162                                             '/boot/vmlinux-2.6.32-5-5kc-malta')
163
164         self.vm.set_console()
165         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
166         self.vm.add_args('-kernel', kernel_path,
167                          '-append', kernel_command_line)
168         self.vm.launch()
169         console_pattern = 'Kernel command line: %s' % kernel_command_line
170         self.wait_for_console_pattern(console_pattern)
171
172     def test_mips_malta_cpio(self):
173         """
174         :avocado: tags=arch:mips
175         :avocado: tags=machine:malta
176         :avocado: tags=endian:big
177         """
178         deb_url = ('http://snapshot.debian.org/archive/debian/'
179                    '20160601T041800Z/pool/main/l/linux/'
180                    'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
181         deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
182         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
183         kernel_path = self.extract_from_deb(deb_path,
184                                             '/boot/vmlinux-4.5.0-2-4kc-malta')
185         initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
186                       '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
187                       'mips/rootfs.cpio.gz')
188         initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
189         initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
190         initrd_path = self.workdir + "rootfs.cpio"
191         archive.gzip_uncompress(initrd_path_gz, initrd_path)
192
193         self.vm.set_console()
194         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
195                                + 'console=ttyS0 console=tty '
196                                + 'rdinit=/sbin/init noreboot')
197         self.vm.add_args('-kernel', kernel_path,
198                          '-initrd', initrd_path,
199                          '-append', kernel_command_line,
200                          '-no-reboot')
201         self.vm.launch()
202         self.wait_for_console_pattern('Boot successful.')
203
204         exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
205                                                 'BogoMIPS')
206         exec_command_and_wait_for_pattern(self, 'uname -a',
207                                                 'Debian')
208         exec_command_and_wait_for_pattern(self, 'reboot',
209                                                 'reboot: Restarting system')
210         # Wait for VM to shut down gracefully
211         self.vm.wait()
212
213     @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
214     def test_mips64el_malta_5KEc_cpio(self):
215         """
216         :avocado: tags=arch:mips64el
217         :avocado: tags=machine:malta
218         :avocado: tags=endian:little
219         """
220         kernel_url = ('https://github.com/philmd/qemu-testing-blob/'
221                       'raw/9ad2df38/mips/malta/mips64el/'
222                       'vmlinux-3.19.3.mtoman.20150408')
223         kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754'
224         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
225         initrd_url = ('https://github.com/groeck/linux-build-test/'
226                       'raw/8584a59e/rootfs/'
227                       'mipsel64/rootfs.mipsel64r1.cpio.gz')
228         initrd_hash = '1dbb8a396e916847325284dbe2151167'
229         initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5',
230                                           asset_hash=initrd_hash)
231         initrd_path = self.workdir + "rootfs.cpio"
232         archive.gzip_uncompress(initrd_path_gz, initrd_path)
233
234         self.vm.set_console()
235         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
236                                + 'console=ttyS0 console=tty '
237                                + 'rdinit=/sbin/init noreboot')
238         self.vm.add_args('-cpu', '5KEc',
239                          '-kernel', kernel_path,
240                          '-initrd', initrd_path,
241                          '-append', kernel_command_line,
242                          '-no-reboot')
243         self.vm.launch()
244         wait_for_console_pattern(self, 'Boot successful.')
245
246         exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
247                                                 'MIPS 5KE')
248         exec_command_and_wait_for_pattern(self, 'uname -a',
249                                                 '3.19.3.mtoman.20150408')
250         exec_command_and_wait_for_pattern(self, 'reboot',
251                                                 'reboot: Restarting system')
252         # Wait for VM to shut down gracefully
253         self.vm.wait()
254
255     def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash):
256         kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
257         kernel_path = self.workdir + "kernel"
258         with lzma.open(kernel_path_xz, 'rb') as f_in:
259             with open(kernel_path, 'wb') as f_out:
260                 shutil.copyfileobj(f_in, f_out)
261
262         self.vm.set_console()
263         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
264                                + 'mem=256m@@0x0 '
265                                + 'console=ttyS0')
266         self.vm.add_args('-no-reboot',
267                          '-cpu', 'I7200',
268                          '-kernel', kernel_path,
269                          '-append', kernel_command_line)
270         self.vm.launch()
271         console_pattern = 'Kernel command line: %s' % kernel_command_line
272         self.wait_for_console_pattern(console_pattern)
273
274     def test_mips_malta32el_nanomips_4k(self):
275         """
276         :avocado: tags=arch:mipsel
277         :avocado: tags=machine:malta
278         :avocado: tags=endian:little
279         """
280         kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
281                       'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
282                       'generic_nano32r6el_page4k.xz')
283         kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
284         self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
285
286     def test_mips_malta32el_nanomips_16k_up(self):
287         """
288         :avocado: tags=arch:mipsel
289         :avocado: tags=machine:malta
290         :avocado: tags=endian:little
291         """
292         kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
293                       'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
294                       'generic_nano32r6el_page16k_up.xz')
295         kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
296         self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
297
298     def test_mips_malta32el_nanomips_64k_dbg(self):
299         """
300         :avocado: tags=arch:mipsel
301         :avocado: tags=machine:malta
302         :avocado: tags=endian:little
303         """
304         kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
305                       'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
306                       'generic_nano32r6el_page64k_dbg.xz')
307         kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
308         self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
309
310     def test_aarch64_virt(self):
311         """
312         :avocado: tags=arch:aarch64
313         :avocado: tags=machine:virt
314         """
315         kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
316                       '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
317                       '/vmlinuz')
318         kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
319         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
320
321         self.vm.set_console()
322         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
323                                'console=ttyAMA0')
324         self.vm.add_args('-cpu', 'cortex-a53',
325                          '-kernel', kernel_path,
326                          '-append', kernel_command_line)
327         self.vm.launch()
328         console_pattern = 'Kernel command line: %s' % kernel_command_line
329         self.wait_for_console_pattern(console_pattern)
330
331     def test_aarch64_xlnx_versal_virt(self):
332         """
333         :avocado: tags=arch:aarch64
334         :avocado: tags=machine:xlnx-versal-virt
335         :avocado: tags=device:pl011
336         :avocado: tags=device:arm_gicv3
337         """
338         images_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/'
339                       'bionic-updates/main/installer-arm64/'
340                       '20101020ubuntu543.15/images/')
341         kernel_url = images_url + 'netboot/ubuntu-installer/arm64/linux'
342         kernel_hash = '5bfc54cf7ed8157d93f6e5b0241e727b6dc22c50'
343         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
344
345         initrd_url = images_url + 'netboot/ubuntu-installer/arm64/initrd.gz'
346         initrd_hash = 'd385d3e88d53e2004c5d43cbe668b458a094f772'
347         initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
348
349         self.vm.set_console()
350         self.vm.add_args('-m', '2G',
351                          '-kernel', kernel_path,
352                          '-initrd', initrd_path)
353         self.vm.launch()
354         self.wait_for_console_pattern('Checked W+X mappings: passed')
355
356     def test_arm_virt(self):
357         """
358         :avocado: tags=arch:arm
359         :avocado: tags=machine:virt
360         """
361         kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
362                       '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
363                       '/vmlinuz')
364         kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
365         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
366
367         self.vm.set_console()
368         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
369                                'console=ttyAMA0')
370         self.vm.add_args('-kernel', kernel_path,
371                          '-append', kernel_command_line)
372         self.vm.launch()
373         console_pattern = 'Kernel command line: %s' % kernel_command_line
374         self.wait_for_console_pattern(console_pattern)
375
376     def test_arm_emcraft_sf2(self):
377         """
378         :avocado: tags=arch:arm
379         :avocado: tags=machine:emcraft-sf2
380         :avocado: tags=endian:little
381         :avocado: tags=u-boot
382         """
383         uboot_url = ('https://raw.githubusercontent.com/'
384                      'Subbaraya-Sundeep/qemu-test-binaries/'
385                      'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot')
386         uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2'
387         uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
388         spi_url = ('https://raw.githubusercontent.com/'
389                    'Subbaraya-Sundeep/qemu-test-binaries/'
390                    'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin')
391         spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501'
392         spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
393
394         self.vm.set_console()
395         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
396         self.vm.add_args('-kernel', uboot_path,
397                          '-append', kernel_command_line,
398                          '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
399                          '-no-reboot')
400         self.vm.launch()
401         self.wait_for_console_pattern('Enter \'help\' for a list')
402
403         exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15',
404                                                  'eth0: link becomes ready')
405         exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
406             '3 packets transmitted, 3 packets received, 0% packet loss')
407
408     def do_test_arm_raspi2(self, uart_id):
409         """
410         The kernel can be rebuilt using the kernel source referenced
411         and following the instructions on the on:
412         https://www.raspberrypi.org/documentation/linux/kernel/building.md
413         """
414         serial_kernel_cmdline = {
415             0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
416         }
417         deb_url = ('http://archive.raspberrypi.org/debian/'
418                    'pool/main/r/raspberrypi-firmware/'
419                    'raspberrypi-kernel_1.20190215-1_armhf.deb')
420         deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
421         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
422         kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
423         dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
424
425         self.vm.set_console()
426         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
427                                serial_kernel_cmdline[uart_id] +
428                                ' root=/dev/mmcblk0p2 rootwait ' +
429                                'dwc_otg.fiq_fsm_enable=0')
430         self.vm.add_args('-kernel', kernel_path,
431                          '-dtb', dtb_path,
432                          '-append', kernel_command_line,
433                          '-device', 'usb-kbd')
434         self.vm.launch()
435         console_pattern = 'Kernel command line: %s' % kernel_command_line
436         self.wait_for_console_pattern(console_pattern)
437         console_pattern = 'Product: QEMU USB Keyboard'
438         self.wait_for_console_pattern(console_pattern)
439
440     def test_arm_raspi2_uart0(self):
441         """
442         :avocado: tags=arch:arm
443         :avocado: tags=machine:raspi2
444         :avocado: tags=device:pl011
445         """
446         self.do_test_arm_raspi2(0)
447
448     def test_arm_exynos4210_initrd(self):
449         """
450         :avocado: tags=arch:arm
451         :avocado: tags=machine:smdkc210
452         """
453         deb_url = ('https://snapshot.debian.org/archive/debian/'
454                    '20190928T224601Z/pool/main/l/linux/'
455                    'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb')
456         deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82'
457         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
458         kernel_path = self.extract_from_deb(deb_path,
459                                             '/boot/vmlinuz-4.19.0-6-armmp')
460         dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb'
461         dtb_path = self.extract_from_deb(deb_path, dtb_path)
462
463         initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
464                       '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
465                       'arm/rootfs-armv5.cpio.gz')
466         initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
467         initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
468         initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
469         archive.gzip_uncompress(initrd_path_gz, initrd_path)
470
471         self.vm.set_console()
472         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
473                                'earlycon=exynos4210,0x13800000 earlyprintk ' +
474                                'console=ttySAC0,115200n8 ' +
475                                'random.trust_cpu=off cryptomgr.notests ' +
476                                'cpuidle.off=1 panic=-1 noreboot')
477
478         self.vm.add_args('-kernel', kernel_path,
479                          '-dtb', dtb_path,
480                          '-initrd', initrd_path,
481                          '-append', kernel_command_line,
482                          '-no-reboot')
483         self.vm.launch()
484
485         self.wait_for_console_pattern('Boot successful.')
486         # TODO user command, for now the uart is stuck
487
488     def test_arm_cubieboard_initrd(self):
489         """
490         :avocado: tags=arch:arm
491         :avocado: tags=machine:cubieboard
492         """
493         deb_url = ('https://apt.armbian.com/pool/main/l/'
494                    'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
495         deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
496         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
497         kernel_path = self.extract_from_deb(deb_path,
498                                             '/boot/vmlinuz-4.20.7-sunxi')
499         dtb_path = '/usr/lib/linux-image-dev-sunxi/sun4i-a10-cubieboard.dtb'
500         dtb_path = self.extract_from_deb(deb_path, dtb_path)
501         initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
502                       '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
503                       'arm/rootfs-armv5.cpio.gz')
504         initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
505         initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
506         initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
507         archive.gzip_uncompress(initrd_path_gz, initrd_path)
508
509         self.vm.set_console()
510         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
511                                'console=ttyS0,115200 '
512                                'usbcore.nousb '
513                                'panic=-1 noreboot')
514         self.vm.add_args('-kernel', kernel_path,
515                          '-dtb', dtb_path,
516                          '-initrd', initrd_path,
517                          '-append', kernel_command_line,
518                          '-no-reboot')
519         self.vm.launch()
520         self.wait_for_console_pattern('Boot successful.')
521
522         exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
523                                                 'Allwinner sun4i/sun5i')
524         exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
525                                                 'system-control@1c00000')
526         # cubieboard's reboot is not functioning; omit reboot test.
527
528     def test_arm_cubieboard_sata(self):
529         """
530         :avocado: tags=arch:arm
531         :avocado: tags=machine:cubieboard
532         """
533         deb_url = ('https://apt.armbian.com/pool/main/l/'
534                    'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
535         deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
536         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
537         kernel_path = self.extract_from_deb(deb_path,
538                                             '/boot/vmlinuz-4.20.7-sunxi')
539         dtb_path = '/usr/lib/linux-image-dev-sunxi/sun4i-a10-cubieboard.dtb'
540         dtb_path = self.extract_from_deb(deb_path, dtb_path)
541         rootfs_url = ('https://github.com/groeck/linux-build-test/raw/'
542                       '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
543                       'arm/rootfs-armv5.ext2.gz')
544         rootfs_hash = '093e89d2b4d982234bf528bc9fb2f2f17a9d1f93'
545         rootfs_path_gz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
546         rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
547         archive.gzip_uncompress(rootfs_path_gz, rootfs_path)
548
549         self.vm.set_console()
550         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
551                                'console=ttyS0,115200 '
552                                'usbcore.nousb '
553                                'root=/dev/sda ro '
554                                'panic=-1 noreboot')
555         self.vm.add_args('-kernel', kernel_path,
556                          '-dtb', dtb_path,
557                          '-drive', 'if=none,format=raw,id=disk0,file='
558                                    + rootfs_path,
559                          '-device', 'ide-hd,bus=ide.0,drive=disk0',
560                          '-append', kernel_command_line,
561                          '-no-reboot')
562         self.vm.launch()
563         self.wait_for_console_pattern('Boot successful.')
564
565         exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
566                                                 'Allwinner sun4i/sun5i')
567         exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
568                                                 'sda')
569         # cubieboard's reboot is not functioning; omit reboot test.
570
571     def test_arm_orangepi(self):
572         """
573         :avocado: tags=arch:arm
574         :avocado: tags=machine:orangepi-pc
575         """
576         deb_url = ('https://apt.armbian.com/pool/main/l/'
577                    'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
578         deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
579         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
580         kernel_path = self.extract_from_deb(deb_path,
581                                             '/boot/vmlinuz-4.20.7-sunxi')
582         dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
583         dtb_path = self.extract_from_deb(deb_path, dtb_path)
584
585         self.vm.set_console()
586         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
587                                'console=ttyS0,115200n8 '
588                                'earlycon=uart,mmio32,0x1c28000')
589         self.vm.add_args('-kernel', kernel_path,
590                          '-dtb', dtb_path,
591                          '-append', kernel_command_line)
592         self.vm.launch()
593         console_pattern = 'Kernel command line: %s' % kernel_command_line
594         self.wait_for_console_pattern(console_pattern)
595
596     def test_arm_orangepi_initrd(self):
597         """
598         :avocado: tags=arch:arm
599         :avocado: tags=machine:orangepi-pc
600         """
601         deb_url = ('https://apt.armbian.com/pool/main/l/'
602                    'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
603         deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
604         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
605         kernel_path = self.extract_from_deb(deb_path,
606                                             '/boot/vmlinuz-4.20.7-sunxi')
607         dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
608         dtb_path = self.extract_from_deb(deb_path, dtb_path)
609         initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
610                       '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
611                       'arm/rootfs-armv7a.cpio.gz')
612         initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
613         initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
614         initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
615         archive.gzip_uncompress(initrd_path_gz, initrd_path)
616
617         self.vm.set_console()
618         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
619                                'console=ttyS0,115200 '
620                                'panic=-1 noreboot')
621         self.vm.add_args('-kernel', kernel_path,
622                          '-dtb', dtb_path,
623                          '-initrd', initrd_path,
624                          '-append', kernel_command_line,
625                          '-no-reboot')
626         self.vm.launch()
627         self.wait_for_console_pattern('Boot successful.')
628
629         exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
630                                                 'Allwinner sun8i Family')
631         exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
632                                                 'system-control@1c00000')
633         exec_command_and_wait_for_pattern(self, 'reboot',
634                                                 'reboot: Restarting system')
635         # Wait for VM to shut down gracefully
636         self.vm.wait()
637
638     def test_arm_orangepi_sd(self):
639         """
640         :avocado: tags=arch:arm
641         :avocado: tags=machine:orangepi-pc
642         :avocado: tags=device:sd
643         """
644         deb_url = ('https://apt.armbian.com/pool/main/l/'
645                    'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
646         deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
647         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
648         kernel_path = self.extract_from_deb(deb_path,
649                                             '/boot/vmlinuz-4.20.7-sunxi')
650         dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
651         dtb_path = self.extract_from_deb(deb_path, dtb_path)
652         rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/'
653                       'kci-2019.02/armel/base/rootfs.ext2.xz')
654         rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061'
655         rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
656         rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
657         archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
658         image_pow2ceil_expand(rootfs_path)
659
660         self.vm.set_console()
661         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
662                                'console=ttyS0,115200 '
663                                'root=/dev/mmcblk0 rootwait rw '
664                                'panic=-1 noreboot')
665         self.vm.add_args('-kernel', kernel_path,
666                          '-dtb', dtb_path,
667                          '-drive', 'file=' + rootfs_path + ',if=sd,format=raw',
668                          '-append', kernel_command_line,
669                          '-no-reboot')
670         self.vm.launch()
671         shell_ready = "/bin/sh: can't access tty; job control turned off"
672         self.wait_for_console_pattern(shell_ready)
673
674         exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
675                                                 'Allwinner sun8i Family')
676         exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
677                                                 'mmcblk0')
678         exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
679                                                  'eth0: Link is Up')
680         exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
681             'udhcpc: lease of 10.0.2.15 obtained')
682         exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
683             '3 packets transmitted, 3 packets received, 0% packet loss')
684         exec_command_and_wait_for_pattern(self, 'reboot',
685                                                 'reboot: Restarting system')
686         # Wait for VM to shut down gracefully
687         self.vm.wait()
688
689     @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
690     @skipUnless(P7ZIP_AVAILABLE, '7z not installed')
691     def test_arm_orangepi_bionic(self):
692         """
693         :avocado: tags=arch:arm
694         :avocado: tags=machine:orangepi-pc
695         :avocado: tags=device:sd
696         """
697
698         # This test download a 196MB compressed image and expand it to 1GB
699         image_url = ('https://dl.armbian.com/orangepipc/archive/'
700                      'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
701         image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e'
702         image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash)
703         image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
704         image_path = os.path.join(self.workdir, image_name)
705         process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
706         image_pow2ceil_expand(image_path)
707
708         self.vm.set_console()
709         self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
710                          '-nic', 'user',
711                          '-no-reboot')
712         self.vm.launch()
713
714         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
715                                'console=ttyS0,115200 '
716                                'loglevel=7 '
717                                'nosmp '
718                                'systemd.default_timeout_start_sec=9000 '
719                                'systemd.mask=armbian-zram-config.service '
720                                'systemd.mask=armbian-ramlog.service')
721
722         self.wait_for_console_pattern('U-Boot SPL')
723         self.wait_for_console_pattern('Autoboot in ')
724         exec_command_and_wait_for_pattern(self, ' ', '=>')
725         exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
726                                                 kernel_command_line + "'", '=>')
727         exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
728
729         self.wait_for_console_pattern('systemd[1]: Set hostname ' +
730                                       'to <orangepipc>')
731         self.wait_for_console_pattern('Starting Load Kernel Modules...')
732
733     @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
734     def test_arm_orangepi_uboot_netbsd9(self):
735         """
736         :avocado: tags=arch:arm
737         :avocado: tags=machine:orangepi-pc
738         :avocado: tags=device:sd
739         """
740         # This test download a 304MB compressed image and expand it to 2GB
741         deb_url = ('http://snapshot.debian.org/archive/debian/'
742                    '20200108T145233Z/pool/main/u/u-boot/'
743                    'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb')
744         deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99'
745         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
746         # We use the common OrangePi PC 'plus' build of U-Boot for our secondary
747         # program loader (SPL). We will then set the path to the more specific
748         # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt,
749         # before to boot NetBSD.
750         uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
751         uboot_path = self.extract_from_deb(deb_path, uboot_path)
752         image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/'
753                      'evbarm-earmv7hf/binary/gzimg/armv7.img.gz')
754         image_hash = '2babb29d36d8360adcb39c09e31060945259917a'
755         image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
756         image_path = os.path.join(self.workdir, 'armv7.img')
757         archive.gzip_uncompress(image_path_gz, image_path)
758         image_pow2ceil_expand(image_path)
759         image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
760
761         # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc
762         with open(uboot_path, 'rb') as f_in:
763             with open(image_path, 'r+b') as f_out:
764                 f_out.seek(8 * 1024)
765                 shutil.copyfileobj(f_in, f_out)
766
767         self.vm.set_console()
768         self.vm.add_args('-nic', 'user',
769                          '-drive', image_drive_args,
770                          '-global', 'allwinner-rtc.base-year=2000',
771                          '-no-reboot')
772         self.vm.launch()
773         wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
774         interrupt_interactive_console_until_pattern(self,
775                                        'Hit any key to stop autoboot:',
776                                        'switch to partitions #0, OK')
777
778         exec_command_and_wait_for_pattern(self, '', '=>')
779         cmd = 'setenv bootargs root=ld0a'
780         exec_command_and_wait_for_pattern(self, cmd, '=>')
781         cmd = 'setenv kernel netbsd-GENERIC.ub'
782         exec_command_and_wait_for_pattern(self, cmd, '=>')
783         cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
784         exec_command_and_wait_for_pattern(self, cmd, '=>')
785         cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
786                "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
787                "fdt addr ${fdt_addr_r}; "
788                "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
789         exec_command_and_wait_for_pattern(self, cmd, '=>')
790
791         exec_command_and_wait_for_pattern(self, 'boot',
792                                           'Booting kernel from Legacy Image')
793         wait_for_console_pattern(self, 'Starting kernel ...')
794         wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
795         # Wait for user-space
796         wait_for_console_pattern(self, 'Starting root file system check')
797
798     def test_s390x_s390_ccw_virtio(self):
799         """
800         :avocado: tags=arch:s390x
801         :avocado: tags=machine:s390-ccw-virtio
802         """
803         kernel_url = ('https://archives.fedoraproject.org/pub/archive'
804                       '/fedora-secondary/releases/29/Everything/s390x/os/images'
805                       '/kernel.img')
806         kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
807         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
808
809         self.vm.set_console()
810         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
811         self.vm.add_args('-nodefaults',
812                          '-kernel', kernel_path,
813                          '-append', kernel_command_line)
814         self.vm.launch()
815         console_pattern = 'Kernel command line: %s' % kernel_command_line
816         self.wait_for_console_pattern(console_pattern)
817
818     def test_alpha_clipper(self):
819         """
820         :avocado: tags=arch:alpha
821         :avocado: tags=machine:clipper
822         """
823         kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
824                       'installer-alpha/20090123lenny10/images/cdrom/vmlinuz')
825         kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
826         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
827
828         uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
829
830         self.vm.set_console()
831         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
832         self.vm.add_args('-nodefaults',
833                          '-kernel', uncompressed_kernel,
834                          '-append', kernel_command_line)
835         self.vm.launch()
836         console_pattern = 'Kernel command line: %s' % kernel_command_line
837         self.wait_for_console_pattern(console_pattern)
838
839     def test_ppc64_pseries(self):
840         """
841         :avocado: tags=arch:ppc64
842         :avocado: tags=machine:pseries
843         """
844         kernel_url = ('https://archives.fedoraproject.org/pub/archive'
845                       '/fedora-secondary/releases/29/Everything/ppc64le/os'
846                       '/ppc/ppc64/vmlinuz')
847         kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
848         kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
849
850         self.vm.set_console()
851         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
852         self.vm.add_args('-kernel', kernel_path,
853                          '-append', kernel_command_line)
854         self.vm.launch()
855         console_pattern = 'Kernel command line: %s' % kernel_command_line
856         self.wait_for_console_pattern(console_pattern)
857
858     def test_m68k_q800(self):
859         """
860         :avocado: tags=arch:m68k
861         :avocado: tags=machine:q800
862         """
863         deb_url = ('https://snapshot.debian.org/archive/debian-ports'
864                    '/20191021T083923Z/pool-m68k/main'
865                    '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
866         deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
867         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
868         kernel_path = self.extract_from_deb(deb_path,
869                                             '/boot/vmlinux-5.3.0-1-m68k')
870
871         self.vm.set_console()
872         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
873                                'console=ttyS0 vga=off')
874         self.vm.add_args('-kernel', kernel_path,
875                          '-append', kernel_command_line)
876         self.vm.launch()
877         console_pattern = 'Kernel command line: %s' % kernel_command_line
878         self.wait_for_console_pattern(console_pattern)
879         console_pattern = 'No filesystem could mount root'
880         self.wait_for_console_pattern(console_pattern)
881
882     def do_test_advcal_2018(self, day, tar_hash, kernel_name, console=0):
883         tar_url = ('https://www.qemu-advent-calendar.org'
884                    '/2018/download/day' + day + '.tar.xz')
885         file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
886         archive.extract(file_path, self.workdir)
887         self.vm.set_console(console_index=console)
888         self.vm.add_args('-kernel',
889                          self.workdir + '/day' + day + '/' + kernel_name)
890         self.vm.launch()
891         self.wait_for_console_pattern('QEMU advent calendar')
892
893     def test_arm_vexpressa9(self):
894         """
895         :avocado: tags=arch:arm
896         :avocado: tags=machine:vexpress-a9
897         """
898         tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b'
899         self.vm.add_args('-dtb', self.workdir + '/day16/vexpress-v2p-ca9.dtb')
900         self.do_test_advcal_2018('16', tar_hash, 'winter.zImage')
901
902     def test_m68k_mcf5208evb(self):
903         """
904         :avocado: tags=arch:m68k
905         :avocado: tags=machine:mcf5208evb
906         """
907         tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c'
908         self.do_test_advcal_2018('07', tar_hash, 'sanity-clause.elf')
909
910     def test_microblaze_s3adsp1800(self):
911         """
912         :avocado: tags=arch:microblaze
913         :avocado: tags=machine:petalogix-s3adsp1800
914         """
915         tar_hash = '08bf3e3bfb6b6c7ce1e54ab65d54e189f2caf13f'
916         self.do_test_advcal_2018('17', tar_hash, 'ballerina.bin')
917
918     def test_or1k_sim(self):
919         """
920         :avocado: tags=arch:or1k
921         :avocado: tags=machine:or1k-sim
922         """
923         tar_hash = '20334cdaf386108c530ff0badaecc955693027dd'
924         self.do_test_advcal_2018('20', tar_hash, 'vmlinux')
925
926     def test_nios2_10m50(self):
927         """
928         :avocado: tags=arch:nios2
929         :avocado: tags=machine:10m50-ghrd
930         """
931         tar_hash = 'e4251141726c412ac0407c5a6bceefbbff018918'
932         self.do_test_advcal_2018('14', tar_hash, 'vmlinux.elf')
933
934     def test_ppc64_e500(self):
935         """
936         :avocado: tags=arch:ppc64
937         :avocado: tags=machine:ppce500
938         """
939         tar_hash = '6951d86d644b302898da2fd701739c9406527fe1'
940         self.vm.add_args('-cpu', 'e5500')
941         self.do_test_advcal_2018('19', tar_hash, 'uImage')
942
943     def test_ppc_g3beige(self):
944         """
945         :avocado: tags=arch:ppc
946         :avocado: tags=machine:g3beige
947         """
948         tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
949         self.vm.add_args('-M', 'graphics=off')
950         self.do_test_advcal_2018('15', tar_hash, 'invaders.elf')
951
952     def test_ppc_mac99(self):
953         """
954         :avocado: tags=arch:ppc
955         :avocado: tags=machine:mac99
956         """
957         tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
958         self.vm.add_args('-M', 'graphics=off')
959         self.do_test_advcal_2018('15', tar_hash, 'invaders.elf')
960
961     def test_sh4_r2d(self):
962         """
963         :avocado: tags=arch:sh4
964         :avocado: tags=machine:r2d
965         """
966         tar_hash = 'fe06a4fd8ccbf2e27928d64472939d47829d4c7e'
967         self.vm.add_args('-append', 'console=ttySC1')
968         self.do_test_advcal_2018('09', tar_hash, 'zImage', console=1)
969
970     def test_sparc_ss20(self):
971         """
972         :avocado: tags=arch:sparc
973         :avocado: tags=machine:SS-20
974         """
975         tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f'
976         self.do_test_advcal_2018('11', tar_hash, 'zImage.elf')
977
978     def test_xtensa_lx60(self):
979         """
980         :avocado: tags=arch:xtensa
981         :avocado: tags=machine:lx60
982         """
983         tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34'
984         self.vm.add_args('-cpu', 'dc233c')
985         self.do_test_advcal_2018('02', tar_hash, 'santas-sleigh-ride.elf')
This page took 0.084805 seconds and 4 git commands to generate.