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
11import os
12import lzma
13import gzip
14import shutil
15
16from avocado import skip
17from avocado import skipUnless
18from avocado_qemu import QemuSystemTest
19from avocado_qemu import exec_command
20from avocado_qemu import exec_command_and_wait_for_pattern
21from avocado_qemu import interrupt_interactive_console_until_pattern
22from avocado_qemu import wait_for_console_pattern
23from avocado.utils import process
24from avocado.utils import archive
25
26"""
27Round up to next power of 2
28"""
29def pow2ceil(x):
30    return 1 if x == 0 else 2**(x - 1).bit_length()
31
32"""
33Expand file size to next power of 2
34"""
35def image_pow2ceil_expand(path):
36        size = os.path.getsize(path)
37        size_aligned = pow2ceil(size)
38        if size != size_aligned:
39            with open(path, 'ab+') as fd:
40                fd.truncate(size_aligned)
41
42class LinuxKernelTest(QemuSystemTest):
43    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
44
45    def wait_for_console_pattern(self, success_message, vm=None):
46        wait_for_console_pattern(self, success_message,
47                                 failure_message='Kernel panic - not syncing',
48                                 vm=vm)
49
50    def extract_from_deb(self, deb, path):
51        """
52        Extracts a file from a deb package into the test workdir
53
54        :param deb: path to the deb archive
55        :param path: path within the deb archive of the file to be extracted
56        :returns: path of the extracted file
57        """
58        cwd = os.getcwd()
59        os.chdir(self.workdir)
60        file_path = process.run("ar t %s" % deb).stdout_text.split()[2]
61        process.run("ar x %s %s" % (deb, file_path))
62        archive.extract(file_path, self.workdir)
63        os.chdir(cwd)
64        # Return complete path to extracted file.  Because callers to
65        # extract_from_deb() specify 'path' with a leading slash, it is
66        # necessary to use os.path.relpath() as otherwise os.path.join()
67        # interprets it as an absolute path and drops the self.workdir part.
68        return os.path.normpath(os.path.join(self.workdir,
69                                             os.path.relpath(path, '/')))
70
71    def extract_from_rpm(self, rpm, path):
72        """
73        Extracts a file from an RPM package into the test workdir.
74
75        :param rpm: path to the rpm archive
76        :param path: path within the rpm archive of the file to be extracted
77                     needs to be a relative path (starting with './') because
78                     cpio(1), which is used to extract the file, expects that.
79        :returns: path of the extracted file
80        """
81        cwd = os.getcwd()
82        os.chdir(self.workdir)
83        process.run("rpm2cpio %s | cpio -id %s" % (rpm, path), shell=True)
84        os.chdir(cwd)
85        return os.path.normpath(os.path.join(self.workdir, path))
86
87class BootLinuxConsole(LinuxKernelTest):
88    """
89    Boots a Linux kernel and checks that the console is operational and the
90    kernel command line is properly passed from QEMU to the kernel
91    """
92    timeout = 90
93
94    def test_x86_64_pc(self):
95        """
96        :avocado: tags=arch:x86_64
97        :avocado: tags=machine:pc
98        """
99        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
100                      '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
101                      '/vmlinuz')
102        kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
103        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
104
105        self.vm.set_console()
106        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
107        self.vm.add_args('-kernel', kernel_path,
108                         '-append', kernel_command_line)
109        self.vm.launch()
110        console_pattern = 'Kernel command line: %s' % kernel_command_line
111        self.wait_for_console_pattern(console_pattern)
112
113    def test_mips_malta(self):
114        """
115        :avocado: tags=arch:mips
116        :avocado: tags=machine:malta
117        :avocado: tags=endian:big
118        """
119        deb_url = ('http://snapshot.debian.org/archive/debian/'
120                   '20130217T032700Z/pool/main/l/linux-2.6/'
121                   'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
122        deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
123        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
124        kernel_path = self.extract_from_deb(deb_path,
125                                            '/boot/vmlinux-2.6.32-5-4kc-malta')
126
127        self.vm.set_console()
128        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
129        self.vm.add_args('-kernel', kernel_path,
130                         '-append', kernel_command_line)
131        self.vm.launch()
132        console_pattern = 'Kernel command line: %s' % kernel_command_line
133        self.wait_for_console_pattern(console_pattern)
134
135    def test_mips64el_malta(self):
136        """
137        This test requires the ar tool to extract "data.tar.gz" from
138        the Debian package.
139
140        The kernel can be rebuilt using this Debian kernel source [1] and
141        following the instructions on [2].
142
143        [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
144            #linux-source-2.6.32_2.6.32-48
145        [2] https://kernel-team.pages.debian.net/kernel-handbook/
146            ch-common-tasks.html#s-common-official
147
148        :avocado: tags=arch:mips64el
149        :avocado: tags=machine:malta
150        """
151        deb_url = ('http://snapshot.debian.org/archive/debian/'
152                   '20130217T032700Z/pool/main/l/linux-2.6/'
153                   'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
154        deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
155        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
156        kernel_path = self.extract_from_deb(deb_path,
157                                            '/boot/vmlinux-2.6.32-5-5kc-malta')
158
159        self.vm.set_console()
160        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
161        self.vm.add_args('-kernel', kernel_path,
162                         '-append', kernel_command_line)
163        self.vm.launch()
164        console_pattern = 'Kernel command line: %s' % kernel_command_line
165        self.wait_for_console_pattern(console_pattern)
166
167    def test_mips64el_fuloong2e(self):
168        """
169        :avocado: tags=arch:mips64el
170        :avocado: tags=machine:fuloong2e
171        :avocado: tags=endian:little
172        """
173        deb_url = ('http://archive.debian.org/debian/pool/main/l/linux/'
174                   'linux-image-3.16.0-6-loongson-2e_3.16.56-1+deb8u1_mipsel.deb')
175        deb_hash = 'd04d446045deecf7b755ef576551de0c4184dd44'
176        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
177        kernel_path = self.extract_from_deb(deb_path,
178                                            '/boot/vmlinux-3.16.0-6-loongson-2e')
179
180        self.vm.set_console()
181        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
182        self.vm.add_args('-kernel', kernel_path,
183                         '-append', kernel_command_line)
184        self.vm.launch()
185        console_pattern = 'Kernel command line: %s' % kernel_command_line
186        self.wait_for_console_pattern(console_pattern)
187
188    def test_mips_malta_cpio(self):
189        """
190        :avocado: tags=arch:mips
191        :avocado: tags=machine:malta
192        :avocado: tags=endian:big
193        """
194        deb_url = ('http://snapshot.debian.org/archive/debian/'
195                   '20160601T041800Z/pool/main/l/linux/'
196                   'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
197        deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
198        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
199        kernel_path = self.extract_from_deb(deb_path,
200                                            '/boot/vmlinux-4.5.0-2-4kc-malta')
201        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
202                      '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
203                      'mips/rootfs.cpio.gz')
204        initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
205        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
206        initrd_path = self.workdir + "rootfs.cpio"
207        archive.gzip_uncompress(initrd_path_gz, initrd_path)
208
209        self.vm.set_console()
210        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
211                               + 'console=ttyS0 console=tty '
212                               + 'rdinit=/sbin/init noreboot')
213        self.vm.add_args('-kernel', kernel_path,
214                         '-initrd', initrd_path,
215                         '-append', kernel_command_line,
216                         '-no-reboot')
217        self.vm.launch()
218        self.wait_for_console_pattern('Boot successful.')
219
220        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
221                                                'BogoMIPS')
222        exec_command_and_wait_for_pattern(self, 'uname -a',
223                                                'Debian')
224        exec_command_and_wait_for_pattern(self, 'reboot',
225                                                'reboot: Restarting system')
226        # Wait for VM to shut down gracefully
227        self.vm.wait()
228
229    @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
230    def test_mips64el_malta_5KEc_cpio(self):
231        """
232        :avocado: tags=arch:mips64el
233        :avocado: tags=machine:malta
234        :avocado: tags=endian:little
235        :avocado: tags=cpu:5KEc
236        """
237        kernel_url = ('https://github.com/philmd/qemu-testing-blob/'
238                      'raw/9ad2df38/mips/malta/mips64el/'
239                      'vmlinux-3.19.3.mtoman.20150408')
240        kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754'
241        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
242        initrd_url = ('https://github.com/groeck/linux-build-test/'
243                      'raw/8584a59e/rootfs/'
244                      'mipsel64/rootfs.mipsel64r1.cpio.gz')
245        initrd_hash = '1dbb8a396e916847325284dbe2151167'
246        initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5',
247                                          asset_hash=initrd_hash)
248        initrd_path = self.workdir + "rootfs.cpio"
249        archive.gzip_uncompress(initrd_path_gz, initrd_path)
250
251        self.vm.set_console()
252        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
253                               + 'console=ttyS0 console=tty '
254                               + 'rdinit=/sbin/init noreboot')
255        self.vm.add_args('-kernel', kernel_path,
256                         '-initrd', initrd_path,
257                         '-append', kernel_command_line,
258                         '-no-reboot')
259        self.vm.launch()
260        wait_for_console_pattern(self, 'Boot successful.')
261
262        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
263                                                'MIPS 5KE')
264        exec_command_and_wait_for_pattern(self, 'uname -a',
265                                                '3.19.3.mtoman.20150408')
266        exec_command_and_wait_for_pattern(self, 'reboot',
267                                                'reboot: Restarting system')
268        # Wait for VM to shut down gracefully
269        self.vm.wait()
270
271    def do_test_mips_malta32el_nanomips(self, kernel_url, kernel_hash):
272        kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
273        kernel_path = self.workdir + "kernel"
274        with lzma.open(kernel_path_xz, 'rb') as f_in:
275            with open(kernel_path, 'wb') as f_out:
276                shutil.copyfileobj(f_in, f_out)
277
278        self.vm.set_console()
279        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
280                               + 'mem=256m@@0x0 '
281                               + 'console=ttyS0')
282        self.vm.add_args('-no-reboot',
283                         '-kernel', kernel_path,
284                         '-append', kernel_command_line)
285        self.vm.launch()
286        console_pattern = 'Kernel command line: %s' % kernel_command_line
287        self.wait_for_console_pattern(console_pattern)
288
289    def test_mips_malta32el_nanomips_4k(self):
290        """
291        :avocado: tags=arch:mipsel
292        :avocado: tags=machine:malta
293        :avocado: tags=endian:little
294        :avocado: tags=cpu:I7200
295        """
296        kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
297                      'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
298                      'generic_nano32r6el_page4k.xz')
299        kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
300        self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
301
302    def test_mips_malta32el_nanomips_16k_up(self):
303        """
304        :avocado: tags=arch:mipsel
305        :avocado: tags=machine:malta
306        :avocado: tags=endian:little
307        :avocado: tags=cpu:I7200
308        """
309        kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
310                      'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
311                      'generic_nano32r6el_page16k_up.xz')
312        kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
313        self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
314
315    def test_mips_malta32el_nanomips_64k_dbg(self):
316        """
317        :avocado: tags=arch:mipsel
318        :avocado: tags=machine:malta
319        :avocado: tags=endian:little
320        :avocado: tags=cpu:I7200
321        """
322        kernel_url = ('https://mipsdistros.mips.com/LinuxDistro/nanomips/'
323                      'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
324                      'generic_nano32r6el_page64k_dbg.xz')
325        kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
326        self.do_test_mips_malta32el_nanomips(kernel_url, kernel_hash)
327
328    def test_aarch64_xlnx_versal_virt(self):
329        """
330        :avocado: tags=arch:aarch64
331        :avocado: tags=machine:xlnx-versal-virt
332        :avocado: tags=device:pl011
333        :avocado: tags=device:arm_gicv3
334        :avocado: tags=accel:tcg
335        """
336        images_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/'
337                      'bionic-updates/main/installer-arm64/'
338                      '20101020ubuntu543.19/images/')
339        kernel_url = images_url + 'netboot/ubuntu-installer/arm64/linux'
340        kernel_hash = 'e167757620640eb26de0972f578741924abb3a82'
341        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
342
343        initrd_url = images_url + 'netboot/ubuntu-installer/arm64/initrd.gz'
344        initrd_hash = 'cab5cb3fcefca8408aa5aae57f24574bfce8bdb9'
345        initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
346
347        self.vm.set_console()
348        self.vm.add_args('-m', '2G',
349                         '-accel', 'tcg',
350                         '-kernel', kernel_path,
351                         '-initrd', initrd_path)
352        self.vm.launch()
353        self.wait_for_console_pattern('Checked W+X mappings: passed')
354
355    def test_arm_virt(self):
356        """
357        :avocado: tags=arch:arm
358        :avocado: tags=machine:virt
359        :avocado: tags=accel:tcg
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        :avocado: tags=accel:tcg
383        """
384        self.require_netdev('user')
385
386        uboot_url = ('https://raw.githubusercontent.com/'
387                     'Subbaraya-Sundeep/qemu-test-binaries/'
388                     'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot')
389        uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2'
390        uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
391        spi_url = ('https://raw.githubusercontent.com/'
392                   'Subbaraya-Sundeep/qemu-test-binaries/'
393                   'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin')
394        spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501'
395        spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
396
397        self.vm.set_console()
398        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
399        self.vm.add_args('-kernel', uboot_path,
400                         '-append', kernel_command_line,
401                         '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
402                         '-no-reboot')
403        self.vm.launch()
404        self.wait_for_console_pattern('Enter \'help\' for a list')
405
406        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15',
407                                                 'eth0: link becomes ready')
408        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
409            '3 packets transmitted, 3 packets received, 0% packet loss')
410
411    def do_test_arm_raspi2(self, uart_id):
412        """
413        :avocado: tags=accel:tcg
414
415        The kernel can be rebuilt using the kernel source referenced
416        and following the instructions on the on:
417        https://www.raspberrypi.org/documentation/linux/kernel/building.md
418        """
419        serial_kernel_cmdline = {
420            0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
421        }
422        deb_url = ('http://archive.raspberrypi.org/debian/'
423                   'pool/main/r/raspberrypi-firmware/'
424                   'raspberrypi-kernel_1.20190215-1_armhf.deb')
425        deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
426        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
427        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
428        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
429
430        self.vm.set_console()
431        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
432                               serial_kernel_cmdline[uart_id] +
433                               ' root=/dev/mmcblk0p2 rootwait ' +
434                               'dwc_otg.fiq_fsm_enable=0')
435        self.vm.add_args('-kernel', kernel_path,
436                         '-dtb', dtb_path,
437                         '-append', kernel_command_line,
438                         '-device', 'usb-kbd')
439        self.vm.launch()
440        console_pattern = 'Kernel command line: %s' % kernel_command_line
441        self.wait_for_console_pattern(console_pattern)
442        console_pattern = 'Product: QEMU USB Keyboard'
443        self.wait_for_console_pattern(console_pattern)
444
445    def test_arm_raspi2_uart0(self):
446        """
447        :avocado: tags=arch:arm
448        :avocado: tags=machine:raspi2b
449        :avocado: tags=device:pl011
450        :avocado: tags=accel:tcg
451        """
452        self.do_test_arm_raspi2(0)
453
454    def test_arm_raspi2_initrd(self):
455        """
456        :avocado: tags=arch:arm
457        :avocado: tags=machine:raspi2b
458        """
459        deb_url = ('http://archive.raspberrypi.org/debian/'
460                   'pool/main/r/raspberrypi-firmware/'
461                   'raspberrypi-kernel_1.20190215-1_armhf.deb')
462        deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
463        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
464        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
465        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
466
467        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
468                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
469                      'arm/rootfs-armv7a.cpio.gz')
470        initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
471        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
472        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
473        archive.gzip_uncompress(initrd_path_gz, initrd_path)
474
475        self.vm.set_console()
476        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
477                               'earlycon=pl011,0x3f201000 console=ttyAMA0 '
478                               'panic=-1 noreboot ' +
479                               'dwc_otg.fiq_fsm_enable=0')
480        self.vm.add_args('-kernel', kernel_path,
481                         '-dtb', dtb_path,
482                         '-initrd', initrd_path,
483                         '-append', kernel_command_line,
484                         '-no-reboot')
485        self.vm.launch()
486        self.wait_for_console_pattern('Boot successful.')
487
488        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
489                                                'BCM2835')
490        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
491                                                '/soc/cprman@7e101000')
492        exec_command(self, 'halt')
493        # Wait for VM to shut down gracefully
494        self.vm.wait()
495
496    def test_arm_exynos4210_initrd(self):
497        """
498        :avocado: tags=arch:arm
499        :avocado: tags=machine:smdkc210
500        :avocado: tags=accel:tcg
501        """
502        deb_url = ('https://snapshot.debian.org/archive/debian/'
503                   '20190928T224601Z/pool/main/l/linux/'
504                   'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb')
505        deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82'
506        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
507        kernel_path = self.extract_from_deb(deb_path,
508                                            '/boot/vmlinuz-4.19.0-6-armmp')
509        dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb'
510        dtb_path = self.extract_from_deb(deb_path, dtb_path)
511
512        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
513                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
514                      'arm/rootfs-armv5.cpio.gz')
515        initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
516        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
517        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
518        archive.gzip_uncompress(initrd_path_gz, initrd_path)
519
520        self.vm.set_console()
521        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
522                               'earlycon=exynos4210,0x13800000 earlyprintk ' +
523                               'console=ttySAC0,115200n8 ' +
524                               'random.trust_cpu=off cryptomgr.notests ' +
525                               'cpuidle.off=1 panic=-1 noreboot')
526
527        self.vm.add_args('-kernel', kernel_path,
528                         '-dtb', dtb_path,
529                         '-initrd', initrd_path,
530                         '-append', kernel_command_line,
531                         '-no-reboot')
532        self.vm.launch()
533
534        self.wait_for_console_pattern('Boot successful.')
535        # TODO user command, for now the uart is stuck
536
537    def test_arm_cubieboard_initrd(self):
538        """
539        :avocado: tags=arch:arm
540        :avocado: tags=machine:cubieboard
541        :avocado: tags=accel:tcg
542        """
543        deb_url = ('https://apt.armbian.com/pool/main/l/'
544                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
545        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
546        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
547        kernel_path = self.extract_from_deb(deb_path,
548                                            '/boot/vmlinuz-5.10.16-sunxi')
549        dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb'
550        dtb_path = self.extract_from_deb(deb_path, dtb_path)
551        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
552                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
553                      'arm/rootfs-armv5.cpio.gz')
554        initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
555        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
556        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
557        archive.gzip_uncompress(initrd_path_gz, initrd_path)
558
559        self.vm.set_console()
560        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
561                               'console=ttyS0,115200 '
562                               'usbcore.nousb '
563                               'panic=-1 noreboot')
564        self.vm.add_args('-kernel', kernel_path,
565                         '-dtb', dtb_path,
566                         '-initrd', initrd_path,
567                         '-append', kernel_command_line,
568                         '-no-reboot')
569        self.vm.launch()
570        self.wait_for_console_pattern('Boot successful.')
571
572        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
573                                                'Allwinner sun4i/sun5i')
574        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
575                                                'system-control@1c00000')
576        # cubieboard's reboot is not functioning; omit reboot test.
577
578    def test_arm_cubieboard_sata(self):
579        """
580        :avocado: tags=arch:arm
581        :avocado: tags=machine:cubieboard
582        :avocado: tags=accel:tcg
583        """
584        deb_url = ('https://apt.armbian.com/pool/main/l/'
585                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
586        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
587        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
588        kernel_path = self.extract_from_deb(deb_path,
589                                            '/boot/vmlinuz-5.10.16-sunxi')
590        dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb'
591        dtb_path = self.extract_from_deb(deb_path, dtb_path)
592        rootfs_url = ('https://github.com/groeck/linux-build-test/raw/'
593                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
594                      'arm/rootfs-armv5.ext2.gz')
595        rootfs_hash = '093e89d2b4d982234bf528bc9fb2f2f17a9d1f93'
596        rootfs_path_gz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
597        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
598        archive.gzip_uncompress(rootfs_path_gz, rootfs_path)
599
600        self.vm.set_console()
601        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
602                               'console=ttyS0,115200 '
603                               'usbcore.nousb '
604                               'root=/dev/sda ro '
605                               'panic=-1 noreboot')
606        self.vm.add_args('-kernel', kernel_path,
607                         '-dtb', dtb_path,
608                         '-drive', 'if=none,format=raw,id=disk0,file='
609                                   + rootfs_path,
610                         '-device', 'ide-hd,bus=ide.0,drive=disk0',
611                         '-append', kernel_command_line,
612                         '-no-reboot')
613        self.vm.launch()
614        self.wait_for_console_pattern('Boot successful.')
615
616        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
617                                                'Allwinner sun4i/sun5i')
618        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
619                                                'sda')
620        # cubieboard's reboot is not functioning; omit reboot test.
621
622    @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
623    def test_arm_quanta_gsj(self):
624        """
625        :avocado: tags=arch:arm
626        :avocado: tags=machine:quanta-gsj
627        :avocado: tags=accel:tcg
628        """
629        # 25 MiB compressed, 32 MiB uncompressed.
630        image_url = (
631                'https://github.com/hskinnemoen/openbmc/releases/download/'
632                '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz')
633        image_hash = '14895e634923345cb5c8776037ff7876df96f6b1'
634        image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
635        image_name = 'obmc.mtd'
636        image_path = os.path.join(self.workdir, image_name)
637        archive.gzip_uncompress(image_path_gz, image_path)
638
639        self.vm.set_console()
640        drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
641        self.vm.add_args('-drive', drive_args)
642        self.vm.launch()
643
644        # Disable drivers and services that stall for a long time during boot,
645        # to avoid running past the 90-second timeout. These may be removed
646        # as the corresponding device support is added.
647        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + (
648                'console=${console} '
649                'mem=${mem} '
650                'initcall_blacklist=npcm_i2c_bus_driver_init '
651                'systemd.mask=systemd-random-seed.service '
652                'systemd.mask=dropbearkey.service '
653        )
654
655        self.wait_for_console_pattern('> BootBlock by Nuvoton')
656        self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
657        self.wait_for_console_pattern('>Skip DDR init.')
658        self.wait_for_console_pattern('U-Boot ')
659        interrupt_interactive_console_until_pattern(
660                self, 'Hit any key to stop autoboot:', 'U-Boot>')
661        exec_command_and_wait_for_pattern(
662                self, "setenv bootargs ${bootargs} " + kernel_command_line,
663                'U-Boot>')
664        exec_command_and_wait_for_pattern(
665                self, 'run romboot', 'Booting Kernel from flash')
666        self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
667        self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
668        self.wait_for_console_pattern('OpenBMC Project Reference Distro')
669        self.wait_for_console_pattern('gsj login:')
670
671    def test_arm_quanta_gsj_initrd(self):
672        """
673        :avocado: tags=arch:arm
674        :avocado: tags=machine:quanta-gsj
675        :avocado: tags=accel:tcg
676        """
677        initrd_url = (
678                'https://github.com/hskinnemoen/openbmc/releases/download/'
679                '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz')
680        initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300'
681        initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
682        kernel_url = (
683                'https://github.com/hskinnemoen/openbmc/releases/download/'
684                '20200711-gsj-qemu-0/uImage-gsj.bin')
685        kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7'
686        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
687        dtb_url = (
688                'https://github.com/hskinnemoen/openbmc/releases/download/'
689                '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb')
690        dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4'
691        dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash)
692
693        self.vm.set_console()
694        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
695                               'console=ttyS0,115200n8 '
696                               'earlycon=uart8250,mmio32,0xf0001000')
697        self.vm.add_args('-kernel', kernel_path,
698                         '-initrd', initrd_path,
699                         '-dtb', dtb_path,
700                         '-append', kernel_command_line)
701        self.vm.launch()
702
703        self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
704        self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
705        self.wait_for_console_pattern(
706                'Give root password for system maintenance')
707
708    def test_arm_orangepi(self):
709        """
710        :avocado: tags=arch:arm
711        :avocado: tags=machine:orangepi-pc
712        :avocado: tags=accel:tcg
713        """
714        deb_url = ('https://apt.armbian.com/pool/main/l/'
715                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
716        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
717        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
718        kernel_path = self.extract_from_deb(deb_path,
719                                            '/boot/vmlinuz-5.10.16-sunxi')
720        dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb'
721        dtb_path = self.extract_from_deb(deb_path, dtb_path)
722
723        self.vm.set_console()
724        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
725                               'console=ttyS0,115200n8 '
726                               'earlycon=uart,mmio32,0x1c28000')
727        self.vm.add_args('-kernel', kernel_path,
728                         '-dtb', dtb_path,
729                         '-append', kernel_command_line)
730        self.vm.launch()
731        console_pattern = 'Kernel command line: %s' % kernel_command_line
732        self.wait_for_console_pattern(console_pattern)
733
734    def test_arm_orangepi_initrd(self):
735        """
736        :avocado: tags=arch:arm
737        :avocado: tags=accel:tcg
738        :avocado: tags=machine:orangepi-pc
739        """
740        deb_url = ('https://apt.armbian.com/pool/main/l/'
741                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
742        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
743        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
744        kernel_path = self.extract_from_deb(deb_path,
745                                            '/boot/vmlinuz-5.10.16-sunxi')
746        dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb'
747        dtb_path = self.extract_from_deb(deb_path, dtb_path)
748        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
749                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
750                      'arm/rootfs-armv7a.cpio.gz')
751        initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
752        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
753        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
754        archive.gzip_uncompress(initrd_path_gz, initrd_path)
755
756        self.vm.set_console()
757        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
758                               'console=ttyS0,115200 '
759                               'panic=-1 noreboot')
760        self.vm.add_args('-kernel', kernel_path,
761                         '-dtb', dtb_path,
762                         '-initrd', initrd_path,
763                         '-append', kernel_command_line,
764                         '-no-reboot')
765        self.vm.launch()
766        self.wait_for_console_pattern('Boot successful.')
767
768        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
769                                                'Allwinner sun8i Family')
770        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
771                                                'system-control@1c00000')
772        exec_command_and_wait_for_pattern(self, 'reboot',
773                                                'reboot: Restarting system')
774        # Wait for VM to shut down gracefully
775        self.vm.wait()
776
777    def test_arm_orangepi_sd(self):
778        """
779        :avocado: tags=arch:arm
780        :avocado: tags=accel:tcg
781        :avocado: tags=machine:orangepi-pc
782        :avocado: tags=device:sd
783        """
784        self.require_netdev('user')
785
786        deb_url = ('https://apt.armbian.com/pool/main/l/'
787                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
788        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
789        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
790        kernel_path = self.extract_from_deb(deb_path,
791                                            '/boot/vmlinuz-5.10.16-sunxi')
792        dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb'
793        dtb_path = self.extract_from_deb(deb_path, dtb_path)
794        rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/'
795                      'kci-2019.02/armel/base/rootfs.ext2.xz')
796        rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061'
797        rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
798        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
799        archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
800        image_pow2ceil_expand(rootfs_path)
801
802        self.vm.set_console()
803        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
804                               'console=ttyS0,115200 '
805                               'root=/dev/mmcblk0 rootwait rw '
806                               'panic=-1 noreboot')
807        self.vm.add_args('-kernel', kernel_path,
808                         '-dtb', dtb_path,
809                         '-drive', 'file=' + rootfs_path + ',if=sd,format=raw',
810                         '-append', kernel_command_line,
811                         '-no-reboot')
812        self.vm.launch()
813        shell_ready = "/bin/sh: can't access tty; job control turned off"
814        self.wait_for_console_pattern(shell_ready)
815
816        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
817                                                'Allwinner sun8i Family')
818        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
819                                                'mmcblk0')
820        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
821                                                 'eth0: Link is Up')
822        exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
823            'udhcpc: lease of 10.0.2.15 obtained')
824        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
825            '3 packets transmitted, 3 packets received, 0% packet loss')
826        exec_command_and_wait_for_pattern(self, 'reboot',
827                                                'reboot: Restarting system')
828        # Wait for VM to shut down gracefully
829        self.vm.wait()
830
831    @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
832    def test_arm_orangepi_bionic_20_08(self):
833        """
834        :avocado: tags=arch:arm
835        :avocado: tags=machine:orangepi-pc
836        :avocado: tags=device:sd
837        """
838
839        # This test download a 275 MiB compressed image and expand it
840        # to 1036 MiB, but the underlying filesystem is 1552 MiB...
841        # As we expand it to 2 GiB we are safe.
842
843        image_url = ('https://archive.armbian.com/orangepipc/archive/'
844                     'Armbian_20.08.1_Orangepipc_bionic_current_5.8.5.img.xz')
845        image_hash = ('b4d6775f5673486329e45a0586bf06b6'
846                      'dbe792199fd182ac6b9c7bb6c7d3e6dd')
847        image_path_xz = self.fetch_asset(image_url, asset_hash=image_hash,
848                                         algorithm='sha256')
849        image_path = archive.extract(image_path_xz, self.workdir)
850        image_pow2ceil_expand(image_path)
851
852        self.vm.set_console()
853        self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
854                         '-nic', 'user',
855                         '-no-reboot')
856        self.vm.launch()
857
858        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
859                               'console=ttyS0,115200 '
860                               'loglevel=7 '
861                               'nosmp '
862                               'systemd.default_timeout_start_sec=9000 '
863                               'systemd.mask=armbian-zram-config.service '
864                               'systemd.mask=armbian-ramlog.service')
865
866        self.wait_for_console_pattern('U-Boot SPL')
867        self.wait_for_console_pattern('Autoboot in ')
868        exec_command_and_wait_for_pattern(self, ' ', '=>')
869        exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
870                                                kernel_command_line + "'", '=>')
871        exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
872
873        self.wait_for_console_pattern('systemd[1]: Set hostname ' +
874                                      'to <orangepipc>')
875        self.wait_for_console_pattern('Starting Load Kernel Modules...')
876
877    @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
878    def test_arm_orangepi_uboot_netbsd9(self):
879        """
880        :avocado: tags=arch:arm
881        :avocado: tags=machine:orangepi-pc
882        :avocado: tags=device:sd
883        :avocado: tags=os:netbsd
884        """
885        # This test download a 304MB compressed image and expand it to 2GB
886        deb_url = ('http://snapshot.debian.org/archive/debian/'
887                   '20200108T145233Z/pool/main/u/u-boot/'
888                   'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb')
889        deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99'
890        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
891        # We use the common OrangePi PC 'plus' build of U-Boot for our secondary
892        # program loader (SPL). We will then set the path to the more specific
893        # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt,
894        # before to boot NetBSD.
895        uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
896        uboot_path = self.extract_from_deb(deb_path, uboot_path)
897        image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/'
898                     'evbarm-earmv7hf/binary/gzimg/armv7.img.gz')
899        image_hash = '2babb29d36d8360adcb39c09e31060945259917a'
900        image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
901        image_path = os.path.join(self.workdir, 'armv7.img')
902        archive.gzip_uncompress(image_path_gz, image_path)
903        image_pow2ceil_expand(image_path)
904        image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
905
906        # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc
907        with open(uboot_path, 'rb') as f_in:
908            with open(image_path, 'r+b') as f_out:
909                f_out.seek(8 * 1024)
910                shutil.copyfileobj(f_in, f_out)
911
912        self.vm.set_console()
913        self.vm.add_args('-nic', 'user',
914                         '-drive', image_drive_args,
915                         '-global', 'allwinner-rtc.base-year=2000',
916                         '-no-reboot')
917        self.vm.launch()
918        wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
919        interrupt_interactive_console_until_pattern(self,
920                                       'Hit any key to stop autoboot:',
921                                       'switch to partitions #0, OK')
922
923        exec_command_and_wait_for_pattern(self, '', '=>')
924        cmd = 'setenv bootargs root=ld0a'
925        exec_command_and_wait_for_pattern(self, cmd, '=>')
926        cmd = 'setenv kernel netbsd-GENERIC.ub'
927        exec_command_and_wait_for_pattern(self, cmd, '=>')
928        cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
929        exec_command_and_wait_for_pattern(self, cmd, '=>')
930        cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
931               "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
932               "fdt addr ${fdt_addr_r}; "
933               "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
934        exec_command_and_wait_for_pattern(self, cmd, '=>')
935
936        exec_command_and_wait_for_pattern(self, 'boot',
937                                          'Booting kernel from Legacy Image')
938        wait_for_console_pattern(self, 'Starting kernel ...')
939        wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
940        # Wait for user-space
941        wait_for_console_pattern(self, 'Starting root file system check')
942
943    def test_aarch64_raspi3_atf(self):
944        """
945        :avocado: tags=arch:aarch64
946        :avocado: tags=machine:raspi3b
947        :avocado: tags=cpu:cortex-a53
948        :avocado: tags=device:pl011
949        :avocado: tags=atf
950        """
951        zip_url = ('https://github.com/pbatard/RPi3/releases/download/'
952                   'v1.15/RPi3_UEFI_Firmware_v1.15.zip')
953        zip_hash = '74b3bd0de92683cadb14e008a7575e1d0c3cafb9'
954        zip_path = self.fetch_asset(zip_url, asset_hash=zip_hash)
955
956        archive.extract(zip_path, self.workdir)
957        efi_fd = os.path.join(self.workdir, 'RPI_EFI.fd')
958
959        self.vm.set_console(console_index=1)
960        self.vm.add_args('-nodefaults',
961                         '-device', 'loader,file=%s,force-raw=true' % efi_fd)
962        self.vm.launch()
963        self.wait_for_console_pattern('version UEFI Firmware v1.15')
964
965    def test_s390x_s390_ccw_virtio(self):
966        """
967        :avocado: tags=arch:s390x
968        :avocado: tags=machine:s390-ccw-virtio
969        """
970        kernel_url = ('https://archives.fedoraproject.org/pub/archive'
971                      '/fedora-secondary/releases/29/Everything/s390x/os/images'
972                      '/kernel.img')
973        kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
974        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
975
976        self.vm.set_console()
977        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
978        self.vm.add_args('-nodefaults',
979                         '-kernel', kernel_path,
980                         '-append', kernel_command_line)
981        self.vm.launch()
982        console_pattern = 'Kernel command line: %s' % kernel_command_line
983        self.wait_for_console_pattern(console_pattern)
984
985    def test_alpha_clipper(self):
986        """
987        :avocado: tags=arch:alpha
988        :avocado: tags=machine:clipper
989        """
990        kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
991                      'installer-alpha/20090123lenny10/images/cdrom/vmlinuz')
992        kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
993        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
994
995        uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
996
997        self.vm.set_console()
998        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
999        self.vm.add_args('-nodefaults',
1000                         '-kernel', uncompressed_kernel,
1001                         '-append', kernel_command_line)
1002        self.vm.launch()
1003        console_pattern = 'Kernel command line: %s' % kernel_command_line
1004        self.wait_for_console_pattern(console_pattern)
1005
1006    def test_m68k_q800(self):
1007        """
1008        :avocado: tags=arch:m68k
1009        :avocado: tags=machine:q800
1010        """
1011        deb_url = ('https://snapshot.debian.org/archive/debian-ports'
1012                   '/20191021T083923Z/pool-m68k/main'
1013                   '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
1014        deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
1015        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
1016        kernel_path = self.extract_from_deb(deb_path,
1017                                            '/boot/vmlinux-5.3.0-1-m68k')
1018
1019        self.vm.set_console()
1020        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
1021                               'console=ttyS0 vga=off')
1022        self.vm.add_args('-kernel', kernel_path,
1023                         '-append', kernel_command_line)
1024        self.vm.launch()
1025        console_pattern = 'Kernel command line: %s' % kernel_command_line
1026        self.wait_for_console_pattern(console_pattern)
1027        console_pattern = 'No filesystem could mount root'
1028        self.wait_for_console_pattern(console_pattern)
1029
1030    def do_test_advcal_2018(self, day, tar_hash, kernel_name, console=0):
1031        tar_url = ('https://www.qemu-advent-calendar.org'
1032                   '/2018/download/day' + day + '.tar.xz')
1033        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
1034        archive.extract(file_path, self.workdir)
1035        self.vm.set_console(console_index=console)
1036        self.vm.add_args('-kernel',
1037                         self.workdir + '/day' + day + '/' + kernel_name)
1038        self.vm.launch()
1039        self.wait_for_console_pattern('QEMU advent calendar')
1040
1041    def test_arm_vexpressa9(self):
1042        """
1043        :avocado: tags=arch:arm
1044        :avocado: tags=machine:vexpress-a9
1045        """
1046        tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b'
1047        self.vm.add_args('-dtb', self.workdir + '/day16/vexpress-v2p-ca9.dtb')
1048        self.do_test_advcal_2018('16', tar_hash, 'winter.zImage')
1049
1050    def test_arm_ast2600_debian(self):
1051        """
1052        :avocado: tags=arch:arm
1053        :avocado: tags=machine:tacoma-bmc
1054        """
1055        deb_url = ('http://snapshot.debian.org/archive/debian/'
1056                   '20210302T203551Z/'
1057                   'pool/main/l/linux/'
1058                   'linux-image-5.10.0-3-armmp_5.10.13-1_armhf.deb')
1059        deb_hash = 'db40d32fe39255d05482bea48d72467b67d6225bb2a2a4d6f618cb8976f1e09e'
1060        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash,
1061                                    algorithm='sha256')
1062        kernel_path = self.extract_from_deb(deb_path, '/boot/vmlinuz-5.10.0-3-armmp')
1063        dtb_path = self.extract_from_deb(deb_path,
1064                '/usr/lib/linux-image-5.10.0-3-armmp/aspeed-bmc-opp-tacoma.dtb')
1065
1066        self.vm.set_console()
1067        self.vm.add_args('-kernel', kernel_path,
1068                         '-dtb', dtb_path,
1069                         '-net', 'nic')
1070        self.vm.launch()
1071        self.wait_for_console_pattern("Booting Linux on physical CPU 0xf00")
1072        self.wait_for_console_pattern("SMP: Total of 2 processors activated")
1073        self.wait_for_console_pattern("No filesystem could mount root")
1074
1075    def test_m68k_mcf5208evb(self):
1076        """
1077        :avocado: tags=arch:m68k
1078        :avocado: tags=machine:mcf5208evb
1079        """
1080        tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c'
1081        self.do_test_advcal_2018('07', tar_hash, 'sanity-clause.elf')
1082
1083    def test_or1k_sim(self):
1084        """
1085        :avocado: tags=arch:or1k
1086        :avocado: tags=machine:or1k-sim
1087        """
1088        tar_hash = '20334cdaf386108c530ff0badaecc955693027dd'
1089        self.do_test_advcal_2018('20', tar_hash, 'vmlinux')
1090
1091    def test_nios2_10m50(self):
1092        """
1093        :avocado: tags=arch:nios2
1094        :avocado: tags=machine:10m50-ghrd
1095        """
1096        tar_hash = 'e4251141726c412ac0407c5a6bceefbbff018918'
1097        self.do_test_advcal_2018('14', tar_hash, 'vmlinux.elf')
1098
1099    def test_ppc64_e500(self):
1100        """
1101        :avocado: tags=arch:ppc64
1102        :avocado: tags=machine:ppce500
1103        :avocado: tags=cpu:e5500
1104        :avocado: tags=accel:tcg
1105        """
1106        self.require_accelerator("tcg")
1107        tar_hash = '6951d86d644b302898da2fd701739c9406527fe1'
1108        self.do_test_advcal_2018('19', tar_hash, 'uImage')
1109
1110    def do_test_ppc64_powernv(self, proc):
1111        self.require_accelerator("tcg")
1112        images_url = ('https://github.com/open-power/op-build/releases/download/v2.7/')
1113
1114        kernel_url = images_url + 'zImage.epapr'
1115        kernel_hash = '0ab237df661727e5392cee97460e8674057a883c5f74381a128fa772588d45cd'
1116        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash,
1117                                       algorithm='sha256')
1118        self.vm.set_console()
1119        self.vm.add_args('-kernel', kernel_path,
1120                         '-append', 'console=tty0 console=hvc0',
1121                         '-device', 'pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0',
1122                         '-device', 'nvme,bus=pcie.2,addr=0x0,serial=1234',
1123                         '-device', 'e1000e,bus=bridge1,addr=0x3',
1124                         '-device', 'nec-usb-xhci,bus=bridge1,addr=0x2')
1125        self.vm.launch()
1126
1127        self.wait_for_console_pattern("CPU: " + proc + " generation processor")
1128        self.wait_for_console_pattern("zImage starting: loaded")
1129        self.wait_for_console_pattern("Run /init as init process")
1130        self.wait_for_console_pattern("Creating 1 MTD partitions")
1131
1132    def test_ppc_powernv8(self):
1133        """
1134        :avocado: tags=arch:ppc64
1135        :avocado: tags=machine:powernv8
1136        :avocado: tags=accel:tcg
1137        """
1138        self.do_test_ppc64_powernv('P8')
1139
1140    def test_ppc_powernv9(self):
1141        """
1142        :avocado: tags=arch:ppc64
1143        :avocado: tags=machine:powernv9
1144        :avocado: tags=accel:tcg
1145        """
1146        self.do_test_ppc64_powernv('P9')
1147
1148    def test_ppc_g3beige(self):
1149        """
1150        :avocado: tags=arch:ppc
1151        :avocado: tags=machine:g3beige
1152        :avocado: tags=accel:tcg
1153        """
1154        # TODO: g3beige works with kvm_pr but we don't have a
1155        # reliable way ATM (e.g. looking at /proc/modules) to detect
1156        # whether we're running kvm_hv or kvm_pr. For now let's
1157        # disable this test if we don't have TCG support.
1158        self.require_accelerator("tcg")
1159        tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
1160        self.vm.add_args('-M', 'graphics=off')
1161        self.do_test_advcal_2018('15', tar_hash, 'invaders.elf')
1162
1163    def test_ppc_mac99(self):
1164        """
1165        :avocado: tags=arch:ppc
1166        :avocado: tags=machine:mac99
1167        :avocado: tags=accel:tcg
1168        """
1169        # TODO: mac99 works with kvm_pr but we don't have a
1170        # reliable way ATM (e.g. looking at /proc/modules) to detect
1171        # whether we're running kvm_hv or kvm_pr. For now let's
1172        # disable this test if we don't have TCG support.
1173        self.require_accelerator("tcg")
1174        tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
1175        self.vm.add_args('-M', 'graphics=off')
1176        self.do_test_advcal_2018('15', tar_hash, 'invaders.elf')
1177
1178    def test_sh4_r2d(self):
1179        """
1180        :avocado: tags=arch:sh4
1181        :avocado: tags=machine:r2d
1182        """
1183        tar_hash = 'fe06a4fd8ccbf2e27928d64472939d47829d4c7e'
1184        self.vm.add_args('-append', 'console=ttySC1')
1185        self.do_test_advcal_2018('09', tar_hash, 'zImage', console=1)
1186
1187    def test_sparc_ss20(self):
1188        """
1189        :avocado: tags=arch:sparc
1190        :avocado: tags=machine:SS-20
1191        """
1192        tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f'
1193        self.do_test_advcal_2018('11', tar_hash, 'zImage.elf')
1194
1195    def test_xtensa_lx60(self):
1196        """
1197        :avocado: tags=arch:xtensa
1198        :avocado: tags=machine:lx60
1199        :avocado: tags=cpu:dc233c
1200        """
1201        tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34'
1202        self.do_test_advcal_2018('02', tar_hash, 'santas-sleigh-ride.elf')
1203