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.15/images/')
339        kernel_url = images_url + 'netboot/ubuntu-installer/arm64/linux'
340        kernel_hash = '5bfc54cf7ed8157d93f6e5b0241e727b6dc22c50'
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 = 'd385d3e88d53e2004c5d43cbe668b458a094f772'
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        uboot_url = ('https://raw.githubusercontent.com/'
385                     'Subbaraya-Sundeep/qemu-test-binaries/'
386                     'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot')
387        uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2'
388        uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash)
389        spi_url = ('https://raw.githubusercontent.com/'
390                   'Subbaraya-Sundeep/qemu-test-binaries/'
391                   'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin')
392        spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501'
393        spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash)
394
395        self.vm.set_console()
396        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
397        self.vm.add_args('-kernel', uboot_path,
398                         '-append', kernel_command_line,
399                         '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
400                         '-no-reboot')
401        self.vm.launch()
402        self.wait_for_console_pattern('Enter \'help\' for a list')
403
404        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15',
405                                                 'eth0: link becomes ready')
406        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
407            '3 packets transmitted, 3 packets received, 0% packet loss')
408
409    def do_test_arm_raspi2(self, uart_id):
410        """
411        :avocado: tags=accel:tcg
412
413        The kernel can be rebuilt using the kernel source referenced
414        and following the instructions on the on:
415        https://www.raspberrypi.org/documentation/linux/kernel/building.md
416        """
417        serial_kernel_cmdline = {
418            0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
419        }
420        deb_url = ('http://archive.raspberrypi.org/debian/'
421                   'pool/main/r/raspberrypi-firmware/'
422                   'raspberrypi-kernel_1.20190215-1_armhf.deb')
423        deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
424        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
425        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
426        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
427
428        self.vm.set_console()
429        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
430                               serial_kernel_cmdline[uart_id] +
431                               ' root=/dev/mmcblk0p2 rootwait ' +
432                               'dwc_otg.fiq_fsm_enable=0')
433        self.vm.add_args('-kernel', kernel_path,
434                         '-dtb', dtb_path,
435                         '-append', kernel_command_line,
436                         '-device', 'usb-kbd')
437        self.vm.launch()
438        console_pattern = 'Kernel command line: %s' % kernel_command_line
439        self.wait_for_console_pattern(console_pattern)
440        console_pattern = 'Product: QEMU USB Keyboard'
441        self.wait_for_console_pattern(console_pattern)
442
443    def test_arm_raspi2_uart0(self):
444        """
445        :avocado: tags=arch:arm
446        :avocado: tags=machine:raspi2b
447        :avocado: tags=device:pl011
448        :avocado: tags=accel:tcg
449        """
450        self.do_test_arm_raspi2(0)
451
452    def test_arm_raspi2_initrd(self):
453        """
454        :avocado: tags=arch:arm
455        :avocado: tags=machine:raspi2b
456        """
457        deb_url = ('http://archive.raspberrypi.org/debian/'
458                   'pool/main/r/raspberrypi-firmware/'
459                   'raspberrypi-kernel_1.20190215-1_armhf.deb')
460        deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
461        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
462        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
463        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
464
465        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
466                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
467                      'arm/rootfs-armv7a.cpio.gz')
468        initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
469        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
470        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
471        archive.gzip_uncompress(initrd_path_gz, initrd_path)
472
473        self.vm.set_console()
474        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
475                               'earlycon=pl011,0x3f201000 console=ttyAMA0 '
476                               'panic=-1 noreboot ' +
477                               'dwc_otg.fiq_fsm_enable=0')
478        self.vm.add_args('-kernel', kernel_path,
479                         '-dtb', dtb_path,
480                         '-initrd', initrd_path,
481                         '-append', kernel_command_line,
482                         '-no-reboot')
483        self.vm.launch()
484        self.wait_for_console_pattern('Boot successful.')
485
486        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
487                                                'BCM2835')
488        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
489                                                '/soc/cprman@7e101000')
490        exec_command(self, 'halt')
491        # Wait for VM to shut down gracefully
492        self.vm.wait()
493
494    def test_arm_exynos4210_initrd(self):
495        """
496        :avocado: tags=arch:arm
497        :avocado: tags=machine:smdkc210
498        :avocado: tags=accel:tcg
499        """
500        deb_url = ('https://snapshot.debian.org/archive/debian/'
501                   '20190928T224601Z/pool/main/l/linux/'
502                   'linux-image-4.19.0-6-armmp_4.19.67-2+deb10u1_armhf.deb')
503        deb_hash = 'fa9df4a0d38936cb50084838f2cb933f570d7d82'
504        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
505        kernel_path = self.extract_from_deb(deb_path,
506                                            '/boot/vmlinuz-4.19.0-6-armmp')
507        dtb_path = '/usr/lib/linux-image-4.19.0-6-armmp/exynos4210-smdkv310.dtb'
508        dtb_path = self.extract_from_deb(deb_path, dtb_path)
509
510        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
511                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
512                      'arm/rootfs-armv5.cpio.gz')
513        initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
514        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
515        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
516        archive.gzip_uncompress(initrd_path_gz, initrd_path)
517
518        self.vm.set_console()
519        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
520                               'earlycon=exynos4210,0x13800000 earlyprintk ' +
521                               'console=ttySAC0,115200n8 ' +
522                               'random.trust_cpu=off cryptomgr.notests ' +
523                               'cpuidle.off=1 panic=-1 noreboot')
524
525        self.vm.add_args('-kernel', kernel_path,
526                         '-dtb', dtb_path,
527                         '-initrd', initrd_path,
528                         '-append', kernel_command_line,
529                         '-no-reboot')
530        self.vm.launch()
531
532        self.wait_for_console_pattern('Boot successful.')
533        # TODO user command, for now the uart is stuck
534
535    def test_arm_cubieboard_initrd(self):
536        """
537        :avocado: tags=arch:arm
538        :avocado: tags=machine:cubieboard
539        :avocado: tags=accel:tcg
540        """
541        deb_url = ('https://apt.armbian.com/pool/main/l/'
542                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
543        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
544        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
545        kernel_path = self.extract_from_deb(deb_path,
546                                            '/boot/vmlinuz-5.10.16-sunxi')
547        dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb'
548        dtb_path = self.extract_from_deb(deb_path, dtb_path)
549        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
550                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
551                      'arm/rootfs-armv5.cpio.gz')
552        initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
553        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
554        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
555        archive.gzip_uncompress(initrd_path_gz, initrd_path)
556
557        self.vm.set_console()
558        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
559                               'console=ttyS0,115200 '
560                               'usbcore.nousb '
561                               'panic=-1 noreboot')
562        self.vm.add_args('-kernel', kernel_path,
563                         '-dtb', dtb_path,
564                         '-initrd', initrd_path,
565                         '-append', kernel_command_line,
566                         '-no-reboot')
567        self.vm.launch()
568        self.wait_for_console_pattern('Boot successful.')
569
570        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
571                                                'Allwinner sun4i/sun5i')
572        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
573                                                'system-control@1c00000')
574        # cubieboard's reboot is not functioning; omit reboot test.
575
576    def test_arm_cubieboard_sata(self):
577        """
578        :avocado: tags=arch:arm
579        :avocado: tags=machine:cubieboard
580        :avocado: tags=accel:tcg
581        """
582        deb_url = ('https://apt.armbian.com/pool/main/l/'
583                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
584        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
585        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
586        kernel_path = self.extract_from_deb(deb_path,
587                                            '/boot/vmlinuz-5.10.16-sunxi')
588        dtb_path = '/usr/lib/linux-image-current-sunxi/sun4i-a10-cubieboard.dtb'
589        dtb_path = self.extract_from_deb(deb_path, dtb_path)
590        rootfs_url = ('https://github.com/groeck/linux-build-test/raw/'
591                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
592                      'arm/rootfs-armv5.ext2.gz')
593        rootfs_hash = '093e89d2b4d982234bf528bc9fb2f2f17a9d1f93'
594        rootfs_path_gz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
595        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
596        archive.gzip_uncompress(rootfs_path_gz, rootfs_path)
597
598        self.vm.set_console()
599        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
600                               'console=ttyS0,115200 '
601                               'usbcore.nousb '
602                               'root=/dev/sda ro '
603                               'panic=-1 noreboot')
604        self.vm.add_args('-kernel', kernel_path,
605                         '-dtb', dtb_path,
606                         '-drive', 'if=none,format=raw,id=disk0,file='
607                                   + rootfs_path,
608                         '-device', 'ide-hd,bus=ide.0,drive=disk0',
609                         '-append', kernel_command_line,
610                         '-no-reboot')
611        self.vm.launch()
612        self.wait_for_console_pattern('Boot successful.')
613
614        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
615                                                'Allwinner sun4i/sun5i')
616        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
617                                                'sda')
618        # cubieboard's reboot is not functioning; omit reboot test.
619
620    @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
621    def test_arm_quanta_gsj(self):
622        """
623        :avocado: tags=arch:arm
624        :avocado: tags=machine:quanta-gsj
625        :avocado: tags=accel:tcg
626        """
627        # 25 MiB compressed, 32 MiB uncompressed.
628        image_url = (
629                'https://github.com/hskinnemoen/openbmc/releases/download/'
630                '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz')
631        image_hash = '14895e634923345cb5c8776037ff7876df96f6b1'
632        image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
633        image_name = 'obmc.mtd'
634        image_path = os.path.join(self.workdir, image_name)
635        archive.gzip_uncompress(image_path_gz, image_path)
636
637        self.vm.set_console()
638        drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
639        self.vm.add_args('-drive', drive_args)
640        self.vm.launch()
641
642        # Disable drivers and services that stall for a long time during boot,
643        # to avoid running past the 90-second timeout. These may be removed
644        # as the corresponding device support is added.
645        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + (
646                'console=${console} '
647                'mem=${mem} '
648                'initcall_blacklist=npcm_i2c_bus_driver_init '
649                'systemd.mask=systemd-random-seed.service '
650                'systemd.mask=dropbearkey.service '
651        )
652
653        self.wait_for_console_pattern('> BootBlock by Nuvoton')
654        self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
655        self.wait_for_console_pattern('>Skip DDR init.')
656        self.wait_for_console_pattern('U-Boot ')
657        interrupt_interactive_console_until_pattern(
658                self, 'Hit any key to stop autoboot:', 'U-Boot>')
659        exec_command_and_wait_for_pattern(
660                self, "setenv bootargs ${bootargs} " + kernel_command_line,
661                'U-Boot>')
662        exec_command_and_wait_for_pattern(
663                self, 'run romboot', 'Booting Kernel from flash')
664        self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
665        self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
666        self.wait_for_console_pattern('OpenBMC Project Reference Distro')
667        self.wait_for_console_pattern('gsj login:')
668
669    def test_arm_quanta_gsj_initrd(self):
670        """
671        :avocado: tags=arch:arm
672        :avocado: tags=machine:quanta-gsj
673        :avocado: tags=accel:tcg
674        """
675        initrd_url = (
676                'https://github.com/hskinnemoen/openbmc/releases/download/'
677                '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz')
678        initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300'
679        initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
680        kernel_url = (
681                'https://github.com/hskinnemoen/openbmc/releases/download/'
682                '20200711-gsj-qemu-0/uImage-gsj.bin')
683        kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7'
684        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
685        dtb_url = (
686                'https://github.com/hskinnemoen/openbmc/releases/download/'
687                '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb')
688        dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4'
689        dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash)
690
691        self.vm.set_console()
692        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
693                               'console=ttyS0,115200n8 '
694                               'earlycon=uart8250,mmio32,0xf0001000')
695        self.vm.add_args('-kernel', kernel_path,
696                         '-initrd', initrd_path,
697                         '-dtb', dtb_path,
698                         '-append', kernel_command_line)
699        self.vm.launch()
700
701        self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
702        self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
703        self.wait_for_console_pattern(
704                'Give root password for system maintenance')
705
706    def test_arm_orangepi(self):
707        """
708        :avocado: tags=arch:arm
709        :avocado: tags=machine:orangepi-pc
710        :avocado: tags=accel:tcg
711        """
712        deb_url = ('https://apt.armbian.com/pool/main/l/'
713                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
714        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
715        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
716        kernel_path = self.extract_from_deb(deb_path,
717                                            '/boot/vmlinuz-5.10.16-sunxi')
718        dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb'
719        dtb_path = self.extract_from_deb(deb_path, dtb_path)
720
721        self.vm.set_console()
722        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
723                               'console=ttyS0,115200n8 '
724                               'earlycon=uart,mmio32,0x1c28000')
725        self.vm.add_args('-kernel', kernel_path,
726                         '-dtb', dtb_path,
727                         '-append', kernel_command_line)
728        self.vm.launch()
729        console_pattern = 'Kernel command line: %s' % kernel_command_line
730        self.wait_for_console_pattern(console_pattern)
731
732    def test_arm_orangepi_initrd(self):
733        """
734        :avocado: tags=arch:arm
735        :avocado: tags=accel:tcg
736        :avocado: tags=machine:orangepi-pc
737        """
738        deb_url = ('https://apt.armbian.com/pool/main/l/'
739                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
740        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
741        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
742        kernel_path = self.extract_from_deb(deb_path,
743                                            '/boot/vmlinuz-5.10.16-sunxi')
744        dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb'
745        dtb_path = self.extract_from_deb(deb_path, dtb_path)
746        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
747                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
748                      'arm/rootfs-armv7a.cpio.gz')
749        initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
750        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
751        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
752        archive.gzip_uncompress(initrd_path_gz, initrd_path)
753
754        self.vm.set_console()
755        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
756                               'console=ttyS0,115200 '
757                               'panic=-1 noreboot')
758        self.vm.add_args('-kernel', kernel_path,
759                         '-dtb', dtb_path,
760                         '-initrd', initrd_path,
761                         '-append', kernel_command_line,
762                         '-no-reboot')
763        self.vm.launch()
764        self.wait_for_console_pattern('Boot successful.')
765
766        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
767                                                'Allwinner sun8i Family')
768        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
769                                                'system-control@1c00000')
770        exec_command_and_wait_for_pattern(self, 'reboot',
771                                                'reboot: Restarting system')
772        # Wait for VM to shut down gracefully
773        self.vm.wait()
774
775    def test_arm_orangepi_sd(self):
776        """
777        :avocado: tags=arch:arm
778        :avocado: tags=accel:tcg
779        :avocado: tags=machine:orangepi-pc
780        :avocado: tags=device:sd
781        """
782        deb_url = ('https://apt.armbian.com/pool/main/l/'
783                   'linux-5.10.16-sunxi/linux-image-current-sunxi_21.02.2_armhf.deb')
784        deb_hash = '9fa84beda245cabf0b4fa84cf6eaa7738ead1da0'
785        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
786        kernel_path = self.extract_from_deb(deb_path,
787                                            '/boot/vmlinuz-5.10.16-sunxi')
788        dtb_path = '/usr/lib/linux-image-current-sunxi/sun8i-h3-orangepi-pc.dtb'
789        dtb_path = self.extract_from_deb(deb_path, dtb_path)
790        rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/'
791                      'kci-2019.02/armel/base/rootfs.ext2.xz')
792        rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061'
793        rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
794        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
795        archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
796        image_pow2ceil_expand(rootfs_path)
797
798        self.vm.set_console()
799        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
800                               'console=ttyS0,115200 '
801                               'root=/dev/mmcblk0 rootwait rw '
802                               'panic=-1 noreboot')
803        self.vm.add_args('-kernel', kernel_path,
804                         '-dtb', dtb_path,
805                         '-drive', 'file=' + rootfs_path + ',if=sd,format=raw',
806                         '-append', kernel_command_line,
807                         '-no-reboot')
808        self.vm.launch()
809        shell_ready = "/bin/sh: can't access tty; job control turned off"
810        self.wait_for_console_pattern(shell_ready)
811
812        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
813                                                'Allwinner sun8i Family')
814        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
815                                                'mmcblk0')
816        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
817                                                 'eth0: Link is Up')
818        exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
819            'udhcpc: lease of 10.0.2.15 obtained')
820        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
821            '3 packets transmitted, 3 packets received, 0% packet loss')
822        exec_command_and_wait_for_pattern(self, 'reboot',
823                                                'reboot: Restarting system')
824        # Wait for VM to shut down gracefully
825        self.vm.wait()
826
827    @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
828    def test_arm_orangepi_bionic_20_08(self):
829        """
830        :avocado: tags=arch:arm
831        :avocado: tags=machine:orangepi-pc
832        :avocado: tags=device:sd
833        """
834
835        # This test download a 275 MiB compressed image and expand it
836        # to 1036 MiB, but the underlying filesystem is 1552 MiB...
837        # As we expand it to 2 GiB we are safe.
838
839        image_url = ('https://archive.armbian.com/orangepipc/archive/'
840                     'Armbian_20.08.1_Orangepipc_bionic_current_5.8.5.img.xz')
841        image_hash = ('b4d6775f5673486329e45a0586bf06b6'
842                      'dbe792199fd182ac6b9c7bb6c7d3e6dd')
843        image_path_xz = self.fetch_asset(image_url, asset_hash=image_hash,
844                                         algorithm='sha256')
845        image_path = archive.extract(image_path_xz, self.workdir)
846        image_pow2ceil_expand(image_path)
847
848        self.vm.set_console()
849        self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
850                         '-nic', 'user',
851                         '-no-reboot')
852        self.vm.launch()
853
854        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
855                               'console=ttyS0,115200 '
856                               'loglevel=7 '
857                               'nosmp '
858                               'systemd.default_timeout_start_sec=9000 '
859                               'systemd.mask=armbian-zram-config.service '
860                               'systemd.mask=armbian-ramlog.service')
861
862        self.wait_for_console_pattern('U-Boot SPL')
863        self.wait_for_console_pattern('Autoboot in ')
864        exec_command_and_wait_for_pattern(self, ' ', '=>')
865        exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
866                                                kernel_command_line + "'", '=>')
867        exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
868
869        self.wait_for_console_pattern('systemd[1]: Set hostname ' +
870                                      'to <orangepipc>')
871        self.wait_for_console_pattern('Starting Load Kernel Modules...')
872
873    @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
874    def test_arm_orangepi_uboot_netbsd9(self):
875        """
876        :avocado: tags=arch:arm
877        :avocado: tags=machine:orangepi-pc
878        :avocado: tags=device:sd
879        :avocado: tags=os:netbsd
880        """
881        # This test download a 304MB compressed image and expand it to 2GB
882        deb_url = ('http://snapshot.debian.org/archive/debian/'
883                   '20200108T145233Z/pool/main/u/u-boot/'
884                   'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb')
885        deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99'
886        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
887        # We use the common OrangePi PC 'plus' build of U-Boot for our secondary
888        # program loader (SPL). We will then set the path to the more specific
889        # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt,
890        # before to boot NetBSD.
891        uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
892        uboot_path = self.extract_from_deb(deb_path, uboot_path)
893        image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/'
894                     'evbarm-earmv7hf/binary/gzimg/armv7.img.gz')
895        image_hash = '2babb29d36d8360adcb39c09e31060945259917a'
896        image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
897        image_path = os.path.join(self.workdir, 'armv7.img')
898        archive.gzip_uncompress(image_path_gz, image_path)
899        image_pow2ceil_expand(image_path)
900        image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
901
902        # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc
903        with open(uboot_path, 'rb') as f_in:
904            with open(image_path, 'r+b') as f_out:
905                f_out.seek(8 * 1024)
906                shutil.copyfileobj(f_in, f_out)
907
908        self.vm.set_console()
909        self.vm.add_args('-nic', 'user',
910                         '-drive', image_drive_args,
911                         '-global', 'allwinner-rtc.base-year=2000',
912                         '-no-reboot')
913        self.vm.launch()
914        wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
915        interrupt_interactive_console_until_pattern(self,
916                                       'Hit any key to stop autoboot:',
917                                       'switch to partitions #0, OK')
918
919        exec_command_and_wait_for_pattern(self, '', '=>')
920        cmd = 'setenv bootargs root=ld0a'
921        exec_command_and_wait_for_pattern(self, cmd, '=>')
922        cmd = 'setenv kernel netbsd-GENERIC.ub'
923        exec_command_and_wait_for_pattern(self, cmd, '=>')
924        cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
925        exec_command_and_wait_for_pattern(self, cmd, '=>')
926        cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
927               "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
928               "fdt addr ${fdt_addr_r}; "
929               "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
930        exec_command_and_wait_for_pattern(self, cmd, '=>')
931
932        exec_command_and_wait_for_pattern(self, 'boot',
933                                          'Booting kernel from Legacy Image')
934        wait_for_console_pattern(self, 'Starting kernel ...')
935        wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
936        # Wait for user-space
937        wait_for_console_pattern(self, 'Starting root file system check')
938
939    def test_aarch64_raspi3_atf(self):
940        """
941        :avocado: tags=arch:aarch64
942        :avocado: tags=machine:raspi3b
943        :avocado: tags=cpu:cortex-a53
944        :avocado: tags=device:pl011
945        :avocado: tags=atf
946        """
947        zip_url = ('https://github.com/pbatard/RPi3/releases/download/'
948                   'v1.15/RPi3_UEFI_Firmware_v1.15.zip')
949        zip_hash = '74b3bd0de92683cadb14e008a7575e1d0c3cafb9'
950        zip_path = self.fetch_asset(zip_url, asset_hash=zip_hash)
951
952        archive.extract(zip_path, self.workdir)
953        efi_fd = os.path.join(self.workdir, 'RPI_EFI.fd')
954
955        self.vm.set_console(console_index=1)
956        self.vm.add_args('-nodefaults',
957                         '-device', 'loader,file=%s,force-raw=true' % efi_fd)
958        self.vm.launch()
959        self.wait_for_console_pattern('version UEFI Firmware v1.15')
960
961    def test_s390x_s390_ccw_virtio(self):
962        """
963        :avocado: tags=arch:s390x
964        :avocado: tags=machine:s390-ccw-virtio
965        """
966        kernel_url = ('https://archives.fedoraproject.org/pub/archive'
967                      '/fedora-secondary/releases/29/Everything/s390x/os/images'
968                      '/kernel.img')
969        kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
970        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
971
972        self.vm.set_console()
973        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
974        self.vm.add_args('-nodefaults',
975                         '-kernel', kernel_path,
976                         '-append', kernel_command_line)
977        self.vm.launch()
978        console_pattern = 'Kernel command line: %s' % kernel_command_line
979        self.wait_for_console_pattern(console_pattern)
980
981    def test_alpha_clipper(self):
982        """
983        :avocado: tags=arch:alpha
984        :avocado: tags=machine:clipper
985        """
986        kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
987                      'installer-alpha/20090123lenny10/images/cdrom/vmlinuz')
988        kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
989        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
990
991        uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
992
993        self.vm.set_console()
994        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
995        self.vm.add_args('-nodefaults',
996                         '-kernel', uncompressed_kernel,
997                         '-append', kernel_command_line)
998        self.vm.launch()
999        console_pattern = 'Kernel command line: %s' % kernel_command_line
1000        self.wait_for_console_pattern(console_pattern)
1001
1002    def test_m68k_q800(self):
1003        """
1004        :avocado: tags=arch:m68k
1005        :avocado: tags=machine:q800
1006        """
1007        deb_url = ('https://snapshot.debian.org/archive/debian-ports'
1008                   '/20191021T083923Z/pool-m68k/main'
1009                   '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
1010        deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
1011        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
1012        kernel_path = self.extract_from_deb(deb_path,
1013                                            '/boot/vmlinux-5.3.0-1-m68k')
1014
1015        self.vm.set_console()
1016        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
1017                               'console=ttyS0 vga=off')
1018        self.vm.add_args('-kernel', kernel_path,
1019                         '-append', kernel_command_line)
1020        self.vm.launch()
1021        console_pattern = 'Kernel command line: %s' % kernel_command_line
1022        self.wait_for_console_pattern(console_pattern)
1023        console_pattern = 'No filesystem could mount root'
1024        self.wait_for_console_pattern(console_pattern)
1025
1026    def do_test_advcal_2018(self, day, tar_hash, kernel_name, console=0):
1027        tar_url = ('https://www.qemu-advent-calendar.org'
1028                   '/2018/download/day' + day + '.tar.xz')
1029        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
1030        archive.extract(file_path, self.workdir)
1031        self.vm.set_console(console_index=console)
1032        self.vm.add_args('-kernel',
1033                         self.workdir + '/day' + day + '/' + kernel_name)
1034        self.vm.launch()
1035        self.wait_for_console_pattern('QEMU advent calendar')
1036
1037    def test_arm_vexpressa9(self):
1038        """
1039        :avocado: tags=arch:arm
1040        :avocado: tags=machine:vexpress-a9
1041        """
1042        tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b'
1043        self.vm.add_args('-dtb', self.workdir + '/day16/vexpress-v2p-ca9.dtb')
1044        self.do_test_advcal_2018('16', tar_hash, 'winter.zImage')
1045
1046    def test_arm_ast2400_palmetto_openbmc_v2_9_0(self):
1047        """
1048        :avocado: tags=arch:arm
1049        :avocado: tags=machine:palmetto-bmc
1050        """
1051
1052        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
1053                     'obmc-phosphor-image-palmetto.static.mtd')
1054        image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d')
1055        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
1056                                      algorithm='sha256')
1057
1058        self.do_test_arm_aspeed(image_path)
1059
1060    def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
1061        """
1062        :avocado: tags=arch:arm
1063        :avocado: tags=machine:romulus-bmc
1064        """
1065
1066        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
1067                     'obmc-phosphor-image-romulus.static.mtd')
1068        image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25')
1069        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
1070                                      algorithm='sha256')
1071
1072        self.do_test_arm_aspeed(image_path)
1073
1074    def do_test_arm_aspeed(self, image):
1075        self.vm.set_console()
1076        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
1077                         '-net', 'nic')
1078        self.vm.launch()
1079
1080        self.wait_for_console_pattern("U-Boot 2016.07")
1081        self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
1082        self.wait_for_console_pattern("Starting kernel ...")
1083        self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
1084        self.wait_for_console_pattern(
1085                "aspeed-smc 1e620000.spi: read control register: 203b0641")
1086        self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
1087        self.wait_for_console_pattern("systemd[1]: Set hostname to")
1088
1089    def test_arm_ast2600_debian(self):
1090        """
1091        :avocado: tags=arch:arm
1092        :avocado: tags=machine:tacoma-bmc
1093        """
1094        deb_url = ('http://snapshot.debian.org/archive/debian/'
1095                   '20210302T203551Z/'
1096                   'pool/main/l/linux/'
1097                   'linux-image-5.10.0-3-armmp_5.10.13-1_armhf.deb')
1098        deb_hash = 'db40d32fe39255d05482bea48d72467b67d6225bb2a2a4d6f618cb8976f1e09e'
1099        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash,
1100                                    algorithm='sha256')
1101        kernel_path = self.extract_from_deb(deb_path, '/boot/vmlinuz-5.10.0-3-armmp')
1102        dtb_path = self.extract_from_deb(deb_path,
1103                '/usr/lib/linux-image-5.10.0-3-armmp/aspeed-bmc-opp-tacoma.dtb')
1104
1105        self.vm.set_console()
1106        self.vm.add_args('-kernel', kernel_path,
1107                         '-dtb', dtb_path,
1108                         '-net', 'nic')
1109        self.vm.launch()
1110        self.wait_for_console_pattern("Booting Linux on physical CPU 0xf00")
1111        self.wait_for_console_pattern("SMP: Total of 2 processors activated")
1112        self.wait_for_console_pattern("No filesystem could mount root")
1113
1114    def test_m68k_mcf5208evb(self):
1115        """
1116        :avocado: tags=arch:m68k
1117        :avocado: tags=machine:mcf5208evb
1118        """
1119        tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c'
1120        self.do_test_advcal_2018('07', tar_hash, 'sanity-clause.elf')
1121
1122    def test_or1k_sim(self):
1123        """
1124        :avocado: tags=arch:or1k
1125        :avocado: tags=machine:or1k-sim
1126        """
1127        tar_hash = '20334cdaf386108c530ff0badaecc955693027dd'
1128        self.do_test_advcal_2018('20', tar_hash, 'vmlinux')
1129
1130    def test_nios2_10m50(self):
1131        """
1132        :avocado: tags=arch:nios2
1133        :avocado: tags=machine:10m50-ghrd
1134        """
1135        tar_hash = 'e4251141726c412ac0407c5a6bceefbbff018918'
1136        self.do_test_advcal_2018('14', tar_hash, 'vmlinux.elf')
1137
1138    def test_ppc64_e500(self):
1139        """
1140        :avocado: tags=arch:ppc64
1141        :avocado: tags=machine:ppce500
1142        :avocado: tags=cpu:e5500
1143        :avocado: tags=accel:tcg
1144        """
1145        self.require_accelerator("tcg")
1146        tar_hash = '6951d86d644b302898da2fd701739c9406527fe1'
1147        self.do_test_advcal_2018('19', tar_hash, 'uImage')
1148
1149    def do_test_ppc64_powernv(self, proc):
1150        self.require_accelerator("tcg")
1151        images_url = ('https://github.com/open-power/op-build/releases/download/v2.7/')
1152
1153        kernel_url = images_url + 'zImage.epapr'
1154        kernel_hash = '0ab237df661727e5392cee97460e8674057a883c5f74381a128fa772588d45cd'
1155        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash,
1156                                       algorithm='sha256')
1157        self.vm.set_console()
1158        self.vm.add_args('-kernel', kernel_path,
1159                         '-append', 'console=tty0 console=hvc0',
1160                         '-device', 'pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0',
1161                         '-device', 'nvme,bus=pcie.2,addr=0x0,serial=1234',
1162                         '-device', 'e1000e,bus=bridge1,addr=0x3',
1163                         '-device', 'nec-usb-xhci,bus=bridge1,addr=0x2')
1164        self.vm.launch()
1165
1166        self.wait_for_console_pattern("CPU: " + proc + " generation processor")
1167        self.wait_for_console_pattern("zImage starting: loaded")
1168        self.wait_for_console_pattern("Run /init as init process")
1169        self.wait_for_console_pattern("Creating 1 MTD partitions")
1170
1171    def test_ppc_powernv8(self):
1172        """
1173        :avocado: tags=arch:ppc64
1174        :avocado: tags=machine:powernv8
1175        :avocado: tags=accel:tcg
1176        """
1177        self.do_test_ppc64_powernv('P8')
1178
1179    def test_ppc_powernv9(self):
1180        """
1181        :avocado: tags=arch:ppc64
1182        :avocado: tags=machine:powernv9
1183        :avocado: tags=accel:tcg
1184        """
1185        self.do_test_ppc64_powernv('P9')
1186
1187    def test_ppc_g3beige(self):
1188        """
1189        :avocado: tags=arch:ppc
1190        :avocado: tags=machine:g3beige
1191        :avocado: tags=accel:tcg
1192        """
1193        # TODO: g3beige works with kvm_pr but we don't have a
1194        # reliable way ATM (e.g. looking at /proc/modules) to detect
1195        # whether we're running kvm_hv or kvm_pr. For now let's
1196        # disable this test if we don't have TCG support.
1197        self.require_accelerator("tcg")
1198        tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
1199        self.vm.add_args('-M', 'graphics=off')
1200        self.do_test_advcal_2018('15', tar_hash, 'invaders.elf')
1201
1202    def test_ppc_mac99(self):
1203        """
1204        :avocado: tags=arch:ppc
1205        :avocado: tags=machine:mac99
1206        :avocado: tags=accel:tcg
1207        """
1208        # TODO: mac99 works with kvm_pr but we don't have a
1209        # reliable way ATM (e.g. looking at /proc/modules) to detect
1210        # whether we're running kvm_hv or kvm_pr. For now let's
1211        # disable this test if we don't have TCG support.
1212        self.require_accelerator("tcg")
1213        tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
1214        self.vm.add_args('-M', 'graphics=off')
1215        self.do_test_advcal_2018('15', tar_hash, 'invaders.elf')
1216
1217    def test_sh4_r2d(self):
1218        """
1219        :avocado: tags=arch:sh4
1220        :avocado: tags=machine:r2d
1221        """
1222        tar_hash = 'fe06a4fd8ccbf2e27928d64472939d47829d4c7e'
1223        self.vm.add_args('-append', 'console=ttySC1')
1224        self.do_test_advcal_2018('09', tar_hash, 'zImage', console=1)
1225
1226    def test_sparc_ss20(self):
1227        """
1228        :avocado: tags=arch:sparc
1229        :avocado: tags=machine:SS-20
1230        """
1231        tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f'
1232        self.do_test_advcal_2018('11', tar_hash, 'zImage.elf')
1233
1234    def test_xtensa_lx60(self):
1235        """
1236        :avocado: tags=arch:xtensa
1237        :avocado: tags=machine:lx60
1238        :avocado: tags=cpu:dc233c
1239        """
1240        tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34'
1241        self.do_test_advcal_2018('02', tar_hash, 'santas-sleigh-ride.elf')
1242