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