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