xref: /qemu/tests/functional/test_arm_cubieboard.py (revision 8a6253a43a43084275b31ef05e674e4987b05a84)
1#!/usr/bin/env python3
2#
3# Functional test that boots a Linux kernel and checks the console
4#
5# SPDX-License-Identifier: GPL-2.0-or-later
6
7import os
8
9from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern
10from qemu_test import interrupt_interactive_console_until_pattern
11from qemu_test.utils import gzip_uncompress, image_pow2ceil_expand
12from unittest import skipUnless
13
14class CubieboardMachine(LinuxKernelTest):
15
16    ASSET_DEB = Asset(
17        ('https://apt.armbian.com/pool/main/l/linux-6.6.16/'
18         'linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb'),
19        '3d968c15b121ede871dce49d13ee7644d6f74b6b121b84c9a40f51b0c80d6d22')
20
21    ASSET_INITRD = Asset(
22        ('https://github.com/groeck/linux-build-test/raw/'
23         '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
24         'arm/rootfs-armv5.cpio.gz'),
25        '334b8d256db67a3f2b3ad070aa08b5ade39624e0e7e35b02f4359a577bc8f39b')
26
27    ASSET_SATA_ROOTFS = Asset(
28        ('https://github.com/groeck/linux-build-test/raw/'
29         '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
30         'arm/rootfs-armv5.ext2.gz'),
31        '17fc750da568580b39372133051ef2f0a963c0c0b369b845614442d025701745')
32
33    ASSET_OPENWRT = Asset(
34        ('https://downloads.openwrt.org/releases/22.03.2/targets/sunxi/cortexa8/'
35         'openwrt-22.03.2-sunxi-cortexa8-cubietech_a10-cubieboard-ext4-sdcard.img.gz'),
36        '94b5ecbfbc0b3b56276e5146b899eafa2ac5dc2d08733d6705af9f144f39f554')
37
38    def test_arm_cubieboard_initrd(self):
39        self.set_machine('cubieboard')
40        deb_path = self.ASSET_DEB.fetch()
41        kernel_path = self.extract_from_deb(deb_path,
42                                            '/boot/vmlinuz-6.6.16-current-sunxi')
43        dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb'
44        dtb_path = self.extract_from_deb(deb_path, dtb_path)
45        initrd_path_gz = self.ASSET_INITRD.fetch()
46        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
47        gzip_uncompress(initrd_path_gz, initrd_path)
48
49        self.vm.set_console()
50        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
51                               'console=ttyS0,115200 '
52                               'usbcore.nousb '
53                               'panic=-1 noreboot')
54        self.vm.add_args('-kernel', kernel_path,
55                         '-dtb', dtb_path,
56                         '-initrd', initrd_path,
57                         '-append', kernel_command_line,
58                         '-no-reboot')
59        self.vm.launch()
60        self.wait_for_console_pattern('Boot successful.')
61
62        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
63                                                'Allwinner sun4i/sun5i')
64        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
65                                                'system-control@1c00000')
66        exec_command_and_wait_for_pattern(self, 'reboot',
67                                                'reboot: Restarting system')
68        # Wait for VM to shut down gracefully
69        self.vm.wait()
70
71    def test_arm_cubieboard_sata(self):
72        self.set_machine('cubieboard')
73        deb_path = self.ASSET_DEB.fetch()
74        kernel_path = self.extract_from_deb(deb_path,
75                                            '/boot/vmlinuz-6.6.16-current-sunxi')
76        dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb'
77        dtb_path = self.extract_from_deb(deb_path, dtb_path)
78
79        rootfs_path_gz = self.ASSET_SATA_ROOTFS.fetch()
80        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
81        gzip_uncompress(rootfs_path_gz, rootfs_path)
82
83        self.vm.set_console()
84        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
85                               'console=ttyS0,115200 '
86                               'usbcore.nousb '
87                               'root=/dev/sda ro '
88                               'panic=-1 noreboot')
89        self.vm.add_args('-kernel', kernel_path,
90                         '-dtb', dtb_path,
91                         '-drive', 'if=none,format=raw,id=disk0,file='
92                                   + rootfs_path,
93                         '-device', 'ide-hd,bus=ide.0,drive=disk0',
94                         '-append', kernel_command_line,
95                         '-no-reboot')
96        self.vm.launch()
97        self.wait_for_console_pattern('Boot successful.')
98
99        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
100                                                'Allwinner sun4i/sun5i')
101        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
102                                                'sda')
103        exec_command_and_wait_for_pattern(self, 'reboot',
104                                                'reboot: Restarting system')
105        # Wait for VM to shut down gracefully
106        self.vm.wait()
107
108    @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
109    def test_arm_cubieboard_openwrt_22_03_2(self):
110        # This test download a 7.5 MiB compressed image and expand it
111        # to 126 MiB.
112        self.set_machine('cubieboard')
113        image_path_gz = self.ASSET_OPENWRT.fetch()
114        image_path = os.path.join(self.workdir, 'sdcard.img')
115        gzip_uncompress(image_path_gz, image_path)
116        image_pow2ceil_expand(image_path)
117
118        self.vm.set_console()
119        self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
120                         '-nic', 'user',
121                         '-no-reboot')
122        self.vm.launch()
123
124        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
125                               'usbcore.nousb '
126                               'noreboot')
127
128        self.wait_for_console_pattern('U-Boot SPL')
129
130        interrupt_interactive_console_until_pattern(
131                self, 'Hit any key to stop autoboot:', '=>')
132        exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
133                                                kernel_command_line + "'", '=>')
134        exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
135
136        self.wait_for_console_pattern(
137            'Please press Enter to activate this console.')
138
139        exec_command_and_wait_for_pattern(self, ' ', 'root@')
140
141        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
142                                                'Allwinner sun4i/sun5i')
143        exec_command_and_wait_for_pattern(self, 'reboot',
144                                                'reboot: Restarting system')
145        # Wait for VM to shut down gracefully
146        self.vm.wait()
147
148if __name__ == '__main__':
149    LinuxKernelTest.main()
150