xref: /qemu/tests/functional/test_arm_bpim2u.py (revision 55f5bf716a65f67663d0769bcb8c017764b3e53a)
1f7d6b772SThomas Huth#!/usr/bin/env python3
2f7d6b772SThomas Huth#
3f7d6b772SThomas Huth# Functional test that boots a Linux kernel on a Banana Pi machine
4f7d6b772SThomas Huth# and checks the console
5f7d6b772SThomas Huth#
6f7d6b772SThomas Huth# SPDX-License-Identifier: GPL-2.0-or-later
7f7d6b772SThomas Huth
8f7d6b772SThomas Huthimport os
9f7d6b772SThomas Huth
10f7d6b772SThomas Huthfrom qemu_test import LinuxKernelTest, exec_command_and_wait_for_pattern
11f7d6b772SThomas Huthfrom qemu_test import Asset, interrupt_interactive_console_until_pattern
123d593860SDaniel P. Berrangéfrom qemu_test import skipBigDataTest
13f7d6b772SThomas Huthfrom qemu_test.utils import image_pow2ceil_expand
143d593860SDaniel P. Berrangé
15f7d6b772SThomas Huth
16f7d6b772SThomas Huthclass BananaPiMachine(LinuxKernelTest):
17f7d6b772SThomas Huth
18f7d6b772SThomas Huth    ASSET_DEB = Asset(
19f7d6b772SThomas Huth        ('https://apt.armbian.com/pool/main/l/linux-6.6.16/'
20f7d6b772SThomas Huth         'linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb'),
21f7d6b772SThomas Huth        '3d968c15b121ede871dce49d13ee7644d6f74b6b121b84c9a40f51b0c80d6d22')
22f7d6b772SThomas Huth
23f7d6b772SThomas Huth    ASSET_INITRD = Asset(
24f7d6b772SThomas Huth        ('https://github.com/groeck/linux-build-test/raw/'
25f7d6b772SThomas Huth         '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
26f7d6b772SThomas Huth         'arm/rootfs-armv7a.cpio.gz'),
27f7d6b772SThomas Huth        '2c8dbdb16ea7af2dfbcbea96044dde639fb07d09fd3c4fb31f2027ef71e55ddd')
28f7d6b772SThomas Huth
29f7d6b772SThomas Huth    ASSET_ROOTFS = Asset(
30f7d6b772SThomas Huth        ('http://storage.kernelci.org/images/rootfs/buildroot/'
31f7d6b772SThomas Huth         'buildroot-baseline/20230703.0/armel/rootfs.ext2.xz'),
32f7d6b772SThomas Huth        '42b44a12965ac0afe9a88378527fb698a7dc76af50495efc2361ee1595b4e5c6')
33f7d6b772SThomas Huth
34f7d6b772SThomas Huth    ASSET_SD_IMAGE = Asset(
35f7d6b772SThomas Huth        ('https://downloads.openwrt.org/releases/22.03.3/targets/sunxi/cortexa7/'
36f7d6b772SThomas Huth         'openwrt-22.03.3-sunxi-cortexa7-sinovoip_bananapi-m2-ultra-ext4-sdcard.img.gz'),
37f7d6b772SThomas Huth        '5b41b4e11423e562c6011640f9a7cd3bdd0a3d42b83430f7caa70a432e6cd82c')
38f7d6b772SThomas Huth
39f7d6b772SThomas Huth    def test_arm_bpim2u(self):
40f7d6b772SThomas Huth        self.set_machine('bpim2u')
415831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
425831ed84SDaniel P. Berrangé            self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi')
435831ed84SDaniel P. Berrangé        dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/'
44f7d6b772SThomas Huth                    'sun8i-r40-bananapi-m2-ultra.dtb')
455831ed84SDaniel P. Berrangé        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
46f7d6b772SThomas Huth
47f7d6b772SThomas Huth        self.vm.set_console()
48f7d6b772SThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
49f7d6b772SThomas Huth                               'console=ttyS0,115200n8 '
50f7d6b772SThomas Huth                               'earlycon=uart,mmio32,0x1c28000')
51f7d6b772SThomas Huth        self.vm.add_args('-kernel', kernel_path,
52f7d6b772SThomas Huth                         '-dtb', dtb_path,
53f7d6b772SThomas Huth                         '-append', kernel_command_line)
54f7d6b772SThomas Huth        self.vm.launch()
55f7d6b772SThomas Huth        console_pattern = 'Kernel command line: %s' % kernel_command_line
56f7d6b772SThomas Huth        self.wait_for_console_pattern(console_pattern)
57f7d6b772SThomas Huth        os.remove(kernel_path)
58f7d6b772SThomas Huth        os.remove(dtb_path)
59f7d6b772SThomas Huth
60f7d6b772SThomas Huth    def test_arm_bpim2u_initrd(self):
61f7d6b772SThomas Huth        self.set_machine('bpim2u')
625831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
635831ed84SDaniel P. Berrangé            self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi')
645831ed84SDaniel P. Berrangé        dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/'
65f7d6b772SThomas Huth                    'sun8i-r40-bananapi-m2-ultra.dtb')
665831ed84SDaniel P. Berrangé        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
6765d35a4eSDaniel P. Berrangé        initrd_path = self.uncompress(self.ASSET_INITRD)
68f7d6b772SThomas Huth
69f7d6b772SThomas Huth        self.vm.set_console()
70f7d6b772SThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
71f7d6b772SThomas Huth                               'console=ttyS0,115200 '
72f7d6b772SThomas Huth                               'panic=-1 noreboot')
73f7d6b772SThomas Huth        self.vm.add_args('-kernel', kernel_path,
74f7d6b772SThomas Huth                         '-dtb', dtb_path,
75f7d6b772SThomas Huth                         '-initrd', initrd_path,
76f7d6b772SThomas Huth                         '-append', kernel_command_line,
77f7d6b772SThomas Huth                         '-no-reboot')
78f7d6b772SThomas Huth        self.vm.launch()
79f7d6b772SThomas Huth        self.wait_for_console_pattern('Boot successful.')
80f7d6b772SThomas Huth
81f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
82f7d6b772SThomas Huth                                                'Allwinner sun8i Family')
83f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
84f7d6b772SThomas Huth                                                'system-control@1c00000')
85f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'reboot',
86f7d6b772SThomas Huth                                                'reboot: Restarting system')
87f7d6b772SThomas Huth        # Wait for VM to shut down gracefully
88f7d6b772SThomas Huth        self.vm.wait()
89f7d6b772SThomas Huth        os.remove(kernel_path)
90f7d6b772SThomas Huth        os.remove(dtb_path)
91f7d6b772SThomas Huth        os.remove(initrd_path)
92f7d6b772SThomas Huth
93f7d6b772SThomas Huth    def test_arm_bpim2u_gmac(self):
94f7d6b772SThomas Huth        self.set_machine('bpim2u')
95f7d6b772SThomas Huth        self.require_netdev('user')
96f7d6b772SThomas Huth
97f7d6b772SThomas Huth        deb_path = self.ASSET_DEB.fetch()
985831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
995831ed84SDaniel P. Berrangé            self.ASSET_DEB, member='boot/vmlinuz-6.6.16-current-sunxi')
1005831ed84SDaniel P. Berrangé        dtb_path = ('usr/lib/linux-image-6.6.16-current-sunxi/'
101f7d6b772SThomas Huth                    'sun8i-r40-bananapi-m2-ultra.dtb')
1025831ed84SDaniel P. Berrangé        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
10365d35a4eSDaniel P. Berrangé        rootfs_path = self.uncompress(self.ASSET_ROOTFS)
104f7d6b772SThomas Huth        image_pow2ceil_expand(rootfs_path)
105f7d6b772SThomas Huth
106f7d6b772SThomas Huth        self.vm.set_console()
107f7d6b772SThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
108f7d6b772SThomas Huth                               'console=ttyS0,115200 '
109f7d6b772SThomas Huth                               'root=b300 rootwait rw '
110f7d6b772SThomas Huth                               'panic=-1 noreboot')
111f7d6b772SThomas Huth        self.vm.add_args('-kernel', kernel_path,
112f7d6b772SThomas Huth                         '-dtb', dtb_path,
113f7d6b772SThomas Huth                         '-drive', 'file=' + rootfs_path + ',if=sd,format=raw',
114f7d6b772SThomas Huth                         '-net', 'nic,model=gmac,netdev=host_gmac',
115f7d6b772SThomas Huth                         '-netdev', 'user,id=host_gmac',
116f7d6b772SThomas Huth                         '-append', kernel_command_line,
117f7d6b772SThomas Huth                         '-no-reboot')
118f7d6b772SThomas Huth        self.vm.launch()
119f7d6b772SThomas Huth        shell_ready = "/bin/sh: can't access tty; job control turned off"
120f7d6b772SThomas Huth        self.wait_for_console_pattern(shell_ready)
121f7d6b772SThomas Huth
122f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
123f7d6b772SThomas Huth                                                'Allwinner sun8i Family')
124f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
125f7d6b772SThomas Huth                                                'mmcblk')
126f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
127f7d6b772SThomas Huth                                                 'eth0: Link is Up')
128f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
129f7d6b772SThomas Huth            'udhcpc: lease of 10.0.2.15 obtained')
130f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
131f7d6b772SThomas Huth            '3 packets transmitted, 3 packets received, 0% packet loss')
132f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'reboot',
133f7d6b772SThomas Huth                                                'reboot: Restarting system')
134f7d6b772SThomas Huth        # Wait for VM to shut down gracefully
135f7d6b772SThomas Huth        self.vm.wait()
136f7d6b772SThomas Huth        os.remove(kernel_path)
137f7d6b772SThomas Huth        os.remove(dtb_path)
138f7d6b772SThomas Huth        os.remove(rootfs_path)
139f7d6b772SThomas Huth
1403d593860SDaniel P. Berrangé    @skipBigDataTest()
141f7d6b772SThomas Huth    def test_arm_bpim2u_openwrt_22_03_3(self):
142f7d6b772SThomas Huth        self.set_machine('bpim2u')
143dba0752fSThomas Huth        self.require_netdev('user')
144dba0752fSThomas Huth
145f7d6b772SThomas Huth        # This test download a 8.9 MiB compressed image and expand it
146f7d6b772SThomas Huth        # to 127 MiB.
14765d35a4eSDaniel P. Berrangé        image_path = self.uncompress(self.ASSET_SD_IMAGE)
148f7d6b772SThomas Huth        image_pow2ceil_expand(image_path)
149f7d6b772SThomas Huth
150f7d6b772SThomas Huth        self.vm.set_console()
151f7d6b772SThomas Huth        self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
152f7d6b772SThomas Huth                         '-nic', 'user',
153f7d6b772SThomas Huth                         '-no-reboot')
154f7d6b772SThomas Huth        self.vm.launch()
155f7d6b772SThomas Huth
156f7d6b772SThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
157f7d6b772SThomas Huth                               'usbcore.nousb '
158f7d6b772SThomas Huth                               'noreboot')
159f7d6b772SThomas Huth
160f7d6b772SThomas Huth        self.wait_for_console_pattern('U-Boot SPL')
161f7d6b772SThomas Huth
162f7d6b772SThomas Huth        interrupt_interactive_console_until_pattern(
163f7d6b772SThomas Huth                self, 'Hit any key to stop autoboot:', '=>')
164f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
165f7d6b772SThomas Huth                                                kernel_command_line + "'", '=>')
166*858640eaSThomas Huth        exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...')
167f7d6b772SThomas Huth
168f7d6b772SThomas Huth        self.wait_for_console_pattern(
169f7d6b772SThomas Huth            'Please press Enter to activate this console.')
170f7d6b772SThomas Huth
171f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, ' ', 'root@')
172f7d6b772SThomas Huth
173f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
174f7d6b772SThomas Huth                                                'Allwinner sun8i Family')
175f7d6b772SThomas Huth        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
176f7d6b772SThomas Huth                                                'system-control@1c00000')
177f7d6b772SThomas Huth        os.remove(image_path)
178f7d6b772SThomas Huth
179f7d6b772SThomas Huthif __name__ == '__main__':
180f7d6b772SThomas Huth    LinuxKernelTest.main()
181