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