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