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 8import shutil 9 10from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern 11from qemu_test import interrupt_interactive_console_until_pattern 12from qemu_test.utils import gzip_uncompress, image_pow2ceil_expand 13from unittest import skipUnless 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 deb_path = self.ASSET_DEB.fetch() 42 kernel_path = self.extract_from_deb(deb_path, 43 '/boot/vmlinuz-6.6.16-current-sunxi') 44 dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb' 45 dtb_path = self.extract_from_deb(deb_path, dtb_path) 46 initrd_path_gz = self.ASSET_INITRD.fetch() 47 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 48 gzip_uncompress(initrd_path_gz, initrd_path) 49 50 self.vm.set_console() 51 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 52 'console=ttyS0,115200 ' 53 'usbcore.nousb ' 54 'panic=-1 noreboot') 55 self.vm.add_args('-kernel', kernel_path, 56 '-dtb', dtb_path, 57 '-initrd', initrd_path, 58 '-append', kernel_command_line, 59 '-no-reboot') 60 self.vm.launch() 61 self.wait_for_console_pattern('Boot successful.') 62 63 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 64 'Allwinner sun4i/sun5i') 65 exec_command_and_wait_for_pattern(self, 'cat /proc/iomem', 66 'system-control@1c00000') 67 exec_command_and_wait_for_pattern(self, 'reboot', 68 'reboot: Restarting system') 69 # Wait for VM to shut down gracefully 70 self.vm.wait() 71 72 def test_arm_cubieboard_sata(self): 73 self.set_machine('cubieboard') 74 deb_path = self.ASSET_DEB.fetch() 75 kernel_path = self.extract_from_deb(deb_path, 76 '/boot/vmlinuz-6.6.16-current-sunxi') 77 dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb' 78 dtb_path = self.extract_from_deb(deb_path, dtb_path) 79 80 rootfs_path_gz = self.ASSET_SATA_ROOTFS.fetch() 81 rootfs_path = os.path.join(self.workdir, 'rootfs.cpio') 82 gzip_uncompress(rootfs_path_gz, rootfs_path) 83 84 self.vm.set_console() 85 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 86 'console=ttyS0,115200 ' 87 'usbcore.nousb ' 88 'root=/dev/sda ro ' 89 'panic=-1 noreboot') 90 self.vm.add_args('-kernel', kernel_path, 91 '-dtb', dtb_path, 92 '-drive', 'if=none,format=raw,id=disk0,file=' 93 + rootfs_path, 94 '-device', 'ide-hd,bus=ide.0,drive=disk0', 95 '-append', kernel_command_line, 96 '-no-reboot') 97 self.vm.launch() 98 self.wait_for_console_pattern('Boot successful.') 99 100 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 101 'Allwinner sun4i/sun5i') 102 exec_command_and_wait_for_pattern(self, 'cat /proc/partitions', 103 'sda') 104 exec_command_and_wait_for_pattern(self, 'reboot', 105 'reboot: Restarting system') 106 # Wait for VM to shut down gracefully 107 self.vm.wait() 108 109 @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited') 110 def test_arm_cubieboard_openwrt_22_03_2(self): 111 # This test download a 7.5 MiB compressed image and expand it 112 # to 126 MiB. 113 self.set_machine('cubieboard') 114 image_path_gz = self.ASSET_OPENWRT.fetch() 115 image_path = os.path.join(self.workdir, 'sdcard.img') 116 gzip_uncompress(image_path_gz, image_path) 117 image_pow2ceil_expand(image_path) 118 119 self.vm.set_console() 120 self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', 121 '-nic', 'user', 122 '-no-reboot') 123 self.vm.launch() 124 125 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 126 'usbcore.nousb ' 127 'noreboot') 128 129 self.wait_for_console_pattern('U-Boot SPL') 130 131 interrupt_interactive_console_until_pattern( 132 self, 'Hit any key to stop autoboot:', '=>') 133 exec_command_and_wait_for_pattern(self, "setenv extraargs '" + 134 kernel_command_line + "'", '=>') 135 exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...'); 136 137 self.wait_for_console_pattern( 138 'Please press Enter to activate this console.') 139 140 exec_command_and_wait_for_pattern(self, ' ', 'root@') 141 142 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 143 'Allwinner sun4i/sun5i') 144 exec_command_and_wait_for_pattern(self, 'reboot', 145 'reboot: Restarting system') 146 # Wait for VM to shut down gracefully 147 self.vm.wait() 148 149if __name__ == '__main__': 150 LinuxKernelTest.main() 151